From b104a50d6d7fbc07fde8de81a4e1935e540214e5 Mon Sep 17 00:00:00 2001 From: "Nicolas Viseur (vin)" Date: Thu, 22 Feb 2024 00:56:41 +0000 Subject: [PATCH] [FIX] account_qr_code_emv: fallback error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The account_qr_code_emv module has an issue at the moment where it will only return errors in _get_error_messages_for_qr for the country the qr code is intended for. This makes sense since you want to check all countries in later versions where we have multiple of them. But it causes an issue with the standard implementation where if you are using a country that is not supported by an EMV QR, _get_error_messages_for_qr will just return None. This means that: - The default QR CODE selection on the invoice that depends on that may select EMV QR for unrelated countries. - If it gets selected, this method will not check that the currency is correct for said countries. To fix this issue, we will simply return an error message in the common module, which will serve as a fallback once all the EMV QR methods have been checked. Task id # 3758668 closes odoo/odoo#156847 X-original-commit: 5290fb7a2d400ce1c9732e8d835f6b7990c0d145 Signed-off-by: de Wouters de Bouchout Jean-BenoƮt (jbw) Signed-off-by: Nicolas Viseur (vin) --- .../i18n/account_qr_code_emv.pot | 7 +++++++ addons/account_qr_code_emv/models/res_bank.py | 7 +++++++ addons/l10n_hk/tests/test_l10n_hk_emv_qr.py | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/addons/account_qr_code_emv/i18n/account_qr_code_emv.pot b/addons/account_qr_code_emv/i18n/account_qr_code_emv.pot index c4edfc3ae55..7a76891a9a7 100644 --- a/addons/account_qr_code_emv/i18n/account_qr_code_emv.pot +++ b/addons/account_qr_code_emv/i18n/account_qr_code_emv.pot @@ -84,6 +84,13 @@ msgstr "" msgid "Missing Proxy Value." msgstr "" +#. module: account_qr_code_emv +#. odoo-python +#: code:addons/account_qr_code_emv/models/res_bank.py:0 +#, python-format +msgid "No EMV QR Code is available for the country of the account %(account_number)s." +msgstr "" + #. module: account_qr_code_emv #: model:ir.model.fields.selection,name:account_qr_code_emv.selection__res_partner_bank__proxy_type__none msgid "None" diff --git a/addons/account_qr_code_emv/models/res_bank.py b/addons/account_qr_code_emv/models/res_bank.py index f9f67f9ca09..bedf8525362 100644 --- a/addons/account_qr_code_emv/models/res_bank.py +++ b/addons/account_qr_code_emv/models/res_bank.py @@ -111,3 +111,10 @@ class ResPartnerBank(models.Model): rslt = super()._get_available_qr_methods() rslt.append(('emv_qr', _("EMV Merchant-Presented QR-code"), 30)) return rslt + + def _get_error_messages_for_qr(self, qr_method, debtor_partner, currency): + """ Return an error for emv_qr if the account's country does no match any methods found in inheriting modules.""" + if qr_method == 'emv_qr': + return _("No EMV QR Code is available for the country of the account %(account_number)s.", account_number=self.acc_number) + + return super()._get_error_messages_for_qr(qr_method, debtor_partner, currency) diff --git a/addons/l10n_hk/tests/test_l10n_hk_emv_qr.py b/addons/l10n_hk/tests/test_l10n_hk_emv_qr.py index 39c11347724..71729b9d632 100644 --- a/addons/l10n_hk/tests/test_l10n_hk_emv_qr.py +++ b/addons/l10n_hk/tests/test_l10n_hk_emv_qr.py @@ -106,3 +106,17 @@ class TestL10nHKEmvQrCode(AccountTestInvoicingCommon): # Check the whole qr code string self.assertEqual(emv_qr_vals, '00020101021226330012hk.com.hkicl0313+852-678912345204000053033445405100.55802HK5914company_1_data6002HK62170513INV/TEST/000263049E64') + + def test_invoice_default_code(self): + """ If no QR method is selected by default, and the country does not match, it should not be selecting the EMV QR method. """ + self.acc_emv_hk.country_code = 'NZ' + + self.assertIsNone(self.emv_qr_invoice._generate_qr_code()) + + def test_invoice_wrong_method(self): + """ If an EMV QR is selected on the invoice with a wrong country, it should raise errors messages. """ + self.acc_emv_hk.country_code = 'NZ' + self.emv_qr_invoice.qr_code_method = 'emv_qr' + + error_message = self.acc_emv_hk._get_error_messages_for_qr('emv_qr', self.partner_a, self.env.ref('base.HKD')) + self.assertIsNotNone(error_message)