From d27d9e0013b44afe82f3e3121a392110b7db25ef Mon Sep 17 00:00:00 2001 From: Alfredo Zamora Date: Fri, 8 Apr 2022 09:52:30 +0200 Subject: [PATCH] [IMP] l10n_it_fatturapa_in: replace UserError with log_inconsistency and return False from getPartnerBase method --- l10n_it_fatturapa_in/models/attachment.py | 4 ++++ l10n_it_fatturapa_in/tests/fatturapa_common.py | 6 +++++- .../tests/test_import_fatturapa_xml.py | 11 +++++++++++ l10n_it_fatturapa_in/views/account_view.xml | 11 ++++++----- .../wizard/wizard_import_fatturapa.py | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/l10n_it_fatturapa_in/models/attachment.py b/l10n_it_fatturapa_in/models/attachment.py index 2dffd990c174..5465a9dd289b 100644 --- a/l10n_it_fatturapa_in/models/attachment.py +++ b/l10n_it_fatturapa_in/models/attachment.py @@ -55,6 +55,8 @@ class FatturaPAAttachmentIn(models.Model): "Contains self invoices", compute="_compute_xml_data", store=True ) + inconsistencies = fields.Text(compute="_compute_xml_data", store=True) + _sql_constraints = [ ( "ftpa_attachment_in_name_uniq", @@ -123,6 +125,8 @@ def _compute_xml_data(self): if dgd.TipoDocumento in SELF_INVOICE_TYPES: att.is_self_invoice = True att.invoices_date = " ".join(invoices_date) + inconsistencies = wiz_obj.env.context.get("inconsistencies", False) + att.inconsistencies = inconsistencies @api.depends("in_invoice_ids") def _compute_registered(self): diff --git a/l10n_it_fatturapa_in/tests/fatturapa_common.py b/l10n_it_fatturapa_in/tests/fatturapa_common.py index 5a3d5328891a..48d9ff940da7 100644 --- a/l10n_it_fatturapa_in/tests/fatturapa_common.py +++ b/l10n_it_fatturapa_in/tests/fatturapa_common.py @@ -144,7 +144,8 @@ def run_wizard( attach_form = Form(self.attach_model) attach_form.name = name attach_form.datas = self.getFile(file_name, module_name=module_name)[1] - attach_id = attach_form.save().id + attach = attach_form.save() + attach_id = attach.id if mode == "import": wizard_form = Form( self.wizard_model.with_context( @@ -163,6 +164,9 @@ def run_wizard( if wiz_values: wiz_values.wizard_id = wizard return wizard.link() + if not mode: + # return created fatturapa.attachment.in record in case no mode provided + return attach def run_wizard_multi(self, file_name_list, module_name=None): if module_name is None: diff --git a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py index 9764c28ec502..1ed15a735b83 100644 --- a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py +++ b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py @@ -996,6 +996,17 @@ def test_e_invoice_field_compute(self): invoices = self.invoice_model.create([{}, {}]) self.assertEqual(invoices.mapped("e_invoice_validation_error"), [False, False]) + def test_duplicated_vat_on_partners(self): + supplier = self.env["res.partner"].search( + [("vat", "=", "IT05979361218")], limit=1 + ) + + duplicated_supplier = supplier.copy() + self.assertEqual(supplier.vat, duplicated_supplier.vat) + attach = self.run_wizard("duplicated_vat", "IT05979361218_012.xml", mode=False) + self.assertFalse(attach.xml_supplier_id) + self.assertTrue(attach.inconsistencies) + class TestFatturaPAEnasarco(FatturapaCommon): def setUp(self): diff --git a/l10n_it_fatturapa_in/views/account_view.xml b/l10n_it_fatturapa_in/views/account_view.xml index 9f9fab0b7e33..df9c9d8a8f3c 100644 --- a/l10n_it_fatturapa_in/views/account_view.xml +++ b/l10n_it_fatturapa_in/views/account_view.xml @@ -6,16 +6,17 @@ fatturapa.attachment.in
+
diff --git a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py index 84163b63e6d7..382a5c5100dc 100644 --- a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py @@ -214,13 +214,14 @@ def getPartnerBase(self, DatiAnagrafici): # noqa: C901 commercial_partner_id and partner.commercial_partner_id.id != commercial_partner_id ): - raise UserError( + self.log_inconsistency( _( "Two distinct partners with " "VAT number %s or Fiscal Code %s already " "present in db." % (vat, cf) ) ) + return False commercial_partner_id = partner.commercial_partner_id.id if partners: if not commercial_partner_id: