[FIX] l10n_dk_oioubl: Verify that partner have a vat number

The aim of this commit is verifying that the partner for who
we want to generate an oioubl file has a vat number set.

no task id

closes odoo/odoo#142684

Signed-off-by: Laurent Smet (las) <las@odoo.com>
This commit is contained in:
Florian(flg)
2023-11-29 22:42:37 +00:00
parent c3781985e5
commit c1caf94f89
2 changed files with 17 additions and 2 deletions
@@ -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
@@ -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
#########