Skip to content

Commit 919ac3f

Browse files
committed
Merge PR #4266 into 14.0
Signed-off-by francesco-ooops
2 parents 846bc2c + 57596aa commit 919ac3f

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

l10n_it_account/tools/account_tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515

1616
def encode_for_export(string_to_encode, max_chars, encoding="latin"):
17+
if not string_to_encode:
18+
return ""
1719
return (
1820
reg_whitespace.sub(" ", string_to_encode)
1921
.encode(encoding, errors="replace")

l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import base64
88
import re
9+
from unittest.mock import Mock
910

1011
from psycopg2 import IntegrityError
1112

13+
import odoo
1214
from odoo import fields
1315
from odoo.exceptions import UserError
1416
from odoo.tests import Form, tagged
@@ -886,6 +888,56 @@ def test_no_tax_fail(self):
886888
)
887889
self.assertEqual(ue.exception.args[0], error_message)
888890

891+
def test_partner_no_address_fail(self):
892+
"""
893+
- create an XML invoice where the customer has no address or city
894+
895+
expect to fail with a proper message
896+
"""
897+
invoice = self._create_invoice()
898+
invoice.partner_id.street = False
899+
invoice.partner_id.city = False
900+
invoice._post()
901+
wizard = self.wizard_model.create({})
902+
with self.assertRaises(UserError) as ue:
903+
wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA()
904+
error_msg = ue.exception.args[0]
905+
error_fragments = (
906+
f"Error processing invoice(s) {invoice.name}",
907+
"Indirizzo",
908+
"Comune",
909+
"Activate debug mode to see the full error",
910+
)
911+
for fragment in error_fragments:
912+
self.assertIn(fragment, error_msg)
913+
914+
try:
915+
# Enter debug mode and add details
916+
odoo.http._request_stack.push(
917+
Mock(
918+
db=self.env.cr.dbname,
919+
env=self.env,
920+
debug=True,
921+
website=False, # compatibility with website module
922+
is_frontend=False,
923+
)
924+
)
925+
wizard = self.wizard_model.create({})
926+
with self.assertRaises(UserError) as ue:
927+
wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA()
928+
debug_error_msg = ue.exception.args[0]
929+
debug_error_fragments = (
930+
"Full error follows",
931+
"Reason: value doesn't match any pattern of",
932+
"p{IsBasicLatin}",
933+
"<Comune xmlns:ns1",
934+
)
935+
for fragment in error_fragments[:-1] + debug_error_fragments:
936+
self.assertIn(fragment, debug_error_msg)
937+
finally:
938+
# Remove from the stack to not interfere with other tests
939+
odoo.http._request_stack.pop()
940+
889941
def test_multicompany_fail(self):
890942
"""
891943
- create two invoices in two different companies

l10n_it_fatturapa_out/wizard/efattura.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,26 @@ def to_xml(self, env):
263263
# i controlli precedenti dovrebbero escludere errori di sintassi XML
264264
# with open("/tmp/fatturaout.xml", "wb") as o:
265265
# o.write(etree.tostring(root, xml_declaration=True, encoding="utf-8"))
266-
raise UserError("\n".join(str(e) for e in errors))
266+
# Print error paths, as they can be helpful even for non-technical people
267+
error_path_string = "\n- ".join(
268+
err.path[err.path.index(":") + 1 :] for err in errors
269+
)
270+
error_msg = _(
271+
"Error processing invoice(s) %(invoices)s.\n\n"
272+
"Errors in the following fields:\n- %(error_path_string)s\n\n",
273+
invoices=", ".join(
274+
inv.display_name for inv in template_values["invoices"]
275+
),
276+
error_path_string=error_path_string,
277+
)
278+
# add details in debug mode
279+
if env.user.user_has_groups("base.group_no_one"):
280+
error_msg += _("Full error follows:\n\n") + "\n".join(
281+
str(e) for e in errors
282+
)
283+
else:
284+
error_msg += _("Activate debug mode to see the full error.")
285+
raise UserError(error_msg)
267286
content = etree.tostring(root, xml_declaration=True, encoding="utf-8")
268287
return content
269288

0 commit comments

Comments
 (0)