Skip to content

Commit

Permalink
IMP l10n_it_fatturapa_out check on invoice lines. Otherwise user woul…
Browse files Browse the repository at this point in the history
…d get (OCA#558)

'Type {http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2}String1000LatinType cannot be created from {http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2}String1000LatinType: Mouse
Optical'
ADD preventive_checks to be used for generic data tests
  • Loading branch information
eLBati authored and TheMule71 committed Nov 25, 2022
1 parent 0398ea8 commit 1a1780b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
'name': 'Italian Localization - FatturaPA - Emission',
'version': '10.0.1.0.1',
'version': '10.0.1.0.2',
'category': 'Localization/Italy',
'summary': 'Electronic invoices emission',
'author': 'Davide Corio, Agile Business Group, Innoviu,'
Expand Down
6 changes: 6 additions & 0 deletions l10n_it_fatturapa_out/i18n/l10n_it_fatturapa_out.pot
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ msgstr ""
msgid "Invoice line %s does not have tax"
msgstr ""

#. module: l10n_it_fatturapa_out
#: code:addons/l10n_it_fatturapa_out/models/account.py:22
#, python-format
msgid "Invoice line [%s] must not contain new line character"
msgstr ""

#. module: l10n_it_fatturapa_out
#: model:ir.ui.view,arch_db:l10n_it_fatturapa_out.view_fatturapa_out_attachment_form
msgid "Invoices"
Expand Down
9 changes: 9 additions & 0 deletions l10n_it_fatturapa_out/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


from odoo import fields, models
from odoo.exceptions import UserError
from odoo.tools.translate import _


class AccountInvoice(models.Model):
Expand All @@ -13,3 +15,10 @@ class AccountInvoice(models.Model):
fatturapa_attachment_out_id = fields.Many2one(
'fatturapa.attachment.out', 'FatturaPA Export File',
readonly=True)

def preventive_checks(self):
for line in self.invoice_line_ids:
if '\n' in line.name:
raise UserError(_(
"Invoice line [%s] must not contain new line character"
) % line.name)
8 changes: 7 additions & 1 deletion l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tempfile
from odoo.addons.account.tests.account_test_users import AccountTestUsers
from odoo.modules.module import get_module_resource
from odoo.exceptions import UserError
from lxml import etree
import shutil
import os
Expand Down Expand Up @@ -142,7 +143,7 @@ def test_1_xml_export(self):
(0, 0, {
'account_id': self.a_sale.id,
'product_id': self.product_product_10.id,
'name': 'Mouse, Optical',
'name': 'Mouse\nOptical',
'quantity': 1,
'uom_id': self.product_uom_unit.id,
'price_unit': 10,
Expand All @@ -161,6 +162,11 @@ def test_1_xml_export(self):
})],
})
invoice.action_invoice_open()
with self.assertRaises(UserError):
self.run_wizard(invoice.id)
for line in invoice.invoice_line_ids:
if line.name == 'Mouse\nOptical':
line.name = 'Mouse, Optical'
res = self.run_wizard(invoice.id)

self.assertTrue(res)
Expand Down
1 change: 1 addition & 0 deletions l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ def exportFatturaPA(self):
_("Invoice %s has FatturaPA Export File yet") % (
inv.number))
invoice_body = FatturaElettronicaBodyType()
inv.preventive_checks()
self.with_context(context_partner).setFatturaElettronicaBody(
inv, invoice_body)
fatturapa.FatturaElettronicaBody.append(invoice_body)
Expand Down

0 comments on commit 1a1780b

Please sign in to comment.