Skip to content

Commit ef35422

Browse files
committed
[ADD] l10n_latam_invoice_document_ux: new module to add UX improvements to the invoice document in latam countries
closes #256 Signed-off-by: Julia Elizondo - jue (#l10n) <jue@adhoc.com.ar>
1 parent 14904b9 commit ef35422

6 files changed

Lines changed: 255 additions & 0 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.

l10n_latam_invoice_document_ux/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "Latam Invoice Document UX",
3+
"version": "19.0.1.0.0",
4+
"author": "ADHOC SA",
5+
"website": "www.adhoc.com.ar",
6+
"license": "AGPL-3",
7+
"category": "Localization",
8+
"depends": [
9+
"l10n_latam_invoice_document",
10+
],
11+
"data": [
12+
"views/account_move_view.xml",
13+
],
14+
"installable": True,
15+
"auto_install": False,
16+
"application": False,
17+
}
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: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
from odoo import tools
2+
from odoo.exceptions import ValidationError
3+
from odoo.tests import Form, common, tagged
4+
5+
6+
@tagged("post_install", "-at_install")
7+
class TestPatchDummy(common.TransactionCase):
8+
def test_dummy(self):
9+
# a trivial test so the test runner reports >0 tests (avoids the 0-tests warning)
10+
self.assertTrue(True)
11+
12+
13+
# Only apply the patch while running tests
14+
if tools.config.get("test_enable"):
15+
from odoo.addons.l10n_ar.tests.test_manual import TestArManual
16+
17+
def test_15_liquido_producto_sales_patch(self):
18+
"""Patcheamos para que la validacion se haga al momento de validar la factura y no antes"""
19+
20+
# Verify that the default sales journals ara created as is ARCA POS
21+
self.assertTrue(self.journal.l10n_ar_is_pos)
22+
23+
# If we create an invoice it will not use manual numbering
24+
invoice = self._create_invoice_ar()
25+
self.assertFalse(invoice.l10n_latam_manual_document_number)
26+
27+
# Create a new sale journal that is not ARCA POS
28+
self.journal = self._create_journal("preprinted", data={"l10n_ar_is_pos": False})
29+
self.assertFalse(self.journal.l10n_ar_is_pos)
30+
31+
doc_27_lu_a = self.env.ref("l10n_ar.dc_liq_uci_a")
32+
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
33+
34+
# 60, 61, 27, 28, 45, 46
35+
# In this case manual numbering should be True and the latam document numer should be required
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+
with invoice_form.invoice_line_ids.new() as line_form:
43+
line_form.product_id = self.env.ref("product.product_product_4")
44+
line_form.quantity = 1
45+
line_form.price_unit = 100
46+
invoice = invoice_form.save()
47+
48+
# Should fail when posting without document number
49+
with self.assertRaisesRegex(ValidationError, "Please set the document number"):
50+
invoice.action_post()
51+
52+
# Adding the document number will let us to save and validate the number without any problems
53+
with Form(self.env["account.move"].with_context(default_move_type="out_invoice")) as invoice_form:
54+
invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
55+
invoice_form.partner_id = self.res_partner_adhoc
56+
invoice_form.invoice_payment_term_id = payment_term_id
57+
invoice_form.journal_id = self.journal
58+
invoice_form.l10n_latam_document_type_id = doc_27_lu_a
59+
invoice_form.l10n_latam_document_number = "00077-00000077"
60+
with invoice_form.invoice_line_ids.new() as line_form:
61+
line_form.product_id = self.env.ref("product.product_product_4")
62+
line_form.quantity = 1
63+
line_form.price_unit = 100
64+
invoice = invoice_form.save()
65+
invoice.action_post()
66+
67+
def test_16_liquido_producto_purchase_patch(self):
68+
"""Patcheamos para que la validacion se haga al momento de validar la factura y no antes"""
69+
70+
# By default purchase journals ar not ARCA POS journal
71+
purchase_not_pos_journal = self.env["account.journal"].search(
72+
[
73+
("type", "=", "purchase"),
74+
("company_id", "=", self.env.company.id),
75+
("l10n_latam_use_documents", "=", True),
76+
]
77+
)
78+
self.assertFalse(purchase_not_pos_journal.l10n_ar_is_pos)
79+
80+
doc_60_lp_a = self.env.ref("l10n_ar.dc_a_cvl")
81+
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
82+
83+
with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form:
84+
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
85+
bill_form.partner_id = self.res_partner_adhoc
86+
bill_form.invoice_payment_term_id = payment_term_id
87+
bill_form.invoice_date = "2023-02-09"
88+
bill_form.l10n_latam_document_type_id = doc_60_lp_a
89+
with bill_form.invoice_line_ids.new() as line_form:
90+
line_form.product_id = self.env.ref("product.product_product_4")
91+
line_form.quantity = 1
92+
line_form.price_unit = 100
93+
bill = bill_form.save()
94+
95+
self.assertEqual(bill.journal_id, purchase_not_pos_journal)
96+
97+
# Should fail when posting without document number
98+
with self.assertRaisesRegex(ValidationError, "Please set the document number"):
99+
bill.action_post()
100+
101+
# Create a new journal that is an ARCA POS
102+
purchase_pos_journal = self._create_journal("preprinted", data={"type": "purchase", "l10n_ar_is_pos": True})
103+
104+
with Form(self.env["account.move"].with_context(default_move_type="in_invoice")) as bill_form:
105+
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
106+
bill_form.partner_id = self.res_partner_adhoc
107+
bill_form.invoice_payment_term_id = payment_term_id
108+
bill_form.invoice_date = "2023-02-09"
109+
bill_form.journal_id = purchase_pos_journal
110+
bill_form.l10n_latam_document_type_id = doc_60_lp_a
111+
bill_form.l10n_latam_document_number = "00077-00000077"
112+
with bill_form.invoice_line_ids.new() as line_form:
113+
line_form.product_id = self.env.ref("product.product_product_4")
114+
line_form.quantity = 1
115+
line_form.price_unit = 100
116+
bill = bill_form.save()
117+
bill.action_post()
118+
119+
# If we create an invoice it will not use manual numbering
120+
self.assertFalse(bill.l10n_latam_manual_document_number)
121+
122+
def propagate(method1, method2):
123+
if method1:
124+
for attr in ("_returns",):
125+
if hasattr(method1, attr) and not hasattr(method2, attr):
126+
setattr(method2, attr, getattr(method1, attr))
127+
return method2
128+
129+
def _patch_method(cls, name, method):
130+
origin = getattr(cls, name)
131+
method.origin = origin
132+
wrapped = propagate(origin, method)
133+
wrapped.origin = origin
134+
setattr(cls, name, wrapped)
135+
136+
_patch_method(
137+
TestArManual,
138+
"test_15_liquido_producto_sales",
139+
test_15_liquido_producto_sales_patch,
140+
)
141+
_patch_method(
142+
TestArManual,
143+
"test_16_liquido_producto_purchase",
144+
test_16_liquido_producto_purchase_patch,
145+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record id="view_move_form" model="ir.ui.view">
5+
<field name="name">account.move.form</field>
6+
<field name="model">account.move</field>
7+
<field name="inherit_id" ref="l10n_latam_invoice_document.view_move_form"/>
8+
<field name="arch" type="xml">
9+
<!-- Solo hacemos requeridos estos campo cuando validamos la factura, no antes-->
10+
<field name="l10n_latam_document_number" position="attributes">
11+
<attribute name="required"/>
12+
</field>
13+
<field name="l10n_latam_document_type_id" position="attributes">
14+
<attribute name="required"/>
15+
</field>
16+
</field>
17+
</record>
18+
19+
</odoo>

0 commit comments

Comments
 (0)