From 3b50fb042617246d3ba2db378f6d08ffb42afdb3 Mon Sep 17 00:00:00 2001 From: Josse Colpaert <jco@odoo.com> Date: Mon, 27 Dec 2021 09:19:46 +0000 Subject: [PATCH] [FIX] l10n_sa_invoice: amounts in the QR code should be in Saudi Riyal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes odoo/odoo#81979 Signed-off-by: William André (wan) <wan@odoo.com> --- addons/l10n_sa_invoice/models/account_move.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/l10n_sa_invoice/models/account_move.py b/addons/l10n_sa_invoice/models/account_move.py index 1e03454853e7..26f450790c99 100644 --- a/addons/l10n_sa_invoice/models/account_move.py +++ b/addons/l10n_sa_invoice/models/account_move.py @@ -4,6 +4,7 @@ import base64 from odoo import api, fields, models, _ from odoo.exceptions import UserError +from odoo.tools import float_repr class AccountMove(models.Model): @@ -21,13 +22,13 @@ class AccountMove(models.Model): for move in self: move.l10n_sa_show_delivery_date = move.country_code == 'SA' and move.move_type in ('out_invoice', 'out_refund') - @api.depends('amount_total', 'amount_untaxed', 'l10n_sa_confirmation_datetime', 'company_id', 'company_id.vat') + @api.depends('amount_total_signed', 'amount_tax_signed', 'l10n_sa_confirmation_datetime', 'company_id', 'company_id.vat') def _compute_qr_code_str(self): """ Generate the qr code for Saudi e-invoicing. Specs are available at the following link at page 23 https://zatca.gov.sa/ar/E-Invoicing/SystemsDevelopers/Documents/20210528_ZATCA_Electronic_Invoice_Security_Features_Implementation_Standards_vShared.pdf """ def get_qr_encoding(tag, field): - company_name_byte_array = field.encode('UTF-8') + company_name_byte_array = field.encode() company_name_tag_encoding = tag.to_bytes(length=1, byteorder='big') company_name_length_encoding = len(company_name_byte_array).to_bytes(length=1, byteorder='big') return company_name_tag_encoding + company_name_length_encoding + company_name_byte_array @@ -39,11 +40,11 @@ class AccountMove(models.Model): company_vat_enc = get_qr_encoding(2, record.company_id.vat) time_sa = fields.Datetime.context_timestamp(self.with_context(tz='Asia/Riyadh'), record.l10n_sa_confirmation_datetime) timestamp_enc = get_qr_encoding(3, time_sa.isoformat()) - invoice_total_enc = get_qr_encoding(4, str(record.amount_total)) - total_vat_enc = get_qr_encoding(5, str(record.currency_id.round(record.amount_total - record.amount_untaxed))) + invoice_total_enc = get_qr_encoding(4, float_repr(abs(record.amount_total_signed), 2)) + total_vat_enc = get_qr_encoding(5, float_repr(abs(record.amount_tax_signed), 2)) str_to_encode = seller_name_enc + company_vat_enc + timestamp_enc + invoice_total_enc + total_vat_enc - qr_code_str = base64.b64encode(str_to_encode).decode('UTF-8') + qr_code_str = base64.b64encode(str_to_encode).decode() record.l10n_sa_qr_code_str = qr_code_str def _post(self, soft=True): -- GitLab