[FIX] account_qr_code_emv, l10n_*: fix emv_qr_vals format

Steps to reproduce:

- Create any emv_qr_code. Set merchant name with a Vietname accent
- Set amount to a integer number

Current behaviour:

- An EMV QR Code will be generated with accent merchant name, and the amount
include .0 value

Expected behaviour:

- The EMV QR Code change change the accent value to alphabet. And the amount should
not contain .0 if the amount is an integer

closes odoo/odoo#131852

X-original-commit: 158f8090ef30065b97ebe8b15b0bf73fff6a9ac4
Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
Signed-off-by: Tommy Ng (tong) <tong@odoo.com>
This commit is contained in:
tong-odoo
2023-08-14 06:17:00 +02:00
parent 00f174fb26
commit 910756df63
4 changed files with 57 additions and 6 deletions
@@ -3,6 +3,7 @@
import re
from odoo import _, api, fields, models
from odoo.tools.misc import remove_accents
from odoo.addons.account_qr_code_emv.const import CURRENCY_MAPPING
@@ -23,6 +24,10 @@ class ResPartnerBank(models.Model):
else:
return ''
@api.model
def _remove_accents(self, string):
return remove_accents(string).replace('đ', 'd').replace('Đ', 'D')
@api.depends('country_code')
def _compute_display_qr_setting(self):
self.display_qr_setting = False
@@ -48,10 +53,11 @@ class ResPartnerBank(models.Model):
def _get_qr_code_vals_list(self, qr_method, amount, currency, debtor_partner, free_communication, structured_communication):
tag, merchant_account_info = self._get_merchant_account_info()
currency_code = CURRENCY_MAPPING[currency.name]
merchant_name = self.partner_id.name and self.partner_id.name[:25] or 'NA'
merchant_city = self.partner_id.city and self.partner_id.city[:15] or ''
amount = amount.is_integer() and int(amount) or amount
merchant_name = self.partner_id.name and self._remove_accents(self.partner_id.name)[:25] or 'NA'
merchant_city = self.partner_id.city and self._remove_accents(self.partner_id.city)[:15] or ''
comment = structured_communication or free_communication or ''
comment = re.sub(r'/[^ A-Za-z0-9_@.\/#&+-]+/g', '', comment)
comment = re.sub(r'/[^ A-Za-z0-9_@.\/#&+-]+/g', '', remove_accents(comment))
additional_data_field = self._get_additional_data_field(comment) if self.include_reference else None
return [
(0, '01'), # Payload Format Indicator