From 5236435bb29b533818363a817463df9417bd2948 Mon Sep 17 00:00:00 2001 From: vlst Date: Wed, 11 Oct 2023 17:24:55 +0200 Subject: [PATCH] [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 --- .../static/src/app/store/models.js | 23 +++++-------------- addons/point_of_sale/static/src/utils.js | 4 ++++ .../screens/payment_screen/payment_screen.js | 7 +++--- .../static/src/app/store/models.js | 6 ----- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/addons/point_of_sale/static/src/app/store/models.js b/addons/point_of_sale/static/src/app/store/models.js index ca08c4a561c..4dd24471876 100644 --- a/addons/point_of_sale/static/src/app/store/models.js +++ b/addons/point_of_sale/static/src/app/store/models.js @@ -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} diff --git a/addons/point_of_sale/static/src/utils.js b/addons/point_of_sale/static/src/utils.js index fa30d1cd12c..56545f7e57f 100644 --- a/addons/point_of_sale/static/src/utils.js +++ b/addons/point_of_sale/static/src/utils.js @@ -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}`; +} diff --git a/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js b/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js index c087c7492d2..22e39394f2e 100644 --- a/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js +++ b/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js @@ -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); } diff --git a/addons/pos_online_payment/static/src/app/store/models.js b/addons/pos_online_payment/static/src/app/store/models.js index 0ef569cd1cd..8265dfbed40 100644 --- a/addons/pos_online_payment/static/src/app/store/models.js +++ b/addons/pos_online_payment/static/src/app/store/models.js @@ -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;