[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:
@@ -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
|
||||
|
||||
@@ -46,6 +46,15 @@ class TestL10nHKEmvQrCode(AccountTestInvoicingCommon):
|
||||
'invoice_line_ids': [Command.create({'quantity': 1, 'price_unit': 100})],
|
||||
})
|
||||
|
||||
cls.emv_qr_invoice_with_non_integer_amount = cls.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': cls.partner_a.id,
|
||||
'currency_id': cls.env.ref('base.HKD').id,
|
||||
'partner_bank_id': cls.acc_emv_hk.id,
|
||||
'company_id': cls.company_data['company'].id,
|
||||
'invoice_line_ids': [Command.create({'quantity': 1, 'price_unit': 100.5})],
|
||||
})
|
||||
|
||||
def test_emv_qr_code_generation(self):
|
||||
self.emv_qr_invoice.qr_code_method = 'emv_qr'
|
||||
self.emv_qr_invoice._generate_qr_code()
|
||||
@@ -81,4 +90,19 @@ class TestL10nHKEmvQrCode(AccountTestInvoicingCommon):
|
||||
|
||||
# Check the whole qr code string
|
||||
qr_code_string = ''.join(emv_qr_vals)
|
||||
self.assertEqual(qr_code_string, '00020101021226330012hk.com.hkicl0313+852-678912345204000053033445405100.05802HK5914company_1_data6002HK62170513INV/TEST/00016304264C')
|
||||
self.assertEqual(qr_code_string, '00020101021226330012hk.com.hkicl0313+852-6789123452040000530334454031005802HK5914company_1_data6002HK62170513INV/TEST/00016304A154')
|
||||
|
||||
def test_emv_qr_vals_with_non_integer_amount(self):
|
||||
self.emv_qr_invoice_with_non_integer_amount.qr_code_method = 'emv_qr'
|
||||
unstruct_ref = 'INV/TEST/0002'
|
||||
emv_qr_vals = self.emv_qr_invoice_with_non_integer_amount.partner_bank_id._get_qr_vals(
|
||||
qr_method=self.emv_qr_invoice_with_non_integer_amount.qr_code_method,
|
||||
amount=self.emv_qr_invoice_with_non_integer_amount.amount_residual,
|
||||
currency=self.emv_qr_invoice_with_non_integer_amount.currency_id,
|
||||
debtor_partner=self.emv_qr_invoice_with_non_integer_amount.partner_id,
|
||||
free_communication=unstruct_ref,
|
||||
structured_communication=self.emv_qr_invoice_with_non_integer_amount.payment_reference,
|
||||
)
|
||||
|
||||
# Check the whole qr code string
|
||||
self.assertEqual(emv_qr_vals, '00020101021226330012hk.com.hkicl0313+852-678912345204000053033445405100.55802HK5914company_1_data6002HK62170513INV/TEST/000263049E64')
|
||||
|
||||
@@ -75,4 +75,4 @@ class TestL10nSGEmvQrCode(AccountTestInvoicingCommon):
|
||||
)
|
||||
|
||||
# Check the whole qr code string
|
||||
self.assertEqual(emv_qr_vals, '00020101021226400009SG.PAYNOW010120213200002150HWCF030105204000053037025405100.05802SG5914company_1_data6009Singapore62170113INV/TEST/00016304FBD5')
|
||||
self.assertEqual(emv_qr_vals, '00020101021226400009SG.PAYNOW010120213200002150HWCF0301052040000530370254031005802SG5914company_1_data6009Singapore62170113INV/TEST/0001630416C8')
|
||||
|
||||
@@ -81,4 +81,25 @@ class TestL10nVNEmvQrCode(AccountTestInvoicingCommon):
|
||||
)
|
||||
|
||||
# Check the whole qr code string
|
||||
self.assertEqual(emv_qr_vals, '00020101021238590010A0000007270129000697042201156607040600001290208QRIBFTTA5204000053037045405100.05802VN5914company_1_data6007Vietnam62170113INV/TEST/0001630425A9')
|
||||
self.assertEqual(emv_qr_vals, '00020101021238590010A0000007270129000697042201156607040600001290208QRIBFTTA52040000530370454031005802VN5914company_1_data6007Vietnam62170113INV/TEST/00016304E801')
|
||||
|
||||
def test_remove_vietnamese_accents(self):
|
||||
accent_string = "áàảãạăắằẳẵặâấầẩẫậÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬéèẻẽẹêếềểễệÉÈẺẼẸÊẾỀỂỄỆóòỏõọôốồổỗộơớờởỡợÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢíìỉĩịÍÌỈĨỊúùủũụưứừửữựÚÙỦŨỤƯỨỪỬỮỰýỳỷỹỵÝỲỶỸỴđĐ"
|
||||
result = self.env['res.partner.bank']._remove_accents(accent_string)
|
||||
self.assertEqual(result, "aaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAeeeeeeeeeeeEEEEEEEEEEEoooooooooooooooooOOOOOOOOOOOOOOOOOiiiiiIIIIIuuuuuuuuuuuUUUUUUUUUUUyyyyyYYYYYdD")
|
||||
|
||||
def test_emv_qr_vals_with_accent_partner(self):
|
||||
self.company_data['company'].partner_id.name = 'áÁéÉóÓíÍúÚýÝđĐ'
|
||||
self.emv_qr_invoice.qr_code_method = 'emv_qr'
|
||||
unstruct_ref = 'INV/TEST/0002'
|
||||
emv_qr_vals = self.emv_qr_invoice.partner_bank_id._get_qr_vals(
|
||||
qr_method=self.emv_qr_invoice.qr_code_method,
|
||||
amount=self.emv_qr_invoice.amount_residual,
|
||||
currency=self.emv_qr_invoice.currency_id,
|
||||
debtor_partner=self.emv_qr_invoice.partner_id,
|
||||
free_communication=unstruct_ref,
|
||||
structured_communication=self.emv_qr_invoice.payment_reference,
|
||||
)
|
||||
|
||||
# Check the whole qr code string
|
||||
self.assertEqual(emv_qr_vals, '00020101021238590010A0000007270129000697042201156607040600001290208QRIBFTTA52040000530370454031005802VN5914aAeEoOiIuUyYdD6007Vietnam62170113INV/TEST/0002630492AF')
|
||||
|
||||
Reference in New Issue
Block a user