Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits: 0423605b by Cédric Krier at 2023-04-11T23:38:33+02:00 Use warehouse from sale and purchase line to fill tax rule pattern Since 6efb525a7b23 the warehouse is always up to date for the line thanks to the on_change_with getter. Closes #12200 - - - - - 3 changed files: - modules/account_tax_rule_country/account.py - modules/account_tax_rule_country/purchase.py - modules/account_tax_rule_country/sale.py Changes: ===================================== modules/account_tax_rule_country/account.py ===================================== @@ -132,7 +132,7 @@ invoice_address = self.origin.purchase.invoice_address from_country = invoice_address.country from_subdivision = invoice_address.subdivision - warehouse = self.origin.purchase.warehouse + warehouse = self.origin.warehouse if warehouse and warehouse.address: to_country = warehouse.address.country to_subdivision = warehouse.address.subdivision ===================================== modules/account_tax_rule_country/purchase.py ===================================== @@ -20,8 +20,8 @@ class Line(metaclass=PoolMeta): __name__ = 'purchase.line' - @fields.depends('purchase', '_parent_purchase.warehouse', - '_parent_purchase.invoice_address') + @fields.depends( + 'purchase', 'warehouse', '_parent_purchase.invoice_address') def _get_tax_rule_pattern(self): pattern = super()._get_tax_rule_pattern() @@ -30,10 +30,9 @@ if self.purchase.invoice_address: from_country = self.purchase.invoice_address.country from_subdivision = self.purchase.invoice_address.subdivision - warehouse = self.purchase.warehouse - if warehouse and warehouse.address: - to_country = warehouse.address.country - to_subdivision = warehouse.address.subdivision + if self.warehouse and self.warehouse.address: + to_country = self.warehouse.address.country + to_subdivision = self.warehouse.address.subdivision pattern['from_country'] = from_country.id if from_country else None pattern['from_subdivision'] = ( ===================================== modules/account_tax_rule_country/sale.py ===================================== @@ -2,7 +2,7 @@ # this repository contains the full copyright notices and license terms. from trytond.model import fields -from trytond.pool import Pool, PoolMeta +from trytond.pool import PoolMeta from trytond.pyson import Eval @@ -20,6 +20,5 @@ class Line(metaclass=PoolMeta): __name__ = 'sale.line' - @fields.depends('sale', '_parent_sale.warehouse', - '_parent_sale.shipment_address') + @fields.depends('sale', 'warehouse', '_parent_sale.shipment_address') def _get_tax_rule_pattern(self): @@ -25,7 +24,4 @@ def _get_tax_rule_pattern(self): - pool = Pool() - Location = pool.get('stock.location') - pattern = super()._get_tax_rule_pattern() from_country = from_subdivision = to_country = to_subdivision = None @@ -29,15 +25,9 @@ pattern = super()._get_tax_rule_pattern() from_country = from_subdivision = to_country = to_subdivision = None - if self.id is None or self.id < 0: - warehouse = self.get_warehouse('warehouse') - if warehouse: - warehouse = Location(warehouse) - else: - warehouse = self.warehouse - if warehouse and warehouse.address: - from_country = warehouse.address.country - from_subdivision = warehouse.address.subdivision + if self.warehouse and self.warehouse.address: + from_country = self.warehouse.address.country + from_subdivision = self.warehouse.address.subdivision if self.sale and self.sale.shipment_address: to_country = self.sale.shipment_address.country to_subdivision = self.sale.shipment_address.subdivision View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/commit/0423605b5ac8ec5a3ef5d10368706170dbfde77f -- View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/commit/0423605b5ac8ec5a3ef5d10368706170dbfde77f You're receiving this email because of your account on foss.heptapod.net.