From 66560cd983fdf048ce5a7dfb7ed5eb1b8d75c49e Mon Sep 17 00:00:00 2001 From: Jorge-C0 <53841628+Jorge-C0@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:47:02 -0400 Subject: [PATCH] [14.0][FIX] l10n_do_accounting: fix seq with same prefix in diferent year (#1158) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FIX] l10n_do_accounting: fix seq with same prefix in diferent year * [REF] l10n_do_accounting: use posted_before --------- Co-authored-by: José López --- l10n_do_accounting/__manifest__.py | 2 +- l10n_do_accounting/models/account_move.py | 17 +++++++++++++++++ l10n_do_accounting/tests/test_account_move.py | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/l10n_do_accounting/__manifest__.py b/l10n_do_accounting/__manifest__.py index 3c954a38..3aab77d3 100644 --- a/l10n_do_accounting/__manifest__.py +++ b/l10n_do_accounting/__manifest__.py @@ -8,7 +8,7 @@ "category": "Localization", "license": "LGPL-3", "website": "https://github.com/odoo-dominicana", - "version": "17.0.1.0.1", + "version": "17.0.1.0.2", "countries": ["do"], # any module necessary for this one to work correctly "depends": ["l10n_latam_invoice_document", "l10n_do"], diff --git a/l10n_do_accounting/models/account_move.py b/l10n_do_accounting/models/account_move.py index ffd0e2bd..b8700acf 100644 --- a/l10n_do_accounting/models/account_move.py +++ b/l10n_do_accounting/models/account_move.py @@ -873,3 +873,20 @@ def unlink(self): _("You cannot delete fiscal invoice which have been posted before") ) return super(AccountMove, self).unlink() + + # Extension of the _deduce_sequence_number_reset function to compute the `name` field according to the invoice + # date and prevent the `l10n_latam_document_number` field from being reset + @api.model + def _deduce_sequence_number_reset(self, name): + if ( + self.l10n_latam_use_documents + and self.company_id.country_id.code == "DO" + and self.posted_before + and not self._context.get("is_l10n_do_seq", False) + ): + return "year" + elif self._context.get("is_l10n_do_seq", False): + return "never" + else: + "never" + return super(AccountMove, self)._deduce_sequence_number_reset(name) diff --git a/l10n_do_accounting/tests/test_account_move.py b/l10n_do_accounting/tests/test_account_move.py index 675e1ee1..08fabbbd 100644 --- a/l10n_do_accounting/tests/test_account_move.py +++ b/l10n_do_accounting/tests/test_account_move.py @@ -708,6 +708,17 @@ def test_009_invoice_sequence(self): self.assertEqual(invoice_2.name, "INV/%s/0002" % invoice_2.date.year) self.assertEqual(invoice_2.l10n_do_fiscal_number, "B0100000002") + # Unit test to verify if the invoice number or document number is repeated + invoice_3 = self._create_l10n_do_invoice( + data={ + "invoice_date": "2023-05-08", + } + ) + invoice_3._post() + self.assertEqual(invoice_3.name, "INV/%s/0001" % invoice_3.date.year) + self.assertNotEqual(invoice_3.l10n_do_fiscal_number, "B0100000001") + self.assertEqual(invoice_3.l10n_do_fiscal_number, "B0100000003") + def test_010_ncf_format(self): with self.assertRaises(ValidationError): self._create_l10n_do_invoice(data={"document_number": "E0100000001"})