From e9956a29e1b90bd821d82a789d3c5148f267c79c Mon Sep 17 00:00:00 2001 From: Aritz Olea Date: Thu, 23 Nov 2023 15:11:14 +0100 Subject: [PATCH] [FIX] intrastat_product: Do not display missing VAT number error when fiscal position is B2C --- .../models/intrastat_product_declaration.py | 2 +- intrastat_product/tests/common.py | 5 +++ intrastat_product/tests/common_sale.py | 7 +++- intrastat_product/tests/test_sale_order.py | 37 +++++++++++++++++-- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index c3f2bac..06432e9 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -491,7 +491,7 @@ class IntrastatProductDeclaration(models.Model): notedict["partner"][partner.display_name][msg].add( notedict["inv_origin"] ) - else: + elif inv.fiscal_position_id.intrastat != "b2c": msg = _("Missing VAT Number") notedict["partner"][partner.display_name][msg].add( notedict["inv_origin"] diff --git a/intrastat_product/tests/common.py b/intrastat_product/tests/common.py index ea2aaca..8b2c211 100644 --- a/intrastat_product/tests/common.py +++ b/intrastat_product/tests/common.py @@ -41,6 +41,11 @@ class IntrastatProductCommon(IntrastatCommon): "vat_required": True, } cls.position = cls.position_obj.create(vals) + vals_b2c = { + "name": "Intrastat Fiscal Position B2C", + "intrastat": "b2c", + } + cls.position_b2c = cls.position_obj.create(vals_b2c) @classmethod def _init_regions(cls): diff --git a/intrastat_product/tests/common_sale.py b/intrastat_product/tests/common_sale.py index a12c368..875c33d 100644 --- a/intrastat_product/tests/common_sale.py +++ b/intrastat_product/tests/common_sale.py @@ -55,6 +55,9 @@ class IntrastatSaleCommon(IntrastatProductCommon): if vals is not None: values.update(vals) cls.customer = cls.partner_obj.create(values) + values.pop("vat") + values["property_account_position_id"] = cls.position_b2c.id + cls.customer_no_vat = cls.partner_obj.create(values) @classmethod def setUpClass(cls): @@ -63,9 +66,9 @@ class IntrastatSaleCommon(IntrastatProductCommon): cls._init_customer() @classmethod - def _create_sale_order(cls, vals=None): + def _create_sale_order(cls, partner, vals=None): vals = { - "partner_id": cls.customer.id, + "partner_id": partner.id, } sale_new = cls.sale_obj.new(vals) sale_vals = sale_new._convert_to_write(sale_new._cache) diff --git a/intrastat_product/tests/test_sale_order.py b/intrastat_product/tests/test_sale_order.py index d51e7c5..f4cab23 100644 --- a/intrastat_product/tests/test_sale_order.py +++ b/intrastat_product/tests/test_sale_order.py @@ -11,7 +11,7 @@ class TestIntrastatProductSale(IntrastatSaleCommon): """Tests for this module""" def test_sale_to_invoice_default(self): - self._create_sale_order() + self._create_sale_order(self.customer) self.sale.action_confirm() self.sale.picking_ids.action_assign() for line in self.sale.picking_ids.move_line_ids: @@ -30,7 +30,7 @@ class TestIntrastatProductSale(IntrastatSaleCommon): # Test specific transport set on sale to invoice def test_sale_to_invoice(self): - self._create_sale_order() + self._create_sale_order(self.customer) # Set intrastat transport mode to rail self.sale.intrastat_transport_id = self.transport_rail self.sale.action_confirm() @@ -53,7 +53,7 @@ class TestIntrastatProductSale(IntrastatSaleCommon): date_order = "2021-09-01" declaration_date = "2021-10-01" with freeze_time(date_order): - self._create_sale_order() + self._create_sale_order(self.customer) # Set intrastat transport mode to rail self.sale.intrastat_transport_id = self.transport_rail self.sale.action_confirm() @@ -87,6 +87,37 @@ class TestIntrastatProductSale(IntrastatSaleCommon): file_data = self._create_xls() self.check_xls(file_data[0]) + def test_sale_declaration_b2c_no_vat(self): + date_order = "2021-09-01" + declaration_date = "2021-10-01" + with freeze_time(date_order): + self._create_sale_order(self.customer_no_vat) + # Set intrastat transport mode to rail + self.sale.intrastat_transport_id = self.transport_rail + self.sale.action_confirm() + self.sale.picking_ids.action_assign() + for line in self.sale.picking_ids.move_line_ids: + line.qty_done = line.reserved_uom_qty + self.sale.picking_ids._action_done() + self.assertEqual("done", self.sale.picking_ids.state) + + with freeze_time(date_order): + invoice = self.sale._create_invoices() + invoice.action_post() + + # Check if transport mode has been transmitted to invoice + self.assertEqual( + self.transport_rail, + invoice.intrastat_transport_id, + ) + vals = { + "declaration_type": "dispatches", + } + with freeze_time(declaration_date): + self._create_declaration(vals) + self.declaration.action_gather() + self.assertFalse(self.declaration.note) + class TestIntrastatProductSaleCase(TestIntrastatProductSale, TransactionCase): """Test Intrastat Sale"""