[FIX] l10n_br_pix: include dummy reference when none is set
Many banks (Itaú, Santander, Caixa) don't support Pix codes without a reference. To fix set a dummy reference of "***" when none is set (this is what Santander bank does when generating Pix codes without a reference). Again thanks to INGO for testing. opw-3818534 closes odoo/odoo#158713 Signed-off-by: Josse Colpaert <jco@odoo.com>
This commit is contained in:
@@ -72,17 +72,20 @@ class ResPartnerBank(models.Model):
|
||||
"""Override."""
|
||||
if self.country_code == "BR":
|
||||
# Only include characters allowed by the Pix spec.
|
||||
return self._serialize(5, re.sub(r"[^a-zA-Z0-9]", "", comment))
|
||||
return self._serialize(5, re.sub(r"[^a-zA-Z0-9*]", "", comment))
|
||||
return super()._get_additional_data_field(comment)
|
||||
|
||||
def _get_qr_code_vals_list(self, *args, **kwargs):
|
||||
"""Override. Force the amount field to always have two decimals. Uppercase the merchant name and merchant city.
|
||||
Although not specified explicitly in the spec, not uppercasing causes errors when scanning the code."""
|
||||
Although not specified explicitly in the spec, not uppercasing causes errors when scanning the code. Also ensure
|
||||
there is always some comment set."""
|
||||
res = super()._get_qr_code_vals_list(*args, **kwargs)
|
||||
if self.country_code == "BR":
|
||||
res[5] = (res[5][0], float_repr(res[5][1], 2)) # amount
|
||||
res[7] = (res[7][0], res[7][1].upper()) # merchant_name
|
||||
res[8] = (res[8][0], res[8][1].upper()) # merchant_city
|
||||
if not res[9][1]:
|
||||
res[9] = (res[9][0], self._get_additional_data_field("***")) # default comment if none is set
|
||||
return res
|
||||
|
||||
def _get_merchant_account_info(self):
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestL10nBrPix(AccountTestInvoicingCommon):
|
||||
with self.assertRaises(ValidationError, msg="The random key"):
|
||||
self.partner_bank.proxy_value = "not a random key"
|
||||
|
||||
def test_get_qr_vals(self):
|
||||
def _get_qr_code_string(self):
|
||||
self.invoice.qr_code_method = "emv_qr"
|
||||
demo_payment_reference = "NFe TÉST 0001" # É and spaces should be removed
|
||||
|
||||
@@ -61,8 +61,17 @@ class TestL10nBrPix(AccountTestInvoicingCommon):
|
||||
structured_communication=None,
|
||||
)
|
||||
|
||||
qr_code_string = "".join(emv_qr_vals)
|
||||
return "".join(emv_qr_vals)
|
||||
|
||||
def test_get_qr_vals(self):
|
||||
self.assertEqual(
|
||||
qr_code_string,
|
||||
self._get_qr_code_string(),
|
||||
"00020101021226580014br.gov.bcb.pix013671d6c6e1-64ea-4a11-9560-a10870c40ca2520400005303986540512.305802BR5914COMPANY_1_DATA62150511NFeTEST000163044CCF",
|
||||
)
|
||||
|
||||
def test_get_qr_vals_without_reference(self):
|
||||
self.partner_bank.include_reference = False
|
||||
self.assertEqual(
|
||||
self._get_qr_code_string(),
|
||||
"00020101021226580014br.gov.bcb.pix013671d6c6e1-64ea-4a11-9560-a10870c40ca2520400005303986540512.305802BR5914COMPANY_1_DATA62070503***6304B27F",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user