forked from ingadhoc/uruguay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_l10n_uy_ux.py
More file actions
220 lines (201 loc) · 9.83 KB
/
test_l10n_uy_ux.py
File metadata and controls
220 lines (201 loc) · 9.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
from odoo import Command
from odoo.addons.l10n_uy_edi.tests.common import TestUyEdi
from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests.common import tagged
@tagged("-at_install", "post_install", "post_install_l10n", "l10n_uy_ux")
class TestUx(TestUyEdi):
@classmethod
def setUpClass(self):
super().setUpClass()
self.company_uy.l10n_uy_edi_ucfe_env = "demo"
def test_invalid_report_params(self):
with self.assertRaisesRegex(UserError, "El parámetro 'reporte' contiene dos valores diferentes."):
record = self.env["res.config.settings"].create(
{"l10n_uy_report_params": "[['reporte', 'reporte'], ['secundario', 'ingles']]"}
)
record.uy_ux_onchange_l10n_uy_report_params()
def _check_computed_params(self, value, expected_result):
self.company_uy.l10n_uy_report_params = value
invoice = self._create_move(
invoice_line_ids=[
Command.create(
{
"product_id": self.service_vat_22.id,
"price_unit": 100.0,
}
),
],
)
invoice.action_post()
self._send_and_print(invoice) # to generate the l10n_uy_edi.document
result = invoice.l10n_uy_edi_document_id._get_report_params()
self.assertEqual(result, expected_result, "Error in computed report parameters")
def _check_automatic_params(self, expected_result):
"""Check if the automatic params are correctly set"""
self.company_uy.l10n_uy_report_params = False
invoice = self._create_move(
invoice_line_ids=[
Command.create(
{
"product_id": self.service_vat_22.id,
"price_unit": 100.0,
}
),
],
)
line_length = 140
max_lines = 6
invoice.narration = "A" * (line_length * max_lines + 10)
invoice.action_post()
self._send_and_print(invoice)
result = invoice.l10n_uy_edi_document_id._get_report_params()
self.assertEqual(result, expected_result, "Error in automatic report parameters")
def test_without_report_params(self):
"""If not set any param should use standar PDF"""
self._check_computed_params(False, ("ObtenerPdf", {}))
self._check_computed_params("", ("ObtenerPdf", {}))
self._check_computed_params("[]", ("ObtenerPdf", {}))
def test_with_report_params(self):
"""If param set then should prepare correctly the report params to send"""
self._check_computed_params(
"[['adenda'], ['true']]",
(
"ObtenerPdfConParametros",
{
"nombreParametros": {"string": ["adenda"]},
"valoresParametros": {"string": ["true"]},
},
),
)
self._check_computed_params(
"[['reporte'], ['ingles']]",
(
"ObtenerPdfConParametros",
{
"nombreParametros": {"string": ["reporte"]},
"valoresParametros": {"string": ["ingles"]},
},
),
)
self._check_computed_params(
"[['reporte'], ['secundario']]",
(
"ObtenerPdfConParametros",
{
"nombreParametros": {"string": ["reporte"]},
"valoresParametros": {"string": ["secundario"]},
},
),
)
self._check_computed_params(
"[['adenda', 'reporte'], ['true', 'ingles']]",
(
"ObtenerPdfConParametros",
{
"nombreParametros": {"string": ["adenda", "reporte"]},
"valoresParametros": {"string": ["true", "ingles"]},
},
),
)
def test_with_automatic_report_params(self):
"""If user does not set any param, it should take the automatic params from Odoo method"""
self._check_automatic_params(
(
"ObtenerPdfConParametros",
{
"nombreParametros": {"string": ["adenda"]},
"valoresParametros": {"string": ["true"]},
},
),
)
def test_110_account_move_line_nom_and_desc(self):
"""Test account move with varied products and descriptions"""
long_name = "Product name for testing purposes that intentionally contains more than eighty chars"
products = [
self.env["product.product"].create({"name": "Product Without Description"}),
self.env["product.product"].create({"name": "Product With Description"}),
self.env["product.product"].create({"name": long_name}),
]
addenda = self.env["l10n_uy_edi.addenda"].create(
{
"content": "Addenda Content",
"is_legend": False,
}
)
# Define invoice lines data to create
invoice_line_data = [
{"product_id": products[0], "name": None, "addenda_ids": []}, # Without description
{"product_id": products[1], "name": "Custom Description", "addenda_ids": []}, # With description
{"product_id": products[2], "name": None, "addenda_ids": []}, # +80 chars without description
{"product_id": products[2], "name": "Custom Description", "addenda_ids": []}, # +80 chars with description
{"product_id": products[2], "name": None, "addenda_ids": [addenda]}, # +80 chars with addenda
{
"product_id": products[2],
"name": "Custom Description",
"addenda_ids": [addenda],
}, # +80 chars with desc and addenda
{"product_id": products[0], "name": False, "addenda_ids": []}, # With description deleted by user
{"product_id": products[0], "name": "", "addenda_ids": []}, # With a empty string as description
]
# Create invoice using Form to simulate UI interaction
with Form(self.env["account.move"].with_context(default_move_type="out_invoice")) as invoice_form:
invoice_form.partner_id = self.partner_local
for line_data in invoice_line_data:
with invoice_form.invoice_line_ids.new() as line_form:
line_form.product_id = line_data["product_id"]
# Only override name if explicitly provided (not None)
if line_data["name"] is not None:
line_form.name = line_data["name"]
# Add addenda if provided
if line_data["addenda_ids"]:
line_form.l10n_uy_edi_addenda_ids.clear()
for addenda_rec in line_data["addenda_ids"]:
line_form.l10n_uy_edi_addenda_ids.add(addenda_rec)
invoice = invoice_form.save()
for idx, line in enumerate(invoice.invoice_line_ids):
nom_item, description = invoice._l10n_uy_edi_get_line_nom_and_desc(line)
if idx == 0: # Without description
self.assertEqual(
nom_item, "Product Without Description"[:80], "NomItem mismatch for line without description"
)
self.assertEqual(description, "", "Description mismatch for line without description")
elif idx == 1: # With custom description (aml.name is the custom description)
self.assertEqual(nom_item, "Custom Description"[:80], "NomItem mismatch for line with description")
self.assertEqual(description, "", "Description mismatch for line with description")
elif idx == 2: # +80 chars without description
self.assertEqual(
nom_item, long_name[:80], "NomItem mismatch for line with long name without description"
)
self.assertEqual(
description, long_name[80:], "Description mismatch for line with long name without description"
)
elif idx == 3: # +80 chars with custom description (aml.name is the custom description)
self.assertEqual(
nom_item, "Custom Description"[:80], "NomItem mismatch for line with long name and description"
)
self.assertEqual(
description,
"",
"Description mismatch for line with long name and description",
)
elif idx == 4: # +80 chars with addenda
self.assertEqual(nom_item, long_name[:80], "NomItem mismatch for line with long name and addenda")
self.assertIn(
"Addenda Content", description, "Addenda content missing in description for line with addenda"
)
elif idx == 5: # +80 chars with custom description and addenda (aml.name is the custom description)
self.assertEqual(
nom_item,
"Custom Description"[:80],
"NomItem mismatch for line with long name, description, and addenda",
)
# When custom description is set, description should contain the addenda
self.assertIn(
"Addenda Content",
description,
"Addenda content missing in description for line with desc and addenda",
)
elif idx == 6 or idx == 7: # With description deleted by user or "" (aml.name is False or empty)
self.assertEqual(nom_item, "-", "NomItem mismatch for line with deleted description")
self.assertEqual(description, "", "Description mismatch for line with deleted description")