Skip to content

Commit 05dab5b

Browse files
committed
[ADD] l10n_latam_invoice_document_ux: patch unit tests
1 parent 22e642e commit 05dab5b

6 files changed

Lines changed: 200 additions & 4 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. |company| replace:: ADHOC SA
2+
3+
.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
4+
:alt: ADHOC SA
5+
:target: https://www.adhoc.com.ar
6+
7+
.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png
8+
9+
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
10+
:target: https://www.gnu.org/licenses/agpl
11+
:alt: License: AGPL-3
12+
13+
=============================
14+
Latam Invoice Document UX
15+
=============================
16+
17+
This module improves the user experience for LATAM invoice documents by making document type and document number fields required at validation time instead of at form level.
18+
19+
20+
Installation
21+
============
22+
23+
To install this module, you need to:
24+
25+
#. Only need to install the module
26+
27+
Configuration
28+
=============
29+
30+
To configure this module, you need to:
31+
32+
#. Nothing to configure
33+
34+
Usage
35+
=====
36+
37+
This module modifies the validation behavior of LATAM invoice documents:
38+
39+
#. Document type and document number fields are now required when validating invoices with manual numbering
40+
#. This allows users to fill in the form without being forced to enter these fields immediately
41+
#. The validation ensures data integrity when the invoice is posted
42+
43+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
44+
:alt: Try me on Runbot
45+
:target: http://runbot.adhoc.com.ar/
46+
47+
Bug Tracker
48+
===========
49+
50+
Bugs are tracked on `GitHub Issues
51+
<https://github.com/ingadhoc/account-invoicing/issues>`_. In case of trouble, please
52+
check there if your issue has already been reported. If you spotted it first,
53+
help us smashing it by providing a detailed and welcomed feedback.
54+
55+
Credits
56+
=======
57+
58+
Images
59+
------
60+
61+
* |company| |icon|
62+
63+
Contributors
64+
------------
65+
66+
Maintainer
67+
----------
68+
69+
|company_logo|
70+
71+
This module is maintained by the |company|.
72+
73+
To contribute to this module, please visit https://www.adhoc.com.ar.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

l10n_latam_invoice_document_ux/models/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_patch_l10n_ar
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
from odoo import tools
2+
from odoo.tests import Form, common, tagged
3+
4+
5+
@tagged("post_install", "-at_install")
6+
class TestPatchDummy(common.TransactionCase):
7+
def test_dummy(self):
8+
# a trivial test so the test runner reports >0 tests (avoids the 0-tests warning)
9+
self.assertTrue(True)
10+
11+
12+
# Only apply the patch while running tests
13+
if tools.config.get("test_enable"):
14+
from odoo.addons.l10n_ar.tests.test_manual import TestArManual
15+
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+
56+
def test_16_liquido_producto_purchase_patch(self):
57+
"""Patcheamos para que la validacion se haga al momento de validar la factura y no antes"""
58+
59+
# By default purchase journals ar not ARCA POS journal
60+
purchase_not_pos_journal = self.env["account.journal"].search(
61+
[
62+
("type", "=", "purchase"),
63+
("company_id", "=", self.env.company.id),
64+
("l10n_latam_use_documents", "=", True),
65+
]
66+
)
67+
self.assertFalse(purchase_not_pos_journal.l10n_ar_is_pos)
68+
69+
doc_60_lp_a = self.env.ref("l10n_ar.dc_a_cvl")
70+
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
71+
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
81+
82+
self.assertEqual(bill.journal_id, purchase_not_pos_journal)
83+
84+
# Create a new journal that is an ARCA POS
85+
purchase_pos_journal = self._create_journal("preprinted", data={"type": "purchase", "l10n_ar_is_pos": True})
86+
87+
with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form:
88+
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
89+
bill_form.partner_id = self.res_partner_adhoc
90+
bill_form.invoice_payment_term_id = payment_term_id
91+
bill_form.invoice_date = "2023-02-09"
92+
bill_form.journal_id = purchase_pos_journal
93+
bill_form.l10n_latam_document_type_id = doc_60_lp_a
94+
bill_form.l10n_latam_document_number = "00077-00000077"
95+
bill = bill_form.save()
96+
bill.action_post()
97+
98+
# If we create an invoice it will not use manual numbering
99+
self.assertFalse(bill.l10n_latam_manual_document_number)
100+
101+
def propagate(method1, method2):
102+
if method1:
103+
for attr in ("_returns",):
104+
if hasattr(method1, attr) and not hasattr(method2, attr):
105+
setattr(method2, attr, getattr(method1, attr))
106+
return method2
107+
108+
def _patch_method(cls, name, method):
109+
origin = getattr(cls, name)
110+
method.origin = origin
111+
wrapped = propagate(origin, method)
112+
wrapped.origin = origin
113+
setattr(cls, name, wrapped)
114+
115+
_patch_method(
116+
TestArManual,
117+
"test_15_liquido_producto_sales",
118+
test_15_liquido_producto_sales_patch,
119+
)
120+
_patch_method(
121+
TestArManual,
122+
"test_16_liquido_producto_purchase",
123+
test_16_liquido_producto_purchase_patch,
124+
)

l10n_latam_invoice_document_ux/views/account_move_view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<field name="arch" type="xml">
99
<!-- Solo hacemos requeridos estos campo cuando validamos la factura, no antes-->
1010
<field name="l10n_latam_document_number" position="attributes">
11-
<attribute name="required">0</attribute>
11+
<attribute name="required"/>
1212
</field>
1313
<field name="l10n_latam_document_type_id" position="attributes">
14-
<attribute name="required">0</attribute>
14+
<attribute name="required"/>
1515
</field>
1616
</field>
1717
</record>

0 commit comments

Comments
 (0)