From 3764cef64a079cd1a2edf7003cc5650052c52dd4 Mon Sep 17 00:00:00 2001 From: "Loukas Wets (lowe)" Date: Fri, 6 Oct 2023 09:02:04 +0200 Subject: [PATCH] [FIX] point_of_sale,pos_restaurant: load data on new pos config In this commit 2 issues are fixed. The first issue is when trying to load demo data when the default pos configs are deleted. The second is when trying to reload onboarding data when the products are already loaded but archived (task-3539455). steps to reproduce the first issue: - load db without demo data - delete pos created by default - create a new pos config - open and try to load demo data steps to reproduce the second issue: - load db without demo data - open pos and load demo data - archive products - open pos and try to load demo data changes: - main pos config demo data has been separated from onboarding data. - condition has been added in the search count of _pos_has_valid_product method to check for archived products. closes odoo/odoo#138035 Related: odoo/enterprise#48621 Signed-off-by: Joseph Caburnay (jcb) --- .../data/point_of_sale_onboarding.xml | 201 -------- .../point_of_sale_onboarding_main_config.xml | 200 +++++++ addons/point_of_sale/models/pos_session.py | 25 +- .../product_list/product_list.js | 4 +- .../product_list/product_list.xml | 4 +- .../static/src/app/store/pos_store.js | 5 +- .../data/pos_restaurant_onboarding.xml | 487 ----------------- .../pos_restaurant_onboarding_main_config.xml | 488 ++++++++++++++++++ addons/pos_restaurant/models/pos_session.py | 27 +- 9 files changed, 721 insertions(+), 720 deletions(-) create mode 100644 addons/point_of_sale/data/point_of_sale_onboarding_main_config.xml create mode 100644 addons/pos_restaurant/data/pos_restaurant_onboarding_main_config.xml diff --git a/addons/point_of_sale/data/point_of_sale_onboarding.xml b/addons/point_of_sale/data/point_of_sale_onboarding.xml index be12d687bb3..a8d8f269098 100644 --- a/addons/point_of_sale/data/point_of_sale_onboarding.xml +++ b/addons/point_of_sale/data/point_of_sale_onboarding.xml @@ -14,10 +14,6 @@ - - - True - @@ -666,17 +662,6 @@ - - - - - - - Office Chair Black @@ -906,190 +891,4 @@ - - - - - - - - - - - - - - - ClosedDemo/0001 - paid - 4.81 - 0.0 - 4.81 - 0.0 - Order 00000-001-1001 - - - - - 1.98 - 1.98 - 1.98 - - Wall Shelf - - - - - 2.83 - 2.83 - 2.83 - - Small Shelf - - - - - - 4.81 - - - - - - ClosedDemo/0002 - paid - 2220.50 - 0.0 - 2220.50 - 0.0 - Order 00000-001-1002 - - - - - 120.50 - 120.5 - 120.50 - - Office Chair Black - - - - - 2100.0 - 2100.0 - 2100.0 - - Desk Stand with Screen - - - - - - 2220.50 - - - - - - - - - - - - - - - - - - - - - ClosedDemo/0003 - paid - 9.90 - 0.0 - 9.90 - 0.0 - Order 00000-002-1001 - - - - Closed Orderline 2.1.1 - - 4.80 - 4.80 - 4.80 - - Letter Tray - - - - Closed Orderline 2.1.2 - - 5.10 - 5.10 - 5.10 - - Desk Organizer - - - - - - 9.90 - - - - - - ClosedDemo/0004 - paid - 8.36 - 0.0 - 8.36 - 0.0 - Order 00000-002-1002 - - - - Closed Orderline 2.2.1 - - 1.98 - 1.98 - 1.98 - - Magnetic Board - - - - Closed Orderline 2.1.2 - - 6.38 - 6.38 - 2 - 3.19 - - Monitor Stand - - - - - - 8.36 - - - - - - - diff --git a/addons/point_of_sale/data/point_of_sale_onboarding_main_config.xml b/addons/point_of_sale/data/point_of_sale_onboarding_main_config.xml new file mode 100644 index 00000000000..6db6049fc3d --- /dev/null +++ b/addons/point_of_sale/data/point_of_sale_onboarding_main_config.xml @@ -0,0 +1,200 @@ + + + + + True + + + + + + + + + + + + + + + + + + ClosedDemo/0001 + paid + 4.81 + 0.0 + 4.81 + 0.0 + Order 00000-001-1001 + + + + + 1.98 + 1.98 + 1.98 + + Wall Shelf + + + + + 2.83 + 2.83 + 2.83 + + Small Shelf + + + + + + 4.81 + + + + + + ClosedDemo/0002 + paid + 2220.50 + 0.0 + 2220.50 + 0.0 + Order 00000-001-1002 + + + + + 120.50 + 120.5 + 120.50 + + Office Chair Black + + + + + 2100.0 + 2100.0 + 2100.0 + + Desk Stand with Screen + + + + + + 2220.50 + + + + + + + + + + + + + + + + + + + + + ClosedDemo/0003 + paid + 9.90 + 0.0 + 9.90 + 0.0 + Order 00000-002-1001 + + + + Closed Orderline 2.1.1 + + 4.80 + 4.80 + 4.80 + + Letter Tray + + + + Closed Orderline 2.1.2 + + 5.10 + 5.10 + 5.10 + + Desk Organizer + + + + + + 9.90 + + + + + + ClosedDemo/0004 + paid + 8.36 + 0.0 + 8.36 + 0.0 + Order 00000-002-1002 + + + + Closed Orderline 2.2.1 + + 1.98 + 1.98 + 1.98 + + Magnetic Board + + + + Closed Orderline 2.1.2 + + 6.38 + 6.38 + 2 + 3.19 + + Monitor Stand + + + + + + 8.36 + + + + + + + + + diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index b17e6ebccdd..b3559a296c4 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -2206,24 +2206,27 @@ class PosSession(models.Model): self.message_post(body=body, author_id=partner_id) def _pos_has_valid_product(self): - return self.env['product.product'].sudo().search_count(['&', ('available_in_pos', '=', True), ('list_price', '>', 0)], limit=1) > 0 + return self.env['product.product'].sudo().search_count([('available_in_pos', '=', True), ('list_price', '>', 0), '|', ('active', '=', False), ('active', '=', True)], limit=1) > 0 @api.model def _load_onboarding_data(self): convert.convert_file(self.env, 'point_of_sale', 'data/point_of_sale_onboarding.xml', None, mode='init', kind='data') - shop_config = self.env.ref('point_of_sale.pos_config_main') - if len(shop_config.session_ids.filtered(lambda s: s.state == 'opened')) == 0: - self.env['pos.session'].create({ - 'config_id': shop_config.id, - 'user_id': self.env.ref('base.user_admin').id, - }) + shop_config = self.env.ref('point_of_sale.pos_config_main', raise_if_not_found=False) + if shop_config: + convert.convert_file(self.env, 'point_of_sale', 'data/point_of_sale_onboarding_main_config.xml', None, mode='init', kind='data') + if len(shop_config.session_ids.filtered(lambda s: s.state == 'opened')) == 0: + self.env['pos.session'].create({ + 'config_id': shop_config.id, + 'user_id': self.env.ref('base.user_admin').id, + }) def _after_load_onboarding_data(self): config = self.env.ref('point_of_sale.pos_config_main', raise_if_not_found=False) - config.with_context(bypass_categories_forbidden_change=True).write({ - 'limit_categories': True, - 'iface_available_categ_ids': [Command.link(self.env.ref('point_of_sale.pos_category_miscellaneous').id), Command.link(self.env.ref('point_of_sale.pos_category_desks').id), Command.link(self.env.ref('point_of_sale.pos_category_chairs').id)] - }) + if config: + config.with_context(bypass_categories_forbidden_change=True).write({ + 'limit_categories': True, + 'iface_available_categ_ids': [Command.link(self.env.ref('point_of_sale.pos_category_miscellaneous').id), Command.link(self.env.ref('point_of_sale.pos_category_desks').id), Command.link(self.env.ref('point_of_sale.pos_category_chairs').id)] + }) def load_product_frontend(self): allowed = not self._pos_has_valid_product() diff --git a/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.js b/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.js index e19b5ef9581..120754dfb1d 100644 --- a/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.js +++ b/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.js @@ -66,9 +66,7 @@ export class ProductsWidget extends Component { } return false; } - get posHasValidProduct() { - return this.pos.posHasValidProduct(); - } + get selectedCategoryId() { return this.pos.selectedCategoryId; } diff --git a/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.xml b/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.xml index 81c104457d9..fe89f8af908 100644 --- a/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.xml +++ b/addons/point_of_sale/static/src/app/screens/product_screen/product_list/product_list.xml @@ -16,7 +16,7 @@ debounceMillis="100" />
-
+
No products found for "" in this category.

- +

There are no products in this category.

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 81e69f8d990..f61ece95cd7 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 @@ -489,10 +489,7 @@ export class PosStore extends Reactive { * @returns true if the POS app (not only this POS config) has at least one valid product. */ posHasValidProduct() { - return ( - this.pos_has_valid_product || - Object.values(this.db.product_by_id).some((p) => p.available_in_pos && p.lst_price > 0) - ); + return this.pos_has_valid_product; } setSelectedCategoryId(categoryId) { diff --git a/addons/pos_restaurant/data/pos_restaurant_onboarding.xml b/addons/pos_restaurant/data/pos_restaurant_onboarding.xml index 7a0ce17b000..7e801324794 100644 --- a/addons/pos_restaurant/data/pos_restaurant_onboarding.xml +++ b/addons/pos_restaurant/data/pos_restaurant_onboarding.xml @@ -231,492 +231,5 @@ - - - Restaurant - True - - True - - - - - - - - - - - - - - - - - - - - - - ClosedDemo/0005 - paid - 14.0 - 0.0 - 14.0 - 0.0 - Order 00000-003-1001 - - - - Closed Orderline 3.1.1 - - 7.0 - 7.0 - 7.0 - - Margherita - - - - Closed Orderline 3.1.2 - - 7.0 - 7.0 - 7.0 - - Funghi - - - - - - 14.0 - - - - - - ClosedDemo/0006 - paid - 7.0 - 0.0 - 7.0 - 0.0 - Order 00000-003-1002 - - - - Closed Orderline 3.2.1 - - 7.0 - 7.0 - 7.0 - - Vegetarian - - - - - - 7.0 - - - - - - - - - - - - - - - - - ClosedDemo/0007 - paid - 6.7 - 0.0 - 6.7 - 0.0 - Order 00000-004-1001 - - - - Closed Orderline 4.1.1 - - 2.20 - 2.20 - 2.20 - - Water - - - - Closed Orderline 4.1.2 - - 4.5 - 4.5 - 4.5 - - Pasta Bolognese - - - - - - 6.7 - - - - - - ClosedDemo/0008 - paid - 28.0 - 0.0 - 28.0 - 0.0 - Order 00000-004-1002 - - - - Closed Orderline 4.2.1 - - 28.0 - 28.0 - 7.0 - 4 - - Cheese Burger - - - - - - 28.0 - - - - - - - Main Floor - rgb(136,137,242) - - - - - 1 - - 4 - rgb(53,211,116) - square - 100 - 100 - 50 - 50 - - - - 2 - - 4 - rgb(53,211,116) - square - 100 - 100 - 212 - 50 - - - - 3 - - 4 - rgb(53,211,116) - square - 100 - 100 - 374 - 50 - - - - 4 - - 4 - rgb(53,211,116) - square - 100 - 100 - 536 - 50 - - - - 5 - - 4 - rgb(53,211,116) - square - 100 - 100 - 698 - 50 - - - - 6 - - 4 - rgb(53,211,116) - square - 100 - 100 - 860 - 50 - - - - 7 - - 4 - rgb(235,109,109) - square - 100 - 100 - 50 - 280 - - - - 8 - - 4 - rgb(235,109,109) - square - 100 - 100 - 212 - 280 - - - - 9 - - 4 - rgb(235,109,109) - square - 100 - 100 - 698 - 280 - - - - 10 - - 4 - rgb(235,109,109) - square - 100 - 100 - 860 - 280 - - - - 11 - - 4 - rgb(78,210,190) - round - 210 - 210 - 400 - 230 - - - - - - Patio - rgb(130, 233, 171) - - - - - - - 1 - - 2 - rgb(53,211,116) - square - 130 - 85 - 100 - 50 - - - - 2 - - 2 - rgb(53,211,116) - square - 130 - 85 - 100 - 166 - - - - 3 - - 2 - rgb(53,211,116) - square - 130 - 85 - 100 - 283 - - - - 4 - - 2 - rgb(53,211,116) - square - 130 - 85 - 100 - 400 - - - - - - 5 - - 2 - rgb(53,211,116) - square - 130 - 85 - 800 - 50 - - - - 6 - - 2 - rgb(53,211,116) - square - 130 - 85 - 800 - 166 - - - - 7 - - 2 - rgb(53,211,116) - square - 130 - 85 - 800 - 283 - - - - 8 - - 2 - rgb(53,211,116) - square - 130 - 85 - 800 - 400 - - - - - - 9 - - 4 - rgb(235,191,109) - square - 130 - 120 - 330 - 100 - - - - 9 - - 4 - rgb(235,191,109) - square - 130 - 120 - 330 - 100 - - - - 10 - - 4 - rgb(235,191,109) - square - 130 - 120 - 560 - 100 - - - - 11 - - 4 - rgb(235,191,109) - square - 130 - 120 - 330 - 315 - - - - 12 - - 4 - rgb(235,191,109) - square - 130 - 120 - 560 - 315 - - diff --git a/addons/pos_restaurant/data/pos_restaurant_onboarding_main_config.xml b/addons/pos_restaurant/data/pos_restaurant_onboarding_main_config.xml new file mode 100644 index 00000000000..10ad31766c5 --- /dev/null +++ b/addons/pos_restaurant/data/pos_restaurant_onboarding_main_config.xml @@ -0,0 +1,488 @@ + + + + Restaurant + True + + True + + + + + + + + + + + + + + + + + + + + + + ClosedDemo/0005 + paid + 14.0 + 0.0 + 14.0 + 0.0 + Order 00000-003-1001 + + + + Closed Orderline 3.1.1 + + 7.0 + 7.0 + 7.0 + + Margherita + + + + Closed Orderline 3.1.2 + + 7.0 + 7.0 + 7.0 + + Funghi + + + + + + 14.0 + + + + + + ClosedDemo/0006 + paid + 7.0 + 0.0 + 7.0 + 0.0 + Order 00000-003-1002 + + + + Closed Orderline 3.2.1 + + 7.0 + 7.0 + 7.0 + + Vegetarian + + + + + + 7.0 + + + + + + + + + + + + + + + + + ClosedDemo/0007 + paid + 6.7 + 0.0 + 6.7 + 0.0 + Order 00000-004-1001 + + + + Closed Orderline 4.1.1 + + 2.20 + 2.20 + 2.20 + + Water + + + + Closed Orderline 4.1.2 + + 4.5 + 4.5 + 4.5 + + Pasta Bolognese + + + + + + 6.7 + + + + + + ClosedDemo/0008 + paid + 28.0 + 0.0 + 28.0 + 0.0 + Order 00000-004-1002 + + + + Closed Orderline 4.2.1 + + 28.0 + 28.0 + 7.0 + 4 + + Cheese Burger + + + + + + 28.0 + + + + + + + Main Floor + rgb(136,137,242) + + + + + 1 + + 4 + rgb(53,211,116) + square + 100 + 100 + 50 + 50 + + + + 2 + + 4 + rgb(53,211,116) + square + 100 + 100 + 212 + 50 + + + + 3 + + 4 + rgb(53,211,116) + square + 100 + 100 + 374 + 50 + + + + 4 + + 4 + rgb(53,211,116) + square + 100 + 100 + 536 + 50 + + + + 5 + + 4 + rgb(53,211,116) + square + 100 + 100 + 698 + 50 + + + + 6 + + 4 + rgb(53,211,116) + square + 100 + 100 + 860 + 50 + + + + 7 + + 4 + rgb(235,109,109) + square + 100 + 100 + 50 + 280 + + + + 8 + + 4 + rgb(235,109,109) + square + 100 + 100 + 212 + 280 + + + + 9 + + 4 + rgb(235,109,109) + square + 100 + 100 + 698 + 280 + + + + 10 + + 4 + rgb(235,109,109) + square + 100 + 100 + 860 + 280 + + + + 11 + + 4 + rgb(78,210,190) + round + 210 + 210 + 400 + 230 + + + + + + Patio + rgb(130, 233, 171) + + + + + + + 1 + + 2 + rgb(53,211,116) + square + 130 + 85 + 100 + 50 + + + + 2 + + 2 + rgb(53,211,116) + square + 130 + 85 + 100 + 166 + + + + 3 + + 2 + rgb(53,211,116) + square + 130 + 85 + 100 + 283 + + + + 4 + + 2 + rgb(53,211,116) + square + 130 + 85 + 100 + 400 + + + + + + 5 + + 2 + rgb(53,211,116) + square + 130 + 85 + 800 + 50 + + + + 6 + + 2 + rgb(53,211,116) + square + 130 + 85 + 800 + 166 + + + + 7 + + 2 + rgb(53,211,116) + square + 130 + 85 + 800 + 283 + + + + 8 + + 2 + rgb(53,211,116) + square + 130 + 85 + 800 + 400 + + + + + + 9 + + 4 + rgb(235,191,109) + square + 130 + 120 + 330 + 100 + + + + 9 + + 4 + rgb(235,191,109) + square + 130 + 120 + 330 + 100 + + + + 10 + + 4 + rgb(235,191,109) + square + 130 + 120 + 560 + 100 + + + + 11 + + 4 + rgb(235,191,109) + square + 130 + 120 + 330 + 315 + + + + 12 + + 4 + rgb(235,191,109) + square + 130 + 120 + 560 + 315 + + diff --git a/addons/pos_restaurant/models/pos_session.py b/addons/pos_restaurant/models/pos_session.py index ba31451cc18..2c825bdabf0 100644 --- a/addons/pos_restaurant/models/pos_session.py +++ b/addons/pos_restaurant/models/pos_session.py @@ -67,21 +67,24 @@ class PosSession(models.Model): def _load_onboarding_data(self): super()._load_onboarding_data() convert.convert_file(self.env, 'pos_restaurant', 'data/pos_restaurant_onboarding.xml', None, mode='init', kind='data') - restaurant_config = self.env.ref('pos_restaurant.pos_config_main_restaurant') - if len(restaurant_config.session_ids.filtered(lambda s: s.state == 'opened')) == 0: - self.env['pos.session'].create({ - 'config_id': restaurant_config.id, - 'user_id': self.env.ref('base.user_admin').id, - }) - convert.convert_file(self.env, 'pos_restaurant', 'data/pos_restaurant_onboarding_open_session.xml', None, mode='init', kind='data') + restaurant_config = self.env.ref('pos_restaurant.pos_config_main_restaurant', raise_if_not_found=False) + if restaurant_config: + convert.convert_file(self.env, 'pos_restaurant', 'data/pos_restaurant_onboarding_main_config.xml', None, mode='init', kind='data') + if len(restaurant_config.session_ids.filtered(lambda s: s.state == 'opened')) == 0: + self.env['pos.session'].create({ + 'config_id': restaurant_config.id, + 'user_id': self.env.ref('base.user_admin').id, + }) + convert.convert_file(self.env, 'pos_restaurant', 'data/pos_restaurant_onboarding_open_session.xml', None, mode='init', kind='data') def _after_load_onboarding_data(self): super()._after_load_onboarding_data() - configs = self.config_id.filtered('module_pos_restaurant').union(self.env.ref('pos_restaurant.pos_config_main_restaurant', raise_if_not_found=False)) - configs.with_context(bypass_categories_forbidden_change=True).write({ - 'limit_categories': True, - 'iface_available_categ_ids': [Command.link(self.env.ref('pos_restaurant.food').id), Command.link(self.env.ref('pos_restaurant.drinks').id)] - }) + configs = self.config_id.filtered('module_pos_restaurant') + if configs: + configs.with_context(bypass_categories_forbidden_change=True).write({ + 'limit_categories': True, + 'iface_available_categ_ids': [Command.link(self.env.ref('pos_restaurant.food').id), Command.link(self.env.ref('pos_restaurant.drinks').id)] + }) @api.model def _set_last_order_preparation_change(self, order_ids):