diff --git a/l10n_it_fatturapa_in/__manifest__.py b/l10n_it_fatturapa_in/__manifest__.py index 5737e9fb49d7..e759e08b02ba 100644 --- a/l10n_it_fatturapa_in/__manifest__.py +++ b/l10n_it_fatturapa_in/__manifest__.py @@ -25,6 +25,7 @@ "views/partner_view.xml", "wizard/wizard_import_fatturapa_view.xml", "wizard/link_to_existing_invoice.xml", + "wizard/wizard_check_intermediary_vat.xml", "views/company_view.xml", "security/ir.model.access.csv", "security/rules.xml", diff --git a/l10n_it_fatturapa_in/security/ir.model.access.csv b/l10n_it_fatturapa_in/security/ir.model.access.csv index c9aeef7c0660..f119c6594452 100644 --- a/l10n_it_fatturapa_in/security/ir.model.access.csv +++ b/l10n_it_fatturapa_in/security/ir.model.access.csv @@ -6,6 +6,7 @@ access_einvoice_line_other_data,access_einvoice_line_other_data,model_einvoice_l access_wizard_import_fatturapa,access_wizard_import_fatturapa,model_wizard_import_fatturapa,account.group_account_invoice,1,1,1,1 access_wizard_link_to_invoice,access_wizard_link_to_invoice,model_wizard_link_to_invoice,account.group_account_invoice,1,1,1,1 access_wizard_link_to_invoice_line,access_wizard_link_to_invoice_line,model_wizard_link_to_invoice_line,account.group_account_invoice,1,1,1,1 +access_wizard_check_intermediary_all,access_wizard_check_intermediary_all,model_wizard_check_intermediary,account.group_account_invoice,1,1,1,1 fatturapa_in_decimal_precision_access_manager,fatturapa_in_decimal_precision_access_manager,base.model_decimal_precision,account.group_account_manager,1,1,0,0 fatturapa_in_decimal_precision_access_billing,fatturapa_in_decimal_precision_access_billing,base.model_decimal_precision,account.group_account_invoice,1,1,0,0 fatturapa_in_mail_followers_access_manager,fatturapa_in_mail_followers_access_manager,mail.model_mail_followers,account.group_account_manager,1,1,0,0 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 b4a97f267ee3..86508650350f 100644 --- a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py +++ b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py @@ -325,8 +325,43 @@ def test_11_xml_import(self): def test_12_xml_import(self): res = self.run_wizard("test12", "IT05979361218_008.xml") - invoice_id = res.get("domain")[0][2][0] - invoice = self.invoice_model.browse(invoice_id) + + # Case where the confirmation wizard is shown + if res.get("res_model") == "wizard.check.intermediary": + # Simulate opening the wizard and retrieving values from the context + context = res.get("context", {}) + intermediary_id = context.get("intermediary_id") + invoice_id = context.get("invoice_id") + + # Check that the wizard was opened with the correct values + self.assertTrue(intermediary_id, "intermediary_id not present in context") + self.assertTrue(invoice_id, "invoice_id not present in context") + + # Simulate the wizard + wizard = ( + self.env["wizard.check.intermediary"] + .with_context(context) + .create( + { + "message": context.get("default_message"), + "intermediary_id": intermediary_id, + "invoice_id": invoice_id, + } + ) + ) + + # Simulate user confirmation + wizard.action_confirm() + + # After confirmation, retrieve the invoice and check the intermediary partner + invoice = self.env["account.move"].browse(invoice_id) + + else: + # Standard flow without wizard + invoice_id = res.get("domain")[0][2][0] + invoice = self.env["account.move"].browse(invoice_id) + + # Final assertions regardless of the path self.assertEqual(invoice.payment_reference, "FT/2015/0012") self.assertEqual(invoice.sender, "TZ") self.assertEqual(invoice.intermediary.name, "MARIO ROSSI") diff --git a/l10n_it_fatturapa_in/wizard/__init__.py b/l10n_it_fatturapa_in/wizard/__init__.py index 9fd3975db539..657c1d0f9693 100644 --- a/l10n_it_fatturapa_in/wizard/__init__.py +++ b/l10n_it_fatturapa_in/wizard/__init__.py @@ -1,2 +1,3 @@ from . import wizard_import_fatturapa +from . import wizard_check_intermediary_vat from . import link_to_existing_invoice diff --git a/l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.py b/l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.py new file mode 100644 index 000000000000..3bea20f24730 --- /dev/null +++ b/l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.py @@ -0,0 +1,21 @@ +from odoo import fields, models + + +class WizardCheckIntermediaryVat(models.TransientModel): + _name = "wizard.check.intermediary" + _description = "Intermediary VAT Check" + + message = fields.Text(string="Message", readonly=True) + intermediary_id = fields.Integer(string="Intermediary", readonly=True) + invoice_id = fields.Many2one("account.move", string="Invoice", readonly=True) + + def action_confirm(self): + if self._context.get("intermediary_id"): + self.env["account.move"].browse(self._context.get("invoice_id")).write( + {"intermediary": self._context.get("intermediary_id")} + ) + + return {"type": "ir.actions.act_window_close"} + + def action_cancel(self): + return {"type": "ir.actions.act_window_close"} diff --git a/l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.xml b/l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.xml new file mode 100644 index 000000000000..0cd343de2d4d --- /dev/null +++ b/l10n_it_fatturapa_in/wizard/wizard_check_intermediary_vat.xml @@ -0,0 +1,30 @@ + + + + check.intermediary.vat.form + wizard.check.intermediary + +
+ + + + + + +
+
+
+
diff --git a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py index 4b4a2539213f..d2f5df1a42d3 100644 --- a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py @@ -1925,7 +1925,33 @@ def importFatturaPA(self): invoice.write({"tax_representative_id": tax_partner_id}) if Intermediary: Intermediary_id = self.getPartnerBase(Intermediary.DatiAnagrafici) - invoice.write({"intermediary": Intermediary_id}) + vat_check = ( + self.env["res.partner"] + .search([("id", "=", Intermediary_id)]) + .vat + ) + if vat_check: + invoice.write({"intermediary": Intermediary_id}) + else: + name = ( + self.env["res.partner"] + .search([("id", "=", Intermediary_id)]) + .name + ) + return { + "type": "ir.actions.act_window", + "name": "Confirm action", + "res_model": "wizard.check.intermediary", + "view_mode": "form", + "target": "new", + "context": { + "default_message": f'The contact intermediary "{name}" ' + "does not exists in the system. Do you want to create it?", + "intermediary_id": Intermediary_id, + "invoice_id": invoice.id, + }, + } + new_invoices.append(invoice.id) self.check_invoice_amount(invoice, fattura)