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)