From 7e6f7d943e8d030309795056b9d368eb049fa5d6 Mon Sep 17 00:00:00 2001
From: Yolann Sabaux
Date: Tue, 3 Jan 2023 12:55:31 +0000
Subject: [PATCH] [FIX] account: prevent qr-generation if errors in preview
Steps to reproduce:
- have a Swiss configuration for qr-code
1) make sure your customer company is in Switzerland and has all the address information
2) make sure the customer set an Invoicing address in Switzerland (address + Country)
3) have set for your bank account in in Accounting/Journals/Bank: the Iban AND the QR iban
- create an invoice for a Swiss client
* monthly
* confirm
- Preview the invoice
Issue:
error, we should able to see the invoice without qr code.
Solution:
the user will still see the error when trying to print the invoice
opw-3104890
closes odoo/odoo#111929
X-original-commit: 30a8e933b3cda9c3c663c4d05d1efdc023b17b1e
Signed-off-by: Olivier Colson (oco)
Signed-off-by: Yolann Sabaux (yosa)
---
addons/account/models/account_move.py | 4 ++--
addons/account/report/account_invoice_report.py | 2 +-
addons/account/views/report_invoice.xml | 2 +-
addons/l10n_in_upi/models/account_invoice.py | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 20c56f258e0..a58640c52e8 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -3739,7 +3739,7 @@ class AccountMove(models.Model):
line[2]['credit'] = currency_id and formatLang(self.env, line[2]['credit'], currency_obj=currency_id) or line[2]['debit']
return preview_vals
- def _generate_qr_code(self):
+ def _generate_qr_code(self, silent_errors=False):
""" Generates and returns a QR-code generation URL for this invoice,
raising an error message if something is misconfigured.
@@ -3770,7 +3770,7 @@ class AccountMove(models.Model):
return None
unstruct_ref = self.ref if self.ref else self.name
- rslt = self.partner_bank_id.build_qr_code_base64(self.amount_residual, unstruct_ref, self.payment_reference, self.currency_id, self.partner_id, qr_code_method, silent_errors=False)
+ rslt = self.partner_bank_id.build_qr_code_base64(self.amount_residual, unstruct_ref, self.payment_reference, self.currency_id, self.partner_id, qr_code_method, silent_errors=silent_errors)
# We only set qr_code_method after generating the url; otherwise, it
# could be set even in case of a failure in the QR code generation
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index 06b4565dac0..7beb151aa31 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -145,7 +145,7 @@ class ReportInvoiceWithoutPayment(models.AbstractModel):
qr_code_urls = {}
for invoice in docs:
if invoice.display_qr_code:
- new_code_url = invoice._generate_qr_code()
+ new_code_url = invoice._generate_qr_code(silent_errors=data['report_type'] == 'html')
if new_code_url:
qr_code_urls[invoice.id] = new_code_url
diff --git a/addons/account/views/report_invoice.xml b/addons/account/views/report_invoice.xml
index 36354160da8..586b3f20229 100644
--- a/addons/account/views/report_invoice.xml
+++ b/addons/account/views/report_invoice.xml
@@ -248,7 +248,7 @@
Incoterm: -
-
+
Scan me with your banking app.
diff --git a/addons/l10n_in_upi/models/account_invoice.py b/addons/l10n_in_upi/models/account_invoice.py
index d0c4411efd3..a0459530103 100644
--- a/addons/l10n_in_upi/models/account_invoice.py
+++ b/addons/l10n_in_upi/models/account_invoice.py
@@ -9,7 +9,7 @@ from odoo.tools.image import image_data_uri
class AccountMove(models.Model):
_inherit = "account.move"
- def _generate_qr_code(self):
+ def _generate_qr_code(self, silent_errors=False):
self.ensure_one()
if self.company_id.country_code == 'IN':
payment_url = 'upi://pay?pa=%s&pn=%s&am=%s&tr=%s&tn=%s' % (
@@ -20,4 +20,4 @@ class AccountMove(models.Model):
("Payment for %s" % self.name))
barcode = self.env['ir.actions.report'].barcode(barcode_type="QR", value=payment_url, width=120, height=120)
return image_data_uri(base64.b64encode(barcode))
- return super()._generate_qr_code()
+ return super()._generate_qr_code(silent_errors)