[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) <pivi@odoo.com>
Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
Victor Piryns (pivi)
2022-10-10 14:04:54 +02:00
parent 170a98d458
commit 503ed1420c
2 changed files with 31 additions and 11 deletions
+24 -8
View File
@@ -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
@@ -2,18 +2,22 @@
<templates id="template" xml:space="preserve">
<t t-inherit="point_of_sale.OrderReceipt" t-inherit-mode="extension" owl="1">
<xpath expr="//img[hasclass('pos-receipt-logo')]" position="after">
<t if="receipt.is_gcc_country">
<t t-if="receipt.is_gcc_country and !receipt.is_settlement">
<img t-if="receipt.qr_code" id="qrcode" t-att-src="receipt.qr_code" class="pos-receipt-logo"/>
<br/>
</t>
</xpath>
<xpath expr="//span[@id='title_english']" position="replace">
<span id="title_english">Simplified Tax Invoice</span>
<t t-if="!receipt.is_settlement">
<span id="title_english">Simplified Tax Invoice</span>
</t>
</xpath>
<xpath expr="//span[@id='title_arabic']" position="replace">
<span id="title_arabic">فاتورة ضريبية مبسطة</span>
<t t-if="!receipt.is_settlement">
<span id="title_arabic">فاتورة ضريبية مبسطة</span>
</t>
</xpath>
</t>
</templates>