From 8f7b1c015130c1b3697b8e6ea73180327b87ccd2 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Wed, 6 Mar 2024 12:55:29 +0100 Subject: [PATCH 1/2] [IMP] l10n_es_aeat_mod349: add tests for rectified bills When we enter refunds in another period, the rectifications section must correctly report the right amounts. --- .../tests/test_l10n_es_aeat_mod349.py | 79 ++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/l10n_es_aeat_mod349/tests/test_l10n_es_aeat_mod349.py b/l10n_es_aeat_mod349/tests/test_l10n_es_aeat_mod349.py index d522d22acc7..5833ca40106 100644 --- a/l10n_es_aeat_mod349/tests/test_l10n_es_aeat_mod349.py +++ b/l10n_es_aeat_mod349/tests/test_l10n_es_aeat_mod349.py @@ -23,7 +23,7 @@ class TestL10nEsAeatMod349Base(TestL10nEsAeatModBase): "P_IVA21_IC_BC//2": (150, 0), } - def test_model_349(self): + def test_model_349_01(self): # Add some test data self.customer.write( {"vat": "BE0411905847", "country_id": self.env.ref("base.be").id} @@ -152,7 +152,7 @@ def test_model_349(self): ) self.assertEqual(a_record.total_operation_amount, 300) # Create a substitutive presentation for 2T 2017. - # We create a refund of p1, and a new sale + # We create a refund of p1 and p2 and a new sale self._invoice_refund(p1, "2017-04-01") self._invoice_sale_create("2017-04-01") model349_2t = model349_model.create( @@ -210,3 +210,78 @@ def test_model_349(self): self.env.ref("l10n_es_aeat_mod349.act_report_aeat_mod349_pdf")._render( model349.ids ) + + def test_model_349_02(self): + """When we enter refunds in another period, the rectifications section must correctly + report the right amounts""" + # Add some test data + self.customer.write( + {"vat": "BE0411905847", "country_id": self.env.ref("base.be").id} + ) + self.supplier.write( + {"vat": "BG0000100159", "country_id": self.env.ref("base.bg").id} + ) + # Data for 1T 2017 + # Purchase invoices + p1 = self._invoice_purchase_create("2017-01-01") + p2 = self._invoice_purchase_create("2017-01-02") + # Create model + model349_model = self.env["l10n.es.aeat.mod349.report"].with_user( + self.account_manager + ) + model349_1t = model349_model.create( + { + "name": "3490000000001", + "company_id": self.company.id, + "company_vat": "1234567890", + "contact_name": "Test owner", + "statement_type": "N", + "support_type": "T", + "contact_phone": "911234455", + "year": 2017, + "period_type": "1T", + "date_start": "2017-01-01", + "date_end": "2017-03-31", + } + ) + # Calculate + _logger.debug("Calculate AEAT 349 1T 2017") + model349_1t.button_calculate() + self.assertEqual(model349_1t.total_partner_records, 1) + # p1 + p2 = 2400 + 2400 = 4800 + self.assertEqual(model349_1t.total_partner_records_amount, 600.00) + self.assertEqual(model349_1t.total_partner_refunds, 0) + self.assertEqual(model349_1t.total_partner_refunds_amount, 0.0) + # Now create 2T 2017, refunding the first two bills + self._invoice_refund(p1, "2017-04-01") + self._invoice_refund(p2, "2017-04-02") + model349_2t = model349_model.create( + { + "name": "3490000000002", + "company_id": self.company.id, + "company_vat": "1234567890", + "contact_name": "Test owner", + "statement_type": "N", + "support_type": "T", + "contact_phone": "911234455", + "year": 2017, + "period_type": "2T", + "date_start": "2017-04-01", + "date_end": "2017-06-30", + } + ) + # Calculate + _logger.debug("Calculate AEAT 349 2T 2017") + model349_2t.button_calculate() + self.assertEqual(model349_2t.total_partner_records, 0) + # p1 + p2 - + self.assertEqual(model349_2t.total_partner_records_amount, 0.0) + self.assertEqual(model349_2t.total_partner_refunds, 1) + self.assertEqual(model349_2t.total_partner_refunds_amount, 600.0) + a_refund = model349_2t.partner_refund_ids.filtered( + lambda x: x.operation_key == "A" + ) + self.assertEqual(len(a_refund), 1) + self.assertEqual(len(a_refund.refund_detail_ids), 4) + self.assertEqual(a_refund.total_origin_amount, 600.0) + self.assertEqual(a_refund.total_operation_amount, 0.0) From 16a7dcede19b68284cfcd8b0e7cdad308235b5a0 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Wed, 6 Mar 2024 13:03:04 +0100 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20l10n=5Fes=5Faeat=5Fmod349:=20Import?= =?UTF-8?q?e=20original=20incorrecto=20en=20rectificaciones=20de=20otros?= =?UTF-8?q?=20periodos=20Se=20crean=20dos=20facturas=20para=20mismo=20prov?= =?UTF-8?q?eedor=20en=20un=20periodo,=20y=20en=20el=20siguiente=20periodo?= =?UTF-8?q?=20se=20hacen=20abonos.=20En=20el=20segundo=20periodo=20del=203?= =?UTF-8?q?49=20se=20observa=20que=20el=20importe=20original=20en=20rectif?= =?UTF-8?q?icaciones=20de=20otros=20periodos=20es=20incorrecto.=20Est?= =?UTF-8?q?=C3=A1=20duplicado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n_es_aeat_mod349/models/mod349.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/l10n_es_aeat_mod349/models/mod349.py b/l10n_es_aeat_mod349/models/mod349.py index 90cb6e9e910..3ae2fd398a8 100644 --- a/l10n_es_aeat_mod349/models/mod349.py +++ b/l10n_es_aeat_mod349/models/mod349.py @@ -214,20 +214,18 @@ def _create_349_refund_records(self): [ ("move_line_id.move_id", "=", origin_invoice.id), ("partner_record_id.operation_key", "=", op_key), - ("id", "not in", visited_details.ids), ], order="report_id desc", + limit=1, ) - # we add all of them to visited, as we don't want to repeat - visited_details |= original_details - if original_details: + origin_amount = 0.0 + if original_details and original_details not in visited_details: # There's at least one previous 349 declaration report report = original_details.mapped("report_id")[:1] partner_id = original_details.mapped("partner_id")[:1] original_details = original_details.filtered( lambda d: d.report_id == report ) - origin_amount = sum(original_details.mapped("amount_untaxed")) period_type = report.period_type year = str(report.year) @@ -240,6 +238,7 @@ def _create_349_refund_records(self): ], order="report_id desc", ) + visited_details |= all_details_period origin_amount = sum(all_details_period.mapped("amount_untaxed")) # If there are intermediate periods between the original @@ -269,7 +268,11 @@ def _create_349_refund_records(self): origin_amount = ( last_refund_detail.refund_id.total_operation_amount ) - + elif original_details and original_details in visited_details: + # This move corresponds to a period that has already been rectified + report = original_details.mapped("report_id")[:1] + period_type = report.period_type + year = str(report.year) else: # There's no previous 349 declaration report in Odoo original_amls = move_line_obj.search( @@ -299,6 +302,8 @@ def _create_349_refund_records(self): period_type = "%sT" % int(math.ceil(int(month) / 3.0)) else: period_type = month + # we add all of them to visited, as we don't want to repeat + visited_details |= original_details key = (partner, op_key, period_type, year) key_vals = data.setdefault( key, {"original_amount": 0, "refund_details": refund_detail_obj}