[FIX] l10n_sa_edi: Fix CSR generation

A few months ago, the onboarding process for the journals according to ZATCA's Saudi eInvoicing
standards required arabic strings to be encoded in a specific format. The format in question
was not mentioned by ZATCA on any official document, however by reverse engineering some of
the sample CSRs shared by ZATCA through their SDK, we were able to figure out that the strings
were encoded using CP1252. Back then doing that allowed us to generate a CSR successfully.
A few days ago, just after the Saudi Localization was merged with master, we received a
complaint where trying to onboard a journal for a company for which the information was
encoded in arabic sometimes raised an exception. Upon investigating we found out that
the CP1252 encoder was the culprit. We tried removing it and now everything is working
fine, including the onboarding.

closes odoo/odoo#128312

X-original-commit: 31a3c25739bb6c0806da887a1f65e670c1b2f7ad
Signed-off-by: Josse Colpaert <jco@odoo.com>
This commit is contained in:
Mehdi Bendali Hacine
2023-07-17 09:20:48 +02:00
parent 15cf748478
commit a275503087
+6 -14
View File
@@ -114,13 +114,6 @@ class AccountJournal(models.Model):
"""
self.ensure_one()
def _encode(s):
"""
Some of the information included in the CSR could be in arabic, and thus needs to be encoded in a
specific format in order to be compliant with the ZATCA CCSID/PCSID APIs
"""
return s.encode().decode('CP1252')
company_id = self.company_id
version_info = service.common.exp_version()
builder = x509.CertificateSigningRequestBuilder()
@@ -130,15 +123,15 @@ class AccountJournal(models.Model):
# Organization Unit Name
(NameOID.ORGANIZATIONAL_UNIT_NAME, (company_id.vat or '')[:10]),
# Organization Name
(NameOID.ORGANIZATION_NAME, _encode(company_id.name)),
(NameOID.ORGANIZATION_NAME, company_id.name),
# Subject Common Name
(NameOID.COMMON_NAME, _encode(company_id.name)),
(NameOID.COMMON_NAME, company_id.name),
# Organization Identifier
(ObjectIdentifier('2.5.4.97'), company_id.vat),
# State/Province Name
(NameOID.STATE_OR_PROVINCE_NAME, _encode(company_id.state_id.name)),
(NameOID.STATE_OR_PROVINCE_NAME, company_id.state_id.name),
# Locality Name
(NameOID.LOCALITY_NAME, _encode(company_id.city)),
(NameOID.LOCALITY_NAME, company_id.city),
)
# The CertificateSigningRequestBuilder instances are immutable, which is why everytime we modify one,
# we have to assign it back to itself to keep track of the changes
@@ -157,10 +150,9 @@ class AccountJournal(models.Model):
# Invoice Type. 4-digit numerical input using 0 & 1
x509.NameAttribute(NameOID.TITLE, company_id._l10n_sa_get_csr_invoice_type()),
# Location
x509.NameAttribute(ObjectIdentifier('2.5.4.26'), _encode(company_id.street)),
x509.NameAttribute(ObjectIdentifier('2.5.4.26'), company_id.street),
# Industry
x509.NameAttribute(ObjectIdentifier('2.5.4.15'),
_encode(company_id.partner_id.industry_id.name or 'Other')),
x509.NameAttribute(ObjectIdentifier('2.5.4.15'), company_id.partner_id.industry_id.name or 'Other'),
]))
])