From 823e345ed985a6c2645f1170c2ffbe8380000f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A0n=20Todorovich?= Date: Tue, 11 Apr 2023 16:13:45 -0300 Subject: [PATCH 1/2] [FIX] pos_event_sale: wrong value for payment_status computation --- pos_event_sale/models/event_registration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pos_event_sale/models/event_registration.py b/pos_event_sale/models/event_registration.py index 5129b74249..bd0cf5167e 100644 --- a/pos_event_sale/models/event_registration.py +++ b/pos_event_sale/models/event_registration.py @@ -46,7 +46,7 @@ def _compute_payment_status(self): elif rec.is_paid: rec.payment_status = "paid" else: - rec.payment_status = "not_paid" + rec.payment_status = "to_pay" return res def _check_auto_confirmation(self): From e5a43565d2048e920525690311b0e285a442df67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A0n=20Todorovich?= Date: Tue, 11 Apr 2023 16:14:42 -0300 Subject: [PATCH 2/2] [IMP] pos_event_sale: implement event registration reprinting --- .../src/js/Screens/AbstractReceiptScreen.js | 47 +++++++++++++++++++ .../static/src/js/Screens/ReceiptScreen.js | 42 ++--------------- .../src/js/Screens/ReprintReceiptScreen.js | 45 ++++++++++++++++++ .../src/xml/ReceiptScreen/ReceiptScreen.xml | 1 - .../ReprintReceiptScreen.xml | 21 +++++++++ 5 files changed, 118 insertions(+), 38 deletions(-) create mode 100644 pos_event_sale/static/src/js/Screens/AbstractReceiptScreen.js create mode 100644 pos_event_sale/static/src/js/Screens/ReprintReceiptScreen.js create mode 100644 pos_event_sale/static/src/xml/ReprintReceiptScreen/ReprintReceiptScreen.xml diff --git a/pos_event_sale/static/src/js/Screens/AbstractReceiptScreen.js b/pos_event_sale/static/src/js/Screens/AbstractReceiptScreen.js new file mode 100644 index 0000000000..e04fb8f413 --- /dev/null +++ b/pos_event_sale/static/src/js/Screens/AbstractReceiptScreen.js @@ -0,0 +1,47 @@ +/* + Copyright 2023 Camptocamp SA (https://www.camptocamp.com). + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ +odoo.define("pos_event_sale.AbstractReceiptScreen", function (require) { + "use strict"; + + const AbstractReceiptScreen = require("point_of_sale.AbstractReceiptScreen"); + const Registries = require("point_of_sale.Registries"); + + /* eslint-disable no-shadow */ + const PosEventSaleAbstractReceiptScreen = (AbstractReceiptScreen) => + class extends AbstractReceiptScreen { + /** + * Prints the event registration receipts through the printer proxy. + * Doesn't do anything if there's no proxy printer. + * + * @returns {Boolean} + */ + async _printEventRegistrations() { + if (this.env.pos.proxy.printer) { + const $receipts = this.el.getElementsByClassName( + "event-registration-receipt" + ); + for (const $receipt of $receipts) { + const printResult = + await this.env.pos.proxy.printer.print_receipt( + $receipt.outerHTML + ); + if (!printResult.successful) { + console.error("Unable to print event registration receipt"); + console.debug(printResult); + return false; + } + } + return true; + } + return false; + } + }; + + Registries.Component.extend( + AbstractReceiptScreen, + PosEventSaleAbstractReceiptScreen + ); + return AbstractReceiptScreen; +}); diff --git a/pos_event_sale/static/src/js/Screens/ReceiptScreen.js b/pos_event_sale/static/src/js/Screens/ReceiptScreen.js index d1ea2b6caf..087ec8952e 100644 --- a/pos_event_sale/static/src/js/Screens/ReceiptScreen.js +++ b/pos_event_sale/static/src/js/Screens/ReceiptScreen.js @@ -9,48 +9,16 @@ odoo.define("pos_event_sale.ReceiptScreen", function (require) { const ReceiptScreen = require("point_of_sale.ReceiptScreen"); const Registries = require("point_of_sale.Registries"); + /* eslint-disable no-shadow */ const PosEventSaleReceiptScreen = (ReceiptScreen) => class extends ReceiptScreen { - /** - * Prints the event registration receipts through the printer proxy. - * Doesn't do anything if there's no proxy printer. - * - * @returns {Boolean} - */ - async _printEventRegistrationReceipts() { - if (this.env.pos.proxy.printer) { - for (const receiptEl of this.el.getElementsByClassName( - "event-registration-receipt" - )) { - const printResult = - await this.env.pos.proxy.printer.print_receipt( - receiptEl.outerHTML - ); - if (!printResult.successful) { - console.error("Unable to print event registration receipt"); - console.debug(printResult); - return false; - } - } - return true; - } - return false; - } /** * @override */ - async _printReceipt() { - // First, print the order receipt - const printed = await super._printReceipt(); - // Then, print the event registration receipts - if (printed && this.env.pos.proxy.printer) { - const registrationsPrinted = - await this._printEventRegistrationReceipts(); - if (!registrationsPrinted) { - return false; - } - } - return printed; + async printReceipt() { + const res = await super.printReceipt(); + await this._printEventRegistrations(); + return res; } }; diff --git a/pos_event_sale/static/src/js/Screens/ReprintReceiptScreen.js b/pos_event_sale/static/src/js/Screens/ReprintReceiptScreen.js new file mode 100644 index 0000000000..ee473d7c73 --- /dev/null +++ b/pos_event_sale/static/src/js/Screens/ReprintReceiptScreen.js @@ -0,0 +1,45 @@ +/* + Copyright 2023 Camptocamp (https://www.camptocamp.com). + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ +odoo.define("pos_event_sale.ReprintReceiptScreen", function (require) { + "use strict"; + + const ReprintReceiptScreen = require("point_of_sale.ReprintReceiptScreen"); + const Registries = require("point_of_sale.Registries"); + const session = require("web.session"); + + /* eslint-disable no-shadow */ + const PosEventSaleReprintReceiptScreen = (ReprintReceiptScreen) => + class extends ReprintReceiptScreen { + /** + * @override + */ + async willStart() { + await super.willStart(); + const order = this.props.order; + if (order.backendId && order.hasEvents()) { + order.event_registrations = await this.rpc({ + model: "event.registration", + method: "search_read", + domain: [ + ["pos_order_id", "=", order.backendId], + ["state", "=", "open"], + ], + kwargs: {context: session.user_context}, + }); + } + } + /** + * @override + */ + async _printReceipt() { + const res = await super._printReceipt(); + await this._printEventRegistrations(); + return res; + } + }; + + Registries.Component.extend(ReprintReceiptScreen, PosEventSaleReprintReceiptScreen); + return ReprintReceiptScreen; +}); diff --git a/pos_event_sale/static/src/xml/ReceiptScreen/ReceiptScreen.xml b/pos_event_sale/static/src/xml/ReceiptScreen/ReceiptScreen.xml index bfb5b21fa4..36518591ae 100644 --- a/pos_event_sale/static/src/xml/ReceiptScreen/ReceiptScreen.xml +++ b/pos_event_sale/static/src/xml/ReceiptScreen/ReceiptScreen.xml @@ -14,7 +14,6 @@ t-as="registration" order="currentOrder" registration="registration" - t-ref="event-registration-receipt" /> diff --git a/pos_event_sale/static/src/xml/ReprintReceiptScreen/ReprintReceiptScreen.xml b/pos_event_sale/static/src/xml/ReprintReceiptScreen/ReprintReceiptScreen.xml new file mode 100644 index 0000000000..2fd29c26dd --- /dev/null +++ b/pos_event_sale/static/src/xml/ReprintReceiptScreen/ReprintReceiptScreen.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + +