[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) <oco@odoo.com> Signed-off-by: Yolann Sabaux (yosa) <yosa@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@
|
||||
<strong>Incoterm: </strong><span t-field="o.invoice_incoterm_id.code"/> - <span t-field="o.invoice_incoterm_id.name"/>
|
||||
</p>
|
||||
<div id="qrcode" t-if="o.display_qr_code and o.amount_residual > 0">
|
||||
<t t-set="qr_code_url" t-value="o._generate_qr_code()"/>
|
||||
<t t-set="qr_code_url" t-value="o._generate_qr_code(silent_errors=True)"/>
|
||||
<p t-if="qr_code_url">
|
||||
<strong class="text-center">Scan me with your banking app.</strong><br/><br/>
|
||||
<img class="border border-dark rounded" t-att-src="qr_code_url"/>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user