From 0a3cbcb67c5e09d36fc2af4df1200f277803b706 Mon Sep 17 00:00:00 2001 From: Maxime Richez Date: Wed, 18 Mar 2026 12:01:17 +0100 Subject: [PATCH] Use the first non-invoice line origin to calculate tax pattern for countries Closes #14388 (grafted from e97af2f1eb234d2f08f893a49b16da6b1660bab5) --HG-- branch : 7.0 --- modules/account_tax_rule_country/account.py | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/modules/account_tax_rule_country/account.py b/modules/account_tax_rule_country/account.py index d28a6db1d0..7798e6b197 100644 --- a/modules/account_tax_rule_country/account.py +++ b/modules/account_tax_rule_country/account.py @@ -124,30 +124,34 @@ class InvoiceLine(metaclass=PoolMeta): pattern = super(InvoiceLine, self)._get_tax_rule_pattern() from_country = from_subdivision = to_country = to_subdivision = None + origin = self.origin + # find the first origin which is not an invoice line + while isinstance(origin, self.__class__) and origin.id >= 0: + origin = origin.origin if (SaleLine - and isinstance(self.origin, SaleLine) - and self.origin.id >= 0): - warehouse = self.origin.warehouse + and isinstance(origin, SaleLine) + and origin.id >= 0): + warehouse = origin.warehouse if warehouse and warehouse.address: from_country = warehouse.address.country from_subdivision = warehouse.address.subdivision - shipment_address = self.origin.sale.shipment_address + shipment_address = origin.sale.shipment_address to_country = shipment_address.country to_subdivision = shipment_address.subdivision elif (PurchaseLine - and isinstance(self.origin, PurchaseLine) - and self.origin.id >= 0): - invoice_address = self.origin.purchase.invoice_address + and isinstance(origin, PurchaseLine) + and origin.id >= 0): + invoice_address = origin.purchase.invoice_address from_country = invoice_address.country from_subdivision = invoice_address.subdivision - warehouse = self.origin.warehouse + warehouse = origin.warehouse if warehouse and warehouse.address: to_country = warehouse.address.country to_subdivision = warehouse.address.subdivision elif (Move - and isinstance(self.origin, Move) - and self.origin.id >= 0): - move = self.origin + and isinstance(origin, Move) + and origin.id >= 0): + move = origin if move.from_location.warehouse: warehouse_address = move.from_location.warehouse.address if warehouse_address: