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
This commit is contained in:
Cédric Krier
2023-04-11 23:38:33 +02:00
parent d31d4dd554
commit 228743d45b
3 changed files with 11 additions and 22 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ class InvoiceLine(metaclass=PoolMeta):
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
+5 -6
View File
@@ -20,8 +20,8 @@ class Purchase(metaclass=PoolMeta):
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 @@ class Line(metaclass=PoolMeta):
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'] = (
+5 -15
View File
@@ -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,24 +20,14 @@ class Sale(metaclass=PoolMeta):
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):
pool = Pool()
Location = pool.get('stock.location')
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