From 09c15454120f0675c60c2c68ff8d52eb74e5c6ab Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Mon, 11 Dec 2023 11:43:24 +0100 Subject: [PATCH] [FIX] point_of_sale: make sure to print changes before saving them Current behavior: When trying to print the changes of an order, nothing was printed. This was happening because we were first saving the changes before sending them to the printer. Because of this when we tried to retrieve the changes to print them, they were already saved and we were not retrieving anything. Steps to reproduce: - Setup a printer to print order changes - Create a new order in PoS restaurant - Add a product to the order - Click on the "Order" button - Nothing is printed opw-3625397 closes odoo/odoo#146461 Signed-off-by: Joseph Caburnay (jcb) --- .../static/src/app/screens/receipt_screen/receipt_screen.js | 2 +- .../static/src/app/screens/ticket_screen/ticket_screen.js | 2 +- addons/point_of_sale/static/src/app/store/pos_store.js | 3 +++ .../product_screen/actionpad_widget/actionpad_widget.js | 2 +- .../src/overrides/components/product_screen/product_screen.js | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/point_of_sale/static/src/app/screens/receipt_screen/receipt_screen.js b/addons/point_of_sale/static/src/app/screens/receipt_screen/receipt_screen.js index b1da75732a7..7247187bd19 100644 --- a/addons/point_of_sale/static/src/app/screens/receipt_screen/receipt_screen.js +++ b/addons/point_of_sale/static/src/app/screens/receipt_screen/receipt_screen.js @@ -34,7 +34,7 @@ export class ReceiptScreen extends Component { // to send in preparation it is automatically sent if (this.pos.orderPreparationCategories.size) { try { - await this.pos.sendOrderInPreparation(this.currentOrder); + await this.pos.sendOrderInPreparationUpdateLastChange(this.currentOrder); } catch (error) { Promise.reject(error); } diff --git a/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js b/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js index 31dc2f7bc7c..b33c6d99522 100644 --- a/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js +++ b/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js @@ -155,7 +155,7 @@ export class TicketScreen extends Component { } if (order && (await this._onBeforeDeleteOrder(order))) { if (Object.keys(order.lastOrderPrepaChange).length > 0) { - await this.pos.sendOrderInPreparation(order, true); + await this.pos.sendOrderInPreparationUpdateLastChange(order, true); } if (order === this.pos.get_order()) { this._selectNextOrder(order); diff --git a/addons/point_of_sale/static/src/app/store/pos_store.js b/addons/point_of_sale/static/src/app/store/pos_store.js index 8d66a36c73a..30b4eba6586 100644 --- a/addons/point_of_sale/static/src/app/store/pos_store.js +++ b/addons/point_of_sale/static/src/app/store/pos_store.js @@ -1711,6 +1711,9 @@ export class PosStore extends Reactive { console.warn("Failed in printing the changes in the order", e); } } + } + async sendOrderInPreparationUpdateLastChange(order, cancelled = false) { + await this.sendOrderInPreparation(order, cancelled); order.updateLastOrderChange(); } closeScreen() { diff --git a/addons/pos_restaurant/static/src/overrides/components/product_screen/actionpad_widget/actionpad_widget.js b/addons/pos_restaurant/static/src/overrides/components/product_screen/actionpad_widget/actionpad_widget.js index 5f0ab700003..bc302594a36 100644 --- a/addons/pos_restaurant/static/src/overrides/components/product_screen/actionpad_widget/actionpad_widget.js +++ b/addons/pos_restaurant/static/src/overrides/components/product_screen/actionpad_widget/actionpad_widget.js @@ -23,7 +23,7 @@ patch(ActionpadWidget.prototype, { if (!this.clicked) { this.clicked = true; try { - await this.pos.sendOrderInPreparation(this.currentOrder); + await this.pos.sendOrderInPreparationUpdateLastChange(this.currentOrder); } finally { this.clicked = false; } diff --git a/addons/pos_restaurant/static/src/overrides/components/product_screen/product_screen.js b/addons/pos_restaurant/static/src/overrides/components/product_screen/product_screen.js index 719e09e684e..c2db9fe57a9 100644 --- a/addons/pos_restaurant/static/src/overrides/components/product_screen/product_screen.js +++ b/addons/pos_restaurant/static/src/overrides/components/product_screen/product_screen.js @@ -34,7 +34,7 @@ patch(ProductScreen.prototype, { return this.pos.config.module_pos_restaurant && this.pos.orderPreparationCategories.size; }, submitOrder() { - this.pos.sendOrderInPreparation(this.pos.get_order()); + this.pos.sendOrderInPreparationUpdateLastChange(this.pos.get_order()); }, get primaryReviewButton() { return (