-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] connector_woocommerce: update the sale price if the backend dis…
…count pricelist values are updated
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
from . import export_mapper | ||
from . import exporter | ||
from . import product | ||
from . import product_pricelist_item |
41 changes: 41 additions & 0 deletions
41
connector_woocommerce/models/product_product/product_pricelist_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class PricelistItem(models.Model): | ||
_inherit = "product.pricelist.item" | ||
|
||
def _update_woocommerce_write_date_by_pricelist(self, values): | ||
product = values.get("product_id", self.product_id) | ||
if not isinstance(product, models.Model): | ||
product = self.env["product.product"].browse(product).exists() | ||
if not product: | ||
product = values.get("product_tmpl_id", self.product_tmpl_id) | ||
if not isinstance(product, models.Model): | ||
product = self.env["product.template"].browse(product).exists() | ||
product = product.product_variant_ids | ||
|
||
if product.woocommerce_bind_ids: | ||
product.woocommerce_write_date = fields.Datetime.now() | ||
|
||
def _dependent_field_product_woocommerce_write_date(self): | ||
return {"product_id", "product_tmpl_id", "fixed_price", "applied_on"} | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for values in vals_list: | ||
if self._dependent_field_product_woocommerce_write_date() & values.keys(): | ||
self._update_woocommerce_write_date_by_pricelist(values) | ||
return super(PricelistItem, self).create(vals_list) | ||
|
||
def write(self, values): | ||
if self._dependent_field_product_woocommerce_write_date() & values.keys(): | ||
self._update_woocommerce_write_date_by_pricelist(values) | ||
return super(PricelistItem, self).write(values) | ||
|
||
def unlink(self): | ||
for rec in self: | ||
rec._update_woocommerce_write_date_by_pricelist({}) | ||
return super(PricelistItem, self).unlink() |