[FIX] l10n_sa_edi: fix scheme ID for foreign customers

Steps to reproduce:
- Install Contacts, Accounting and l10n_sa_edi
- Switch to a Saudi Arabian company (e.g. SA Company)
- Create a contact who is not in Saudi Arabia:
  * Address: [Complete address in United Arab Emirates]
  * VAT: [any]
- Create an invoice:
  * Customer: [The created contact]
  * Product: [any]
- Confirm the invoice
- Process by ZATCA

Issue:
The following warning is returned:
"The other Buyer ID (BT-46) must present in the tax invoice and associated
debit notes and credit notes (KSA-2, position 1 and 2 = 01), where the buyer
VAT registration number or buyer group VAT registration number (BT-48) is
not provided."

Cause:
"PartyIdentification" element is not set in the electronic invoice for customer
because he doesn't have "l10n_sa_additional_identification_number" field set.
This field is only available for contacts living in Saudi Arabia.
For contacts who don't live in Saudi Arabia, "PartyIdentification" should be
populate with their VAT number.

opw-3845645

closes odoo/odoo#163652

X-original-commit: 3500c5f5dc78ea88bb662bb08cb6c59482f502db
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Anh Thao Pham (pta)
2024-04-27 09:25:41 +00:00
parent 704c0bec40
commit 2a2c76a028
5 changed files with 8 additions and 8 deletions
@@ -104,7 +104,11 @@ class AccountEdiXmlUBL21Zatca(models.AbstractModel):
""" Override to include/update values specific to ZATCA's UBL 2.1 specs """
return [{
'id_attrs': {'schemeID': partner.l10n_sa_additional_identification_scheme},
'id': partner.l10n_sa_additional_identification_number if partner.l10n_sa_additional_identification_scheme != 'TIN' else partner.vat
'id': (
partner.l10n_sa_additional_identification_number
if partner.l10n_sa_additional_identification_scheme != 'TIN' and partner.country_code == 'SA'
else partner.vat
),
}]
def _l10n_sa_get_payment_means_code(self, invoice):
@@ -102,9 +102,6 @@
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID schemeID="CRN">353535353535353</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>Chichi Lboukla</cbc:Name>
</cac:PartyName>
@@ -102,9 +102,6 @@
</cac:AccountingSupplierParty>
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID schemeID="CRN">353535353535353</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>Chichi Lboukla</cbc:Name>
</cac:PartyName>
@@ -97,7 +97,7 @@
<cac:AccountingCustomerParty>
<cac:Party>
<cac:PartyIdentification>
<cbc:ID schemeID="CRN">353535353535353</cbc:ID>
<cbc:ID schemeID="CRN">US12345677</cbc:ID>
</cac:PartyIdentification>
<cac:PartyName>
<cbc:Name>Chichi Lboukla</cbc:Name>
@@ -118,6 +118,7 @@
</cac:PostalAddress>
<cac:PartyLegalEntity>
<cbc:RegistrationName>Chichi Lboukla</cbc:RegistrationName>
<cbc:CompanyID>US12345677</cbc:CompanyID>
<cac:RegistrationAddress>
<cbc:StreetName>4557 De Silva St</cbc:StreetName>
<cbc:BuildingNumber>12300</cbc:BuildingNumber>
@@ -22,6 +22,7 @@ class TestEdiZatca(TestSaEdiCommon):
expected_tree = self.get_xml_tree_from_string(standard_invoice)
expected_tree = self.with_applied_xpath(expected_tree, self.invoice_applied_xpath)
self.partner_us.vat = 'US12345677'
move = self._create_invoice(name='INV/2022/00014', date='2022-09-05', date_due='2022-09-22', partner_id=self.partner_us,
product_id=self.product_a, price=320.0)
move._l10n_sa_generate_unsigned_data()