From e779af09c1ba8e6e7738220fffc29705eb1c695c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 12 Dec 2022 09:02:14 +0100 Subject: [PATCH] [FIX] intrastat_product: Set the correct country code when the country of the delivery address is different (and to be consistent with the src_dest_country_id field). TT40764 --- intrastat_product/models/intrastat_product_declaration.py | 5 +++-- intrastat_product/tests/test_brexit.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index 793b40506..6daaa69e3 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -648,6 +648,7 @@ def _gather_invoices(self, notedict): domain = self._prepare_invoice_domain() order = "journal_id, name" invoices = self.env["account.move"].search(domain, order=order) + partner_model = self.env["res.partner"] for invoice in invoices: @@ -692,8 +693,8 @@ def _gather_invoices(self, notedict): # When the country is the same as the company's country must be skipped. if partner_country == self.company_id.country_id: continue - partner_country_code = ( - invoice.commercial_partner_id._get_intrastat_country_code() + partner_country_code = partner_model._get_intrastat_country_code( + country=partner_country, state=invoice.partner_shipping_id.state_id ) if inv_intrastat_line: diff --git a/intrastat_product/tests/test_brexit.py b/intrastat_product/tests/test_brexit.py index 5e3a4d116..a8e455f66 100644 --- a/intrastat_product/tests/test_brexit.py +++ b/intrastat_product/tests/test_brexit.py @@ -53,6 +53,7 @@ def test_brexit_sale(self): inv_out_xi = self.inv_obj.with_context(default_move_type="out_invoice").create( { "partner_id": self.partner_xi.id, + "partner_shipping_id": self.partner_xi.id, "fiscal_position_id": self.position.id, } )