diff --git a/modules/account_tax_rule_country/__init__.py b/modules/account_tax_rule_country/__init__.py index 4def8f2788..99600edd41 100644 --- a/modules/account_tax_rule_country/__init__.py +++ b/modules/account_tax_rule_country/__init__.py @@ -3,7 +3,7 @@ from trytond.pool import Pool -from . import account, purchase, sale, stock +from . import account, purchase, sale def register(): @@ -26,7 +26,3 @@ def register(): purchase.Line, module='account_tax_rule_country', type_='model', depends=['purchase']) - Pool.register( - stock.Move, - module='account_tax_rule_country', type_='model', - depends=['stock']) diff --git a/modules/account_tax_rule_country/account.py b/modules/account_tax_rule_country/account.py index 39e9be9827..d28a6db1d0 100644 --- a/modules/account_tax_rule_country/account.py +++ b/modules/account_tax_rule_country/account.py @@ -114,6 +114,12 @@ class InvoiceLine(metaclass=PoolMeta): PurchaseLine = pool.get('purchase.line') except KeyError: PurchaseLine = None + try: + Move = pool.get('stock.move') + ShipmentOut = pool.get('stock.shipment.out') + ShipmentOutReturn = pool.get('stock.shipment.out.return') + except KeyError: + Move = ShipmentOut = ShipmentOutReturn = None pattern = super(InvoiceLine, self)._get_tax_rule_pattern() @@ -138,6 +144,28 @@ class InvoiceLine(metaclass=PoolMeta): 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 + if move.from_location.warehouse: + warehouse_address = move.from_location.warehouse.address + if warehouse_address: + from_country = warehouse_address.country + from_subdivision = warehouse_address.subdivision + elif isinstance(move.origin, ShipmentOutReturn): + delivery_address = move.origin.delivery_address + from_country = delivery_address.country + from_subdivision = delivery_address.subdivision + if move.to_location.warehouse: + warehouse_address = move.to_location.warehouse.address + if warehouse_address: + to_country = warehouse_address.country + to_subdivision = warehouse_address.subdivision + elif isinstance(move.origin, ShipmentOut): + delivery_address = move.origin.delivery_address + to_country = delivery_address.country + to_subdivision = delivery_address.subdivision pattern['from_country'] = from_country.id if from_country else None pattern['from_subdivision'] = ( diff --git a/modules/account_tax_rule_country/stock.py b/modules/account_tax_rule_country/stock.py deleted file mode 100644 index 0c5b167173..0000000000 --- a/modules/account_tax_rule_country/stock.py +++ /dev/null @@ -1,43 +0,0 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. - -from trytond.pool import Pool, PoolMeta - - -class Move(metaclass=PoolMeta): - __name__ = 'stock.move' - - def _get_tax_rule_pattern(self): - pool = Pool() - ShipmentOut = pool.get('stock.shipment.out') - ShipmentOutReturn = pool.get('stock.shipment.out.return') - - pattern = super(Move, self)._get_tax_rule_pattern() - - from_country = from_subdivision = to_country = to_subdivision = None - if self.from_location.warehouse: - warehouse_address = self.from_location.warehouse.address - if warehouse_address: - from_country = warehouse_address.country - from_subdivision = warehouse_address.subdivision - elif isinstance(self.origin, ShipmentOutReturn): - delivery_address = self.origin.delivery_address - from_country = delivery_address.country - from_subdivision = delivery_address.subdivision - if self.to_location.warehouse: - warehouse_address = self.to_location.warehouse.address - if warehouse_address: - to_country = warehouse_address.country - to_subdivision = warehouse_address.subdivision - elif isinstance(self.origin, ShipmentOut): - delivery_address = self.origin.delivery_address - to_country = delivery_address.country - to_subdivision = delivery_address.subdivision - - pattern['from_country'] = from_country.id if from_country else None - pattern['from_subdivision'] = ( - from_subdivision.id if from_subdivision else None) - pattern['to_country'] = to_country.id if to_country else None - pattern['to_subdivision'] = ( - to_subdivision.id if to_subdivision else None) - return pattern diff --git a/modules/account_tax_rule_country/tryton.cfg b/modules/account_tax_rule_country/tryton.cfg index 7c559abb5a..acdddbb4db 100644 --- a/modules/account_tax_rule_country/tryton.cfg +++ b/modules/account_tax_rule_country/tryton.cfg @@ -7,6 +7,6 @@ extras_depend: account_invoice purchase sale - stock_consignment + stock xml: account.xml