Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] l10n_it_fatturapa_out: errore più verboso nel caso di presenza di caratteri non validi #4390

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Contributors
* Lorenzo Battistini <https://github.com/eLBati>
* Roberto Onnis
* Alessio Gerace
* Alex Comba
* Alex Comba <[email protected]>
* Sergio Zanchetta <https://github.com/primes2h>
* Marco Colombo <https://github.com/TheMule71>
* Giovanni Serra <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Lorenzo Battistini <https://github.com/eLBati>
* Roberto Onnis
* Alessio Gerace
* Alex Comba
* Alex Comba <[email protected]>
* Sergio Zanchetta <https://github.com/primes2h>
* Marco Colombo <https://github.com/TheMule71>
* Giovanni Serra <[email protected]>
Expand Down
17 changes: 7 additions & 10 deletions l10n_it_fatturapa_out/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>ITA - Fattura elettronica - Emissione</title>
<style type="text/css">

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -451,7 +450,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Lorenzo Battistini &lt;<a class="reference external" href="https://github.com/eLBati">https://github.com/eLBati</a>&gt;</li>
<li>Roberto Onnis</li>
<li>Alessio Gerace</li>
<li>Alex Comba</li>
<li>Alex Comba &lt;<a class="reference external" href="mailto:alex.comba&#64;agilebg.com">alex.comba&#64;agilebg.com</a>&gt;</li>
<li>Sergio Zanchetta &lt;<a class="reference external" href="https://github.com/primes2h">https://github.com/primes2h</a>&gt;</li>
<li>Marco Colombo &lt;<a class="reference external" href="https://github.com/TheMule71">https://github.com/TheMule71</a>&gt;</li>
<li>Giovanni Serra &lt;<a class="reference external" href="mailto:giovanni&#64;gslab.it">giovanni&#64;gslab.it</a>&gt;</li>
Expand All @@ -468,9 +467,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
36 changes: 35 additions & 1 deletion l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright 2014 Davide Corio
# Copyright 2015-2016 Lorenzo Battistini - Agile Business Group
# Copyright 2018-2019 Alex Comba - Agile Business Group
# Copyright 2018-2024 Alex Comba - Agile Business Group
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
import re
from unittest.mock import Mock

from lxml import etree
from psycopg2 import IntegrityError

import odoo
Expand Down Expand Up @@ -938,6 +939,39 @@ def test_partner_no_address_fail(self):
# Remove from the stack to not interfere with other tests
odoo.http._request_stack.pop()

def test_invalid_char_fail(self):
"""
- create an invoice with a product line with invalid char
as the https://en.wikipedia.org/wiki/List_of_Unicode_characters#Control_codes

expect to fail with a proper message
"""
invoice = self._create_invoice()
# Set invoice line label to https://www.ascii-code.com/character/%E2%90%82
CHAR_CODE = 2
invoice.invoice_line_ids.name = chr(CHAR_CODE)
try:
invoice._post()
except etree.XMLSyntaxError as e:
entry = e.error_log.last_error
if entry.type_name == "ERR_INVALID_CHAR":
# just passing in order to not break the test execution
# due to the exception raised by account_edi_xml_cii_facturx.py/_export_invoice
# (https://github.com/odoo/odoo/blob/14.0/addons/account_edi_ubl_cii/
# models/account_edi_xml_cii_facturx.py#L242)
pass
wizard = self.wizard_model.create({})
with self.assertRaises(UserError) as ue:
wizard.with_context({"active_ids": [invoice.id]}).exportFatturaPA()
error_msg = ue.exception.args[0]
error_fragments = (
f"Error processing invoice(s) {invoice.name}",
f"PCDATA invalid Char value {CHAR_CODE}",
"Line affected",
)
for fragment in error_fragments:
self.assertIn(fragment, error_msg)

def test_multicompany_fail(self):
"""
- create two invoices in two different companies
Expand Down
29 changes: 25 additions & 4 deletions l10n_it_fatturapa_out/wizard/efattura.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2020 Giuseppe Borruso
# Copyright 2020 Marco Colombo
# Copyright 2024 Alex Comba - Agile Business Group
import logging
import os
from datetime import datetime
Expand Down Expand Up @@ -254,10 +255,30 @@ def to_xml(self, env):
content = env.ref(
"l10n_it_fatturapa_out.account_invoice_it_FatturaPA_export"
)._render(template_values)
# 14.0 - occorre rimuovere gli spazi tra i tag
root = etree.fromstring(content, parser=etree.XMLParser(remove_blank_text=True))
# già che ci siamo, validiamo con l'XMLSchema dello SdI
errors = list(fpa_schema.iter_errors(root))
try:
# 14.0 - occorre rimuovere gli spazi tra i tag
root = etree.fromstring(
content, parser=etree.XMLParser(remove_blank_text=True)
)
# già che ci siamo, validiamo con l'XMLSchema dello SdI
errors = list(fpa_schema.iter_errors(root))
except etree.XMLSyntaxError as e:
entry = e.error_log.last_error
error_msg = _(
"Error processing invoice(s) %(invoices)s.\n\n"
"Error message: %(error)s\n\n",
invoices=", ".join(
inv.display_name for inv in template_values["invoices"]
),
error=entry.message,
)
# when there is a char that belongs to
# https://en.wikipedia.org/wiki/List_of_Unicode_characters#Control_codes
if entry.type_name == "ERR_INVALID_CHAR":
lines = [line for line in content.decode().split("\n")]
line = lines[entry.line - 1]
error_msg += _("Line affected: %(line)s\n", line=line)
raise UserError(error_msg)
if errors:
# XXX - da migliorare?
# i controlli precedenti dovrebbero escludere errori di sintassi XML
Expand Down
Loading