[REF] pos*: use /report for qr code generation

pos*: point_of_sale, pos_online_pay

In this pr we remove the custom generation of qr codes and
adapt the codebase to rely on the `/report/barcode` api.

Task: 3550015
Part-of: odoo/odoo#137397
This commit is contained in:
vlst
2023-10-18 15:26:31 +00:00
parent 8c955c21bf
commit 5236435bb2
4 changed files with 14 additions and 26 deletions
@@ -1,6 +1,6 @@
/** @odoo-module */
import { uuidv4, constructFullProductName } from "@point_of_sale/utils";
import { qrCodeSrc, uuidv4, constructFullProductName } from "@point_of_sale/utils";
// FIXME POSREF - unify use of native parseFloat and web's parseFloat. We probably don't need the native version.
import { parseFloat as oParseFloat } from "@web/views/fields/parsers";
import {
@@ -1627,7 +1627,11 @@ export class Order extends PosModel {
logo: this.pos.company_logo_base64,
},
currency: this.pos.currency,
pos_qr_code: this._get_qr_code_data(),
pos_qr_code:
this.pos.company.point_of_sale_use_ticket_qr_code &&
qrCodeSrc(
`${this.pos.base_url}/pos/ticket/validate?access_token=${this.access_token}`
),
ticket_code: this.pos.company.point_of_sale_ticket_unique_code
? this.ticketCode
: false,
@@ -2812,21 +2816,6 @@ export class Order extends PosModel {
return true;
}
}
_get_qr_code_data() {
if (this.pos.company.point_of_sale_use_ticket_qr_code) {
// Use the unique access token to ensure the authenticity of the request. Use the order reference as a second check just in case.
return this._make_qr_code_data(
`${this.pos.base_url}/pos/ticket/validate?access_token=${this.access_token}`
);
} else {
return false;
}
}
_make_qr_code_data(url) {
const codeWriter = new window.ZXing.BrowserQRCodeSvgWriter();
const qr_code_svg = new XMLSerializer().serializeToString(codeWriter.write(url, 150, 150));
return "data:image/svg+xml;base64," + window.btoa(qr_code_svg);
}
/**
* Returns a random 5 digits alphanumeric code
* @returns {string}
+4
View File
@@ -53,3 +53,7 @@ export function constructFullProductName(line, attribute_value_by_id, display_na
return attributeString !== "" ? `${display_name} ${attributeString}` : display_name;
}
export function qrCodeSrc(url, { size = 200 } = {}) {
return `/report/barcode/QR/${encodeURIComponent(url)}?width=${size}&height=${size}`;
}
@@ -7,6 +7,7 @@ import { OnlinePaymentPopup } from "@pos_online_payment/app/utils/online_payment
import { ConfirmPopup } from "@point_of_sale/app/utils/confirm_popup/confirm_popup";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
import { floatIsZero } from "@web/core/utils/numbers";
import { qrCodeSrc } from "@point_of_sale/utils";
patch(PaymentScreen.prototype, {
getRemainingOnlinePaymentLines() {
@@ -96,8 +97,7 @@ patch(PaymentScreen.prototype, {
return false;
}
const qrCodeData = this.currentOrder._get_online_payment_qr_code_data();
if (!qrCodeData || qrCodeData.length == 0) {
if (!this.currentOrder.server_id) {
this.cancelOnlinePayment(this.currentOrder);
this.popup.add(ErrorPopup, {
title: _t("Online payment unavailable"),
@@ -105,6 +105,7 @@ patch(PaymentScreen.prototype, {
});
return false;
}
const qrCodeImgSrc = qrCodeSrc(`${this.pos.base_url}/pos/pay/${this.currentOrder.server_id}?access_token=${this.currentOrder.access_token}`);
let prevOnlinePaymentLine = null;
let lastOrderServerOPData = null;
@@ -132,7 +133,7 @@ patch(PaymentScreen.prototype, {
onlinePaymentLine.set_payment_status("waiting");
this.currentOrder.select_paymentline(onlinePaymentLine);
lastOrderServerOPData = await this.showOnlinePaymentQrCode(qrCodeData, onlinePaymentLineAmount);
lastOrderServerOPData = await this.showOnlinePaymentQrCode(qrCodeImgSrc, onlinePaymentLineAmount);
if (onlinePaymentLine.get_payment_status() === "waiting") {
onlinePaymentLine.set_payment_status(undefined);
}
@@ -4,12 +4,6 @@ import { Order, Payment } from "@point_of_sale/app/store/models";
import { floatIsZero } from "@web/core/utils/numbers";
patch(Order.prototype, {
_get_online_payment_url() {
return `${this.pos.base_url}/pos/pay/${this.server_id}?access_token=${this.access_token}`;
},
_get_online_payment_qr_code_data() {
return this.server_id ? this._make_qr_code_data(this._get_online_payment_url()) : false;
},
async update_online_payments_data_with_server(orm, next_online_payment_amount) {
if (!this.server_id) {
return false;