Skip to content

Commit

Permalink
[IMP] connector_woocommerce: update the sale price if the backend dis…
Browse files Browse the repository at this point in the history
…count pricelist values are updated
  • Loading branch information
FrankC013 committed Nov 4, 2024
1 parent 416910c commit ed77b3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions connector_woocommerce/models/product_product/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import export_mapper
from . import exporter
from . import product
from . import product_pricelist_item
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()

0 comments on commit ed77b3e

Please sign in to comment.