From 40ee7288124178db03f4f04f812070e0de46fa2d Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Tue, 19 Dec 2023 14:32:17 +0000 Subject: [PATCH] [FIX] point_of_sale,pos_restaurant:save last preparation change on order Current behavior: Before this fix, when you sent the order to the kitchen, the preparation changes were not saved directly. So if you refreshed the page right after sending the order to the kitchen, the preparation changes were lost. Steps to reproduce: - Open a POS restaurant session - Add a product to the order - Click on Order - Refresh the page (F5) - Go back to the table were you made the order - The product still appears as not sent to the kitchen opw-3614345 closes odoo/odoo#148755 X-original-commit: 8f33d6fa0261373fee276efd20dcbf75e95e1e28 Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Robin Engels (roen) --- .../point_of_sale/static/src/app/store/pos_store.js | 5 +++++ .../static/tests/tours/pos_restaurant.js | 13 +++++++++++++ addons/pos_restaurant/tests/test_frontend.py | 7 +++++++ 3 files changed, 25 insertions(+) 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 30b4eba6586..959f4e296ec 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 @@ -1715,6 +1715,11 @@ export class PosStore extends Reactive { async sendOrderInPreparationUpdateLastChange(order, cancelled = false) { await this.sendOrderInPreparation(order, cancelled); order.updateLastOrderChange(); + + //We make sure that the last_order_change is updated in the backend + order.save_to_db(); + order.pos.ordersToUpdateSet.add(this); + order.pos.sendDraftToServer(); } closeScreen() { this.addOrderIfEmpty(); diff --git a/addons/pos_restaurant/static/tests/tours/pos_restaurant.js b/addons/pos_restaurant/static/tests/tours/pos_restaurant.js index 995e7e7f522..ac1629b1c39 100644 --- a/addons/pos_restaurant/static/tests/tours/pos_restaurant.js +++ b/addons/pos_restaurant/static/tests/tours/pos_restaurant.js @@ -142,3 +142,16 @@ registry.category("web_tour.tours").add("pos_restaurant_sync_second_login", { FloorScreen.orderCountSyncedInTableIs("4", "1"), ].flat(), }); + +registry.category("web_tour.tours").add("SaveLastPreparationChangesTour", { + test: true, + url: "/pos/ui", + steps: () => [ + ProductScreen.confirmOpeningPopup(), + FloorScreen.clickTable("5"), + ProductScreen.clickDisplayedProduct("Coca-Cola"), + ProductScreen.selectedOrderlineHas("Coca-Cola", "1.0"), + ProductScreen.clickOrderButton(), + ProductScreen.orderlinesHaveNoChange() + ].flat(), + }); diff --git a/addons/pos_restaurant/tests/test_frontend.py b/addons/pos_restaurant/tests/test_frontend.py index b00918a0066..2380b59fec3 100644 --- a/addons/pos_restaurant/tests/test_frontend.py +++ b/addons/pos_restaurant/tests/test_frontend.py @@ -262,3 +262,10 @@ class TestFrontend(AccountTestInvoicingCommon, HttpCaseWithUserDemo): self.office_combo.write({'lst_price': 40}) self.pos_config.with_user(self.pos_admin).open_ui() self.start_tour(f"/pos/ui?config_id={self.pos_config.id}", 'SplitBillScreenTour4PosCombo', login="pos_admin") + + def test_10_save_last_preparation_changes(self): + self.pos_config.write({'printer_ids': False}) + self.pos_config.with_user(self.pos_admin).open_ui() + self.start_tour("/pos/ui?config_id=%d" % self.pos_config.id, 'SaveLastPreparationChangesTour', login="pos_admin") + self.assertTrue(self.pos_config.current_session_id.order_ids.last_order_preparation_change, "There should be a last order preparation change") + self.assertTrue("Coca" in self.pos_config.current_session_id.order_ids.last_order_preparation_change, "The last order preparation change should contain 'Coca'")