Skip to content

Commit 056a49a

Browse files
committed
[ADD] l10n_latam_invoice_document_ux: Add new module to handle duplication of errors
1 parent 10fa70f commit 056a49a

4 files changed

Lines changed: 49 additions & 55 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import account_move
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo import models
4+
5+
6+
class AccountMove(models.Model):
7+
_inherit = "account.move"
8+
9+
def _post(self, soft=True):
10+
"""Override to validate document number format before posting.
11+
This ensures format errors are shown first, preventing duplicate error messages.
12+
Only applies to vendor bills."""
13+
# Validate document number format before posting (only for vendor bills)
14+
vendor_bills = self.filtered(
15+
lambda x: (
16+
x.l10n_latam_use_documents
17+
and x.l10n_latam_manual_document_number
18+
and x.move_type in ("in_invoice", "in_refund")
19+
)
20+
)
21+
for rec in vendor_bills:
22+
if rec.l10n_latam_document_number and rec.l10n_latam_document_type_id:
23+
if not rec._skip_format_document_number():
24+
# This will raise UserError if format is invalid
25+
# We let it propagate so the user sees the original format error
26+
rec.l10n_latam_document_type_id._format_document_number(rec.l10n_latam_document_number)
27+
return super()._post(soft)

l10n_latam_invoice_document_ux/tests/test_patch_l10n_ar.py

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,6 @@ def test_dummy(self):
1313
if tools.config.get("test_enable"):
1414
from odoo.addons.l10n_ar.tests.test_manual import TestArManual
1515

16-
def test_15_liquido_producto_sales_patch(self):
17-
"""Patcheamos para que la validacion se haga al momento de validar la factura y no antes"""
18-
19-
# Verify that the default sales journals ara created as is ARCA POS
20-
self.assertTrue(self.journal.l10n_ar_is_pos)
21-
22-
# If we create an invoice it will not use manual numbering
23-
invoice = self._create_invoice_ar()
24-
self.assertFalse(invoice.l10n_latam_manual_document_number)
25-
26-
# Create a new sale journal that is not ARCA POS
27-
self.journal = self._create_journal("preprinted", data={"l10n_ar_is_pos": False})
28-
self.assertFalse(self.journal.l10n_ar_is_pos)
29-
30-
doc_27_lu_a = self.env.ref("l10n_ar.dc_liq_uci_a")
31-
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
32-
33-
# 60, 61, 27, 28, 45, 46
34-
# In this case manual numbering should be True and the latam document numer should be required
35-
with self.assertRaisesRegex(AssertionError, "l10n_latam_document_number is a required field"):
36-
with Form(self.env["account.move"].with_context(default_move_type="out_invoice")) as invoice_form:
37-
invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
38-
invoice_form.partner_id = self.res_partner_adhoc
39-
invoice_form.invoice_payment_term_id = payment_term_id
40-
invoice_form.journal_id = self.journal
41-
invoice_form.l10n_latam_document_type_id = doc_27_lu_a
42-
invoice = invoice_form.save()
43-
invoice.action_post() # Agregamos esta linea para que se dispare la validacion al momento de validar la factura y no antes
44-
45-
# Adding the document number will let us to save and validate the number without any problems
46-
with Form(self.env["account.move"].with_context(default_move_type="out_invoice")) as invoice_form:
47-
invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
48-
invoice_form.partner_id = self.res_partner_adhoc
49-
invoice_form.invoice_payment_term_id = payment_term_id
50-
invoice_form.journal_id = self.journal
51-
invoice_form.l10n_latam_document_type_id = doc_27_lu_a
52-
invoice_form.l10n_latam_document_number = "00077-00000077"
53-
invoice = invoice_form.save()
54-
invoice.action_post()
55-
5616
def test_16_liquido_producto_purchase_patch(self):
5717
"""Patcheamos para que la validacion se haga al momento de validar la factura y no antes"""
5818

@@ -69,17 +29,23 @@ def test_16_liquido_producto_purchase_patch(self):
6929
doc_60_lp_a = self.env.ref("l10n_ar.dc_a_cvl")
7030
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
7131

72-
with self.assertRaisesRegex(AssertionError, "l10n_latam_document_number is a required field"):
73-
with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form:
74-
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
75-
bill_form.partner_id = self.res_partner_adhoc
76-
bill_form.invoice_payment_term_id = payment_term_id
77-
bill_form.invoice_date = "2023-02-09"
78-
bill_form.l10n_latam_document_type_id = doc_60_lp_a
79-
bill = bill_form.save()
80-
bill.action_post() # Agregamos esta linea para que se dispare la validacion al momento de validar la factura y no antes
32+
with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form:
33+
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
34+
bill_form.partner_id = self.res_partner_adhoc
35+
bill_form.invoice_payment_term_id = payment_term_id
36+
bill_form.invoice_date = "2023-02-09"
37+
bill_form.l10n_latam_document_type_id = doc_60_lp_a
38+
with bill_form.invoice_line_ids.new() as line_form:
39+
line_form.product_id = self.env.ref("product.product_product_4")
40+
line_form.quantity = 1
41+
line_form.price_unit = 100
42+
bill = bill_form.save()
8143

82-
self.assertEqual(bill.journal_id, purchase_not_pos_journal)
44+
self.assertEqual(bill.journal_id, purchase_not_pos_journal)
45+
46+
# Should fail when posting without document number
47+
with self.assertRaisesRegex(AssertionError, "l10n_latam_document_number is a required field"):
48+
bill.action_post()
8349

8450
# Create a new journal that is an ARCA POS
8551
purchase_pos_journal = self._create_journal("preprinted", data={"type": "purchase", "l10n_ar_is_pos": True})
@@ -92,6 +58,10 @@ def test_16_liquido_producto_purchase_patch(self):
9258
bill_form.journal_id = purchase_pos_journal
9359
bill_form.l10n_latam_document_type_id = doc_60_lp_a
9460
bill_form.l10n_latam_document_number = "00077-00000077"
61+
with bill_form.invoice_line_ids.new() as line_form:
62+
line_form.product_id = self.env.ref("product.product_product_4")
63+
line_form.quantity = 1
64+
line_form.price_unit = 100
9565
bill = bill_form.save()
9666
bill.action_post()
9767

@@ -112,11 +82,6 @@ def _patch_method(cls, name, method):
11282
wrapped.origin = origin
11383
setattr(cls, name, wrapped)
11484

115-
_patch_method(
116-
TestArManual,
117-
"test_15_liquido_producto_sales",
118-
test_15_liquido_producto_sales_patch,
119-
)
12085
_patch_method(
12186
TestArManual,
12287
"test_16_liquido_producto_purchase",

0 commit comments

Comments
 (0)