diff --git a/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py b/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py index 5f72508b57e..60571916ce9 100644 --- a/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py +++ b/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py @@ -32,7 +32,7 @@ TAX_POSSIBLE_VALUES = set(UBL_TO_OIOUBL_TAX_CATEGORY_ID_MAPPING.values()) def format_vat_number(partner): - vat = partner.vat.replace(' ', '') + vat = (partner.vat or '').replace(' ', '') if vat[:2].isnumeric(): vat = partner.country_code.upper() + vat return vat @@ -275,6 +275,7 @@ class AccountEdiXmlOIOUBL201(models.AbstractModel): if partner.country_code == "FR" and not partner.company_registry: constraints["oioubl201_company_registry_required_for_french_partner"] = \ _("The company registry is required for french partner: %s", partner.name) + constraints[f'oioubl201_{partner_type}_vat_required'] = self._check_required_fields(vals[partner_type], 'vat') return constraints diff --git a/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py b/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py index 7c1b8689d87..a83fef9d70a 100644 --- a/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py +++ b/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py @@ -103,7 +103,10 @@ class TestUBLDK(TestUBLCommon, TestAccountMoveSendCommon): ], }) invoice.action_post() - invoice._generate_pdf_and_send_invoice(self.move_template, allow_fallback_pdf=False) + self.env['account.move.send'] \ + .with_context(active_model=invoice._name, active_ids=invoice.ids) \ + .create({}) \ + .action_send_and_print() return invoice ######### @@ -173,6 +176,17 @@ class TestUBLDK(TestUBLCommon, TestAccountMoveSendCommon): with self.assertRaisesRegex(UserError, "The company registry is required for french partner:"): self.create_post_and_send_invoice(partner=self.partner_c) + @freeze_time('2017-01-01') + def test_oioubl_export_partner_without_vat_number(self): + """ This test verifies that we can't export an OIOUBL file for a partner + who doesn't have a tax ID. It verifies that we receive a UserError + telling to the user that this field is missing. + """ + self.partner_b.vat = None + with self.assertRaises(UserError) as exception: + self.create_post_and_send_invoice(partner=self.partner_b) + self.assertIn(f"The field '{self.partner_b._fields['vat'].string}' is required", exception.exception.args[0]) + ######### # IMPORT #########