From edca41774a0df98a43f4e441f12bd520fa814f60 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 7 Sep 2023 10:43:30 +0200 Subject: [PATCH] [IMP] l10n_it_edi_pa: adapt to account_edi removal changes closes odoo/odoo#122194 Related: odoo/upgrade#4893 Signed-off-by: Josse Colpaert --- .../tests/export_xmls/split_payment.xml | 1 + addons/l10n_it_edi_pa/models/__init__.py | 1 - .../models/account_edi_format.py | 17 ---------------- addons/l10n_it_edi_pa/models/account_move.py | 16 ++++++++++++--- addons/l10n_it_edi_pa/tests/test_edi_pa.py | 20 +------------------ 5 files changed, 15 insertions(+), 40 deletions(-) delete mode 100644 addons/l10n_it_edi_pa/models/account_edi_format.py diff --git a/addons/l10n_it_edi/tests/export_xmls/split_payment.xml b/addons/l10n_it_edi/tests/export_xmls/split_payment.xml index 62dcc234381..60f8f4ea080 100644 --- a/addons/l10n_it_edi/tests/export_xmls/split_payment.xml +++ b/addons/l10n_it_edi/tests/export_xmls/split_payment.xml @@ -6,6 +6,7 @@ IT 01234560157 + ___ignore___ FPA12 123456 diff --git a/addons/l10n_it_edi_pa/models/__init__.py b/addons/l10n_it_edi_pa/models/__init__.py index 8072ca1f74f..6eca875fbf9 100644 --- a/addons/l10n_it_edi_pa/models/__init__.py +++ b/addons/l10n_it_edi_pa/models/__init__.py @@ -1,4 +1,3 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import account_move -from . import account_edi_format diff --git a/addons/l10n_it_edi_pa/models/account_edi_format.py b/addons/l10n_it_edi_pa/models/account_edi_format.py deleted file mode 100644 index 9f5b06ebed2..00000000000 --- a/addons/l10n_it_edi_pa/models/account_edi_format.py +++ /dev/null @@ -1,17 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import _, fields, models - - -class AccountEdiFormat(models.Model): - _inherit = 'account.edi.format' - - def _l10n_it_edi_check_ordinary_invoice_configuration(self, invoice): - errors = super()._l10n_it_edi_check_ordinary_invoice_configuration(invoice) - if invoice._is_commercial_partner_pa(): - if not invoice.l10n_it_origin_document_type: - errors.append(_("This invoice targets the Public Administration, please fill out" - " Origin Document Type field in the Electronic Invoicing tab.")) - if invoice.l10n_it_origin_document_date and invoice.l10n_it_origin_document_date > fields.Date.today(): - errors.append(_("The Origin Document Date cannot be in the future.")) - return errors diff --git a/addons/l10n_it_edi_pa/models/account_move.py b/addons/l10n_it_edi_pa/models/account_move.py index 3c6627e6d40..7d74b72e2e4 100644 --- a/addons/l10n_it_edi_pa/models/account_move.py +++ b/addons/l10n_it_edi_pa/models/account_move.py @@ -1,6 +1,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models +from odoo import api, fields, models, _ class AccountMove(models.Model): @@ -33,9 +33,9 @@ class AccountMove(models.Model): move.l10n_it_partner_pa = (move.country_code == 'IT' and move.commercial_partner_id.l10n_it_pa_index and len(move.commercial_partner_id.l10n_it_pa_index) == 6) - def _prepare_fatturapa_export_values(self): + def _l10n_it_edi_get_values(self, pdf_values=None): """Add origin document features.""" - template_values = super()._prepare_fatturapa_export_values() + template_values = super()._l10n_it_edi_get_values(pdf_values=pdf_values) template_values.update({ 'origin_document_type': self.l10n_it_origin_document_type, 'origin_document_name': self.l10n_it_origin_document_name, @@ -44,3 +44,13 @@ class AccountMove(models.Model): 'cup': self.l10n_it_cup, }) return template_values + + def _l10n_it_edi_base_export_data_check(self): + errors = super()._l10n_it_edi_base_export_data_check() + if self.l10n_it_partner_pa: + if not self.l10n_it_origin_document_type: + errors.append(_("This invoice targets the Public Administration, please fill out" + " Origin Document Type field in the Electronic Invoicing tab.")) + if self.l10n_it_origin_document_date and self.l10n_it_origin_document_date > fields.Date.today(): + errors.append(_("The Origin Document Date cannot be in the future.")) + return errors diff --git a/addons/l10n_it_edi_pa/tests/test_edi_pa.py b/addons/l10n_it_edi_pa/tests/test_edi_pa.py index 86b1c71c824..eb372c30d1b 100644 --- a/addons/l10n_it_edi_pa/tests/test_edi_pa.py +++ b/addons/l10n_it_edi_pa/tests/test_edi_pa.py @@ -43,30 +43,12 @@ class TestItEdiPa(TestItEdi): 'l10n_it_origin_document_type': False, }) cls.pa_partner_invoice._post() - cls.split_payment_invoice_content = cls._get_test_file_content('split_payment.xml') - - @classmethod - def _get_test_file_content(cls, filename): - """ Get the content of a test file inside this module """ - path = 'l10n_it_edi/tests/export_xmls/' + filename - with tools.file_open(path, mode='rb') as test_file: - return test_file.read() def test_send_pa_partner(self): - res = self.edi_format._l10n_it_post_invoices_step_1(self.pa_partner_invoice) - self.assertEqual(res[self.pa_partner_invoice], {'attachment': self.pa_partner_invoice.l10n_it_edi_attachment_id, 'success': True}) - - def test_send_pa_partner_missing_field(self): - with self.assertRaises(UserError): - self.pa_partner_invoice_2._post() - - def test_split_payment(self): """ ImportoTotaleDocumento must include VAT ImportoPagamento must be without VAT EsigibilitaIva of the Split payment tax must be 'S' The orgin_document fields must appear in the XML. Use reference validator: https://fex-app.com/servizi/inizia """ - invoice_etree = self._cleanup_etree(self.edi_format._l10n_it_edi_export_invoice_as_xml(self.pa_partner_invoice)) - expected_etree = etree.fromstring(self.split_payment_invoice_content) - self.assertXmlTreeEqual(invoice_etree, expected_etree) + self._assert_export_invoice(self.pa_partner_invoice, 'split_payment.xml')