diff --git a/connector_oxigesti/models/product_pricelist_item/binding.py b/connector_oxigesti/models/product_pricelist_item/binding.py index 0d16a1ea5..c1db6410f 100644 --- a/connector_oxigesti/models/product_pricelist_item/binding.py +++ b/connector_oxigesti/models/product_pricelist_item/binding.py @@ -7,6 +7,24 @@ from odoo.exceptions import ValidationError +class Pricelist(models.Model): + _inherit = "product.pricelist" + + # TODO: Review use deleter to mark items as deprecated + def unlink(self): + for rec in self: + if rec.item_ids.oxigesti_bind_ids: + raise ValidationError( + _( + "You can't delete a pricelist that has been exported " + "the product prices by customer to Oxigesti. If you " + "want to delete it, you must first delete the items " + "of the pricelist." + ) + ) + return super().unlink() + + class ProductPricelistItem(models.Model): _inherit = "product.pricelist.item" diff --git a/connector_oxigesti/models/product_pricelist_item/listener.py b/connector_oxigesti/models/product_pricelist_item/listener.py index 93a032bf7..d45e55080 100644 --- a/connector_oxigesti/models/product_pricelist_item/listener.py +++ b/connector_oxigesti/models/product_pricelist_item/listener.py @@ -11,7 +11,7 @@ class ProductPricelistItemListener(Component): _apply_on = "product.pricelist.item" def on_record_unlink(self, relation): - bindings = relation.oxigesti_bind_ids + bindings = relation.sudo().oxigesti_bind_ids for backend in bindings.with_context( pricelist_item_unlink=relation.id ).backend_id: