diff --git a/addons/l10n_br_pix/models/res_partner_bank.py b/addons/l10n_br_pix/models/res_partner_bank.py index cedcf7314bd..430ac8344f5 100644 --- a/addons/l10n_br_pix/models/res_partner_bank.py +++ b/addons/l10n_br_pix/models/res_partner_bank.py @@ -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): diff --git a/addons/l10n_br_pix/tests/test_l10n_br_pix.py b/addons/l10n_br_pix/tests/test_l10n_br_pix.py index 261a50c883c..0216a4ad9a5 100644 --- a/addons/l10n_br_pix/tests/test_l10n_br_pix.py +++ b/addons/l10n_br_pix/tests/test_l10n_br_pix.py @@ -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", + )