From 508dc8ac8b91d5a0140f912cc284dced3d6c0c52 Mon Sep 17 00:00:00 2001 From: Camille Spiritus Date: Tue, 15 Nov 2022 13:12:08 +0000 Subject: [PATCH] [FIX] account-l10n_ch: solve sepa vs swiss QR problems Aim : Allow customer from Switzerland to emit an invoice with a QR code to a SEPA customer. Context: In Switzerland, adding an extra page containing a QR Bill is mandatory in many cases, mainly when the customer is also from Switzerland (although there are other conditions). However, activating the option 'QR Codes' in the settings (which is not linked to the QR Bill) can cause problem. For instance, it will be impossible to bill a foreign customer, because we check that the conditions are right to emit a swiss QR (which is a bug). After this commit : The new behaviour is : - Swiss user --> swiss customer: don't change the invoice, allow to create a QR Bill - SEPA option activated, swiss user --> SEPA customer : join the SEPA QR to the invoice - SEPA option activated, swiss user --> swiss customer : raise error task-3062570 Manual fw-port of https://github.com/odoo/odoo/pull/109808 closes odoo/odoo#109935 X-original-commit: a9980477048e4adffda4a71a72ff1cc8490637f9 Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_move.py | 2 +- addons/l10n_ch/__manifest__.py | 1 + addons/l10n_ch/models/res_bank.py | 2 ++ addons/l10n_ch/views/account_invoice.xml | 8 ++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 addons/l10n_ch/views/account_invoice.xml diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index e0cd13f76d8..fb216f05347 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3768,7 +3768,7 @@ class AccountMove(models.Model): else: # Else we find one that's eligible and assign it to the invoice for candidate_method, _candidate_name in self.env['res.partner.bank'].get_available_qr_methods_in_sequence(): - if self.partner_bank_id._eligible_for_qr_code(candidate_method, self.partner_id, self.currency_id): + if self.partner_bank_id._eligible_for_qr_code(candidate_method, self.partner_id, self.currency_id, raises_error=False): qr_code_method = candidate_method break diff --git a/addons/l10n_ch/__manifest__.py b/addons/l10n_ch/__manifest__.py index 4de7e40085e..ec74bbdb94f 100644 --- a/addons/l10n_ch/__manifest__.py +++ b/addons/l10n_ch/__manifest__.py @@ -49,6 +49,7 @@ Here is how it works: 'report/swissqr_report.xml', 'views/res_bank_view.xml', 'views/account_invoice_view.xml', + 'views/account_invoice.xml', 'views/res_config_settings_views.xml', 'views/setup_wizard_views.xml', 'views/qr_invoice_wizard_view.xml' diff --git a/addons/l10n_ch/models/res_bank.py b/addons/l10n_ch/models/res_bank.py index d24673ff425..a06542d2d81 100644 --- a/addons/l10n_ch/models/res_bank.py +++ b/addons/l10n_ch/models/res_bank.py @@ -347,6 +347,8 @@ class ResPartnerBank(models.Model): # see https://github.com/arthurdejong/python-stdnum/blob/master/stdnum/iso11649.py def _eligible_for_qr_code(self, qr_method, debtor_partner, currency, raises_error=True): + if qr_method == 'sct_qr' and debtor_partner.country_id.code == 'CH' and self.journal_id.country_code == 'CH': + return False if qr_method == 'ch_qr': error_messages = [_("The QR code could not be generated for the following reason(s):")] if self.acc_type != 'iban': diff --git a/addons/l10n_ch/views/account_invoice.xml b/addons/l10n_ch/views/account_invoice.xml new file mode 100644 index 00000000000..9bbd33c772c --- /dev/null +++ b/addons/l10n_ch/views/account_invoice.xml @@ -0,0 +1,8 @@ + + + +