-
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_oxigesti: logic for deprecated field of pricelist item
- Loading branch information
Showing
5 changed files
with
134 additions
and
19 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from . import export_mapper | ||
from . import binder | ||
from . import binding | ||
from . import listener |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Copyright NuoBiT Solutions - Eric Antones <[email protected]> | ||
# Copyright NuoBiT Solutions - Kilian Niubo <[email protected]> | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import api, fields, models | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductPricelistItem(models.Model): | ||
|
@@ -14,6 +16,32 @@ class ProductPricelistItem(models.Model): | |
string="Oxigesti Bindings", | ||
) | ||
|
||
@api.constrains("compute_price", "applied_on", "product_tmpl_id") | ||
def _check_binding(self): | ||
if self.oxigesti_bind_ids: | ||
partners = ( | ||
self.env["res.partner"] | ||
.search( | ||
[ | ||
("company_id", "=?", self.company_id.id), | ||
] | ||
) | ||
.filtered( | ||
lambda x: x.property_product_pricelist.id == self.pricelist_id.id | ||
) | ||
) | ||
if partners: | ||
raise ValidationError( | ||
_( | ||
"You can't change the product, the price calculation " | ||
"method or the applied on field of a pricelist item " | ||
"because they have been exported the product prices by " | ||
"customer to Oxigesti.\nIf you need to change any of " | ||
"these fields, you can delete the pricelist item and " | ||
"create a new one." | ||
) | ||
) | ||
|
||
|
||
class ProductPricelistItemBinding(models.Model): | ||
_name = "oxigesti.product.pricelist.item" | ||
|
@@ -44,6 +72,8 @@ class ProductPricelistItemBinding(models.Model): | |
), | ||
] | ||
|
||
deprecated = fields.Boolean() | ||
|
||
@api.model | ||
def export_data(self, backend, since_date): | ||
domain = [("company_id", "in", (backend.company_id.id, False))] | ||
|
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
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
23 changes: 23 additions & 0 deletions
23
connector_oxigesti/models/product_pricelist_item/listener.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,23 @@ | ||
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo.addons.component.core import Component | ||
|
||
|
||
class ProductPricelistItemListener(Component): | ||
_name = "oxigesti.product.pricelist.item.listener" | ||
_inherit = "oxigesti.event.listener" | ||
|
||
_apply_on = "product.pricelist.item" | ||
|
||
def on_record_unlink(self, relation): | ||
bindings = relation.oxigesti_bind_ids | ||
for backend in bindings.with_context( | ||
pricelist_item_unlink=relation.id | ||
).backend_id: | ||
partners = bindings.filtered( | ||
lambda x: x.backend_id == backend | ||
).odoo_partner_id | ||
with backend.work_on(bindings._name) as work: | ||
exporter = work.component(usage="direct.batch.exporter") | ||
exporter.run([("id", "=", partners.ids)]) | ||