[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) <bib@odoo.com>
This commit is contained in:
Camille Spiritus
2023-01-16 18:14:53 +01:00
parent cb9e936dc8
commit 508dc8ac8b
4 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -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
+1
View File
@@ -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'
+2
View File
@@ -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':
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<odoo>
<template id="l10n_ch_report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//div[@id='qrcode']" position="attributes">
<attribute name="t-if" add="and o.qr_code_method != 'ch_qr'" separator=" "/>
</xpath>
</template>
</odoo>