From 503ed1420c4f4641ebc997fc7d0ca70f0ffcc3c2 Mon Sep 17 00:00:00 2001 From: "Victor Piryns (pivi)" Date: Mon, 26 Sep 2022 13:14:58 +0000 Subject: [PATCH] [FIX] l10n_sa_pos: not create invoice on pos settlement Current behaviour: Currently when settling an account in a POS session, in Saudi Arabia, there is QR code on the receipt and a title "Simplified Tax Invoice", which should not be present on settlement Expected behaviour: Receipts generated from a settlement in Saudi Arabia localisation shouldn't generate a QR code and a tax title. Steps to reproduce: - install the modules: `l10n_sa`, `l10n_sa_pos`, `settle_due` - Switch to the Saudi Arabia company - Enter POS and create at least 2 payment method: - Cash: Identify Customer = false, Journal = Cash - Customer Balance: Identify Customer = true, Journal = empty - Create a new POS Session, just add "Customer Balance" to payment methods, the rest of settings are as default (might need to add "Customer Invoices" to the journal of the session) - Start a new session, find a customer with some "Amount Due" and click on the value, choose one of the payment methods - On the payment screen choose "Customer Balance", now you should have 2 payment lines, one is the payment methods for settling, the other is the customer balance with a negative value. - When validating, the receipt has a QR code and Invoice title, when it shouldn't. Reason for the problem: There is currently no state that differentiate between a normal order and a settlement. Fix: Implement a settlement state (computed) in the localistation order model. Add the state to the data that goes to the templating engine. Add conditional rendering for the templates related to the QR code and the "Simplified Tax Invoice" title. Affected versions: - 15.0 - saas-15.2 - saas-15.3 - 16.0 - master opw-2976267 closes odoo/odoo#102853 X-original-commit: 0b04230d3c5e7fc1bc83340ec2fca9cf646cbc60 Signed-off-by: Piryns Victor (pivi) Signed-off-by: Masereel Pierre --- addons/l10n_sa_pos/static/src/js/models.js | 32 ++++++++++++++----- .../static/src/xml/OrderReceipt.xml | 10 ++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/addons/l10n_sa_pos/static/src/js/models.js b/addons/l10n_sa_pos/static/src/js/models.js index 9806a8704d7..952e616f24d 100644 --- a/addons/l10n_sa_pos/static/src/js/models.js +++ b/addons/l10n_sa_pos/static/src/js/models.js @@ -6,15 +6,31 @@ var Registries = require('point_of_sale.Registries'); const PosL10nSAOrder = (Order) => class PosL10nSAOrder extends Order { export_for_printing() { - var result = super.export_for_printing(...arguments); - if (this.pos.company.country.code === 'SA') { - const codeWriter = new window.ZXing.BrowserQRCodeSvgWriter() - let qr_values = this.compute_sa_qr_code(result.company.name, result.company.vat, result.date.isostring, result.total_with_tax, result.total_tax); - let qr_code_svg = new XMLSerializer().serializeToString(codeWriter.write(qr_values, 150, 150)); - result.qr_code = "data:image/svg+xml;base64,"+ window.btoa(qr_code_svg); - } - return result; + var result = super.export_for_printing(...arguments); + if (this.pos.company.country.code === 'SA') { + result.is_settlement = this.is_settlement(); + if (!result.is_settlement) { + const codeWriter = new window.ZXing.BrowserQRCodeSvgWriter() + let qr_values = this.compute_sa_qr_code(result.company.name, result.company.vat, result.date.isostring, result.total_with_tax, result.total_tax); + let qr_code_svg = new XMLSerializer().serializeToString(codeWriter.write(qr_values, 150, 150)); + result.qr_code = "data:image/svg+xml;base64," + window.btoa(qr_code_svg); + } + } + return result; } + /** + * If the order is empty (there are no products) + * and all "pay_later" payments are negative, + * we are settling a customer's account. + * If the module pos_settle_due is not installed, + * the function always returns false (since "pay_later" doesn't exist) + * @returns {boolean} true if the current order is a settlement, else false + */ + is_settlement() { + return this.is_empty() && + !!this.paymentlines.filter(paymentline => paymentline.payment_method.type === "pay_later" && paymentline.amount < 0).length; + } + compute_sa_qr_code(name, vat, date_isostring, amount_total, amount_tax) { /* 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 diff --git a/addons/l10n_sa_pos/static/src/xml/OrderReceipt.xml b/addons/l10n_sa_pos/static/src/xml/OrderReceipt.xml index 78fdfaa2f84..6b6551f6fe5 100644 --- a/addons/l10n_sa_pos/static/src/xml/OrderReceipt.xml +++ b/addons/l10n_sa_pos/static/src/xml/OrderReceipt.xml @@ -2,18 +2,22 @@ - +
- Simplified Tax Invoice + + Simplified Tax Invoice + - فاتورة ضريبية مبسطة + + فاتورة ضريبية مبسطة +