From d5dc5e135b8f8f9d3fe249d3968b49bf6de7237c Mon Sep 17 00:00:00 2001 From: Marco Colombo Date: Fri, 21 Jan 2022 17:02:38 +0100 Subject: [PATCH] [FIX] l10n_it_fatturapa_out: add check on invoice check for fiscal_document_type_id and parner_id.city --- l10n_it_fatturapa_out/models/account.py | 11 +++++ .../tests/test_fatturapa_xml_validation.py | 46 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/l10n_it_fatturapa_out/models/account.py b/l10n_it_fatturapa_out/models/account.py index 69549a5de343..3d496bbbd656 100644 --- a/l10n_it_fatturapa_out/models/account.py +++ b/l10n_it_fatturapa_out/models/account.py @@ -55,6 +55,14 @@ def preventive_checks(self): % invoice.name ) + if not invoice.fiscal_document_type_id: + raise UserError( + _( + "Invoice %s fiscal document type must be set", + invoice.name, + ) + ) + if ( invoice.invoice_payment_term_id and invoice.invoice_payment_term_id.fatturapa_pt_id.code is False @@ -81,6 +89,9 @@ def preventive_checks(self): ) ) + if not invoice.partner_id.city: + raise UserError(_("Invoice %s partner city must be set", invoice.name)) + if not all( aml.tax_ids for aml in invoice.invoice_line_ids if aml.product_id ): diff --git a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py index 4830ba6470b8..9fd276f1229c 100644 --- a/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py +++ b/l10n_it_fatturapa_out/tests/test_fatturapa_xml_validation.py @@ -924,3 +924,49 @@ def test_max_invoice_in_xml(self): res = self.run_wizard(invoices.ids) attachments = self.attach_model.browse(res["res_id"]) self.assertEqual(len(attachments), 1) + + def test_preventive_checks(self): + invoice_form = Form( + self.env["account.move"].with_context({"default_move_type": "in_invoice"}) + ) + invoice = invoice_form.save() + with self.assertRaises(UserError) as ue: + self.run_wizard(invoice.id) + self.assertIn(invoice.name, ue.exception.args[0]) + + invoice_form = Form( + self.env["account.move"].with_context({"default_move_type": "out_invoice"}) + ) + invoice = invoice_form.save() + invoice.fiscal_document_type_id = False + with self.assertRaises(UserError) as ue: + self.run_wizard(invoice.id) + self.assertIn(invoice.name, ue.exception.args[0]) + + invoice_form = Form( + self.env["account.move"].with_context({"default_move_type": "out_invoice"}) + ) + invoice = invoice_form.save() + invoice.invoice_payment_term_id.fatturapa_pt_id.code = False + with self.assertRaises(UserError) as ue: + self.run_wizard(invoice.id) + self.assertIn(invoice.name, ue.exception.args[0]) + + invoice_form = Form( + self.env["account.move"].with_context({"default_move_type": "out_invoice"}) + ) + invoice = invoice_form.save() + invoice.invoice_payment_term_id.fatturapa_pm_id.code = False + with self.assertRaises(UserError) as ue: + self.run_wizard(invoice.id) + self.assertIn(invoice.name, ue.exception.args[0]) + + invoice_form = Form( + self.env["account.move"].with_context({"default_move_type": "out_invoice"}) + ) + invoice_form.partner_id = self.res_partner_fatturapa_0 + self.res_partner_fatturapa_0.city = False + invoice = invoice_form.save() + with self.assertRaises(UserError) as ue: + self.run_wizard(invoice.id) + self.assertIn(invoice.name, ue.exception.args[0])