From 5e55758d66e72c8b36fbfe42f94caa157e78f6a6 Mon Sep 17 00:00:00 2001 From: rhe-odoo Date: Thu, 24 Nov 2022 15:36:41 +0000 Subject: [PATCH] [IMP] point_of_sale: load default demo data When loading the pos without demo data, before we had a wizard that allowed the user to load data before the pos starts. Now, we let the user go to the frontend without preloading products and categories in the database. In the front end, when no products and categories are loaded, we let the user press buttons to load the default products and categories. The user can also be redirected to the back end to add new products. closes odoo/odoo#117823 Task-id: 3054477 Related: odoo/upgrade#4523 Signed-off-by: Samuel Degueldre --- addons/point_of_sale/__manifest__.py | 1 - .../point_of_sale/data/point_of_sale_data.xml | 6 +++++ addons/point_of_sale/models/pos_config.py | 14 ----------- addons/point_of_sale/models/pos_session.py | 8 ++++++- .../security/ir.model.access.csv | 1 - .../Screens/ProductScreen/ProductsWidget.js | 23 ++++++++++++++++++- addons/point_of_sale/static/src/scss/pos.scss | 17 ++++++++++++++ .../Screens/ProductScreen/ProductsWidget.xml | 7 ++++++ addons/point_of_sale/wizard/__init__.py | 1 - .../pos_session_check_product_wizard.py | 18 --------------- .../pos_session_check_product_wizard.xml | 19 --------------- 11 files changed, 59 insertions(+), 56 deletions(-) delete mode 100644 addons/point_of_sale/wizard/pos_session_check_product_wizard.py delete mode 100644 addons/point_of_sale/wizard/pos_session_check_product_wizard.xml diff --git a/addons/point_of_sale/__manifest__.py b/addons/point_of_sale/__manifest__.py index 1315c4c462d..ed659958c0c 100644 --- a/addons/point_of_sale/__manifest__.py +++ b/addons/point_of_sale/__manifest__.py @@ -16,7 +16,6 @@ 'wizard/pos_details.xml', 'wizard/pos_payment.xml', 'wizard/pos_close_session_wizard.xml', - 'wizard/pos_session_check_product_wizard.xml', 'wizard/pos_daily_sales_reports.xml', 'views/pos_assets_index.xml', 'views/pos_assets_qunit.xml', diff --git a/addons/point_of_sale/data/point_of_sale_data.xml b/addons/point_of_sale/data/point_of_sale_data.xml index a0db0e67330..245e8e316b3 100644 --- a/addons/point_of_sale/data/point_of_sale_data.xml +++ b/addons/point_of_sale/data/point_of_sale_data.xml @@ -8,6 +8,12 @@ + + Load Product Menu + reload + + + diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 24dc0967403..9374d3f0274 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -527,20 +527,6 @@ class PosConfig(models.Model): self._check_before_creating_new_session() self._validate_fields(self._fields) - # check if there's any product for this PoS - domain = [('available_in_pos', '=', True)] - if self.limit_categories and self.iface_available_categ_ids: - domain.append(('pos_categ_id', 'in', self.iface_available_categ_ids.ids)) - if not self.env['product.product'].search(domain): - return { - 'name': _("There is no product linked to your PoS"), - 'type': 'ir.actions.act_window', - 'view_mode': 'form', - 'res_model': 'pos.session.check_product_wizard', - 'target': 'new', - 'context': {'config_id': self.id} - } - return self._action_to_open_ui() def open_existing_session_cb(self): diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 0136357e4cb..47a63f965de 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -8,7 +8,7 @@ from markupsafe import Markup, escape from odoo import api, fields, models, _, Command from odoo.exceptions import AccessError, UserError, ValidationError -from odoo.tools import float_is_zero, float_compare +from odoo.tools import float_is_zero, float_compare, convert from odoo.osv.expression import AND, OR from odoo.service.common import exp_version @@ -2125,6 +2125,12 @@ class PosSession(models.Model): return fps + def load_product_frontend(self): + convert.convert_file(self.env, 'point_of_sale', 'data/point_of_sale_onboarding.xml', None, mode='init', + kind='data') + return self.get_onboarding_data() + + class ProcurementGroup(models.Model): _inherit = 'procurement.group' diff --git a/addons/point_of_sale/security/ir.model.access.csv b/addons/point_of_sale/security/ir.model.access.csv index 78d331cc471..5716eababfa 100644 --- a/addons/point_of_sale/security/ir.model.access.csv +++ b/addons/point_of_sale/security/ir.model.access.csv @@ -52,5 +52,4 @@ access_pos_make_payment,access.pos.make.payment,model_pos_make_payment,point_of_ access_pos_close_session_wizard,access.pos.close.session.wizard,model_pos_close_session_wizard,point_of_sale.group_pos_user,1,1,1,0 access_account_cash_rounding_pos_user,account.cash.rounding pos_user,account.model_account_cash_rounding,group_pos_user,1,0,0,0 access_pos_bill,pos.bill pos_user,model_pos_bill,group_pos_user,1,1,1,1 -access_pos_session_check_product_wizard,access.pos.session.check.product.wizard,model_pos_session_check_product_wizard,group_pos_user,1,1,1,0 access_pos_daily_sales_reports_wizard,access.pos.daily.sales.reports.wizard,model_pos_daily_sales_reports_wizard,group_pos_manager,1,1,1,0 diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js index 047dc2e8923..a2257e9f470 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js @@ -21,12 +21,19 @@ export class ProductsWidget extends Component { */ setup() { super.setup(); - this.state = useState({ previousSearchWord: "", currentOffset: 0 }); + this.state = useState({ + previousSearchWord: "", + currentOffset: 0, + showReloadMessage: false, + }); this.pos = usePos(); this.popup = useService("popup"); this.notification = useService("pos_notification"); this.orm = useService("orm"); } + get hasProducts() { + return Object.keys(this.pos.globalState.db.product_by_id).length > 0; + } get selectedCategoryId() { return this.env.pos.selectedCategoryId; } @@ -161,4 +168,18 @@ export class ProductsWidget extends Component { } } } + async loadDemoDataProducts() { + const { products, categories } = await this.orm.call( + "pos.session", + "load_product_frontend", + [this.pos.globalState.pos_session.id] + ); + this.pos.globalState.db.add_categories(categories); + this.pos.globalState._loadProductProduct(products); + } + + createNewProducts() { + window.open("/web#action=point_of_sale.action_client_product_menu", "_blank"); + this.state.showReloadMessage = true; + } } diff --git a/addons/point_of_sale/static/src/scss/pos.scss b/addons/point_of_sale/static/src/scss/pos.scss index fbcf0f12857..9570a513359 100644 --- a/addons/point_of_sale/static/src/scss/pos.scss +++ b/addons/point_of_sale/static/src/scss/pos.scss @@ -3600,6 +3600,23 @@ td { background: rgba(104,69,95, 0.7); } +.pos .no-results-message .button-no-demo { + margin: 3px; + width: 180px; + padding: 10px 0; + cursor: pointer; + font-size: large; +} + +.info-load-product-message { + background: lightblue; + color: #017e84; + padding: 8px; + width: fit-content; + display: block; + margin : 3px auto 0 auto; +} + @media screen and (max-width: 768px) { .pos .search-bar-container.sb-product { max-width: none; diff --git a/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml b/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml index 152484eca82..8328a336065 100644 --- a/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml +++ b/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml @@ -26,6 +26,13 @@

There are no products in this category.

+
+ + +
+ Please reload this page once products have been created +
+
Search more
diff --git a/addons/point_of_sale/wizard/__init__.py b/addons/point_of_sale/wizard/__init__.py index 50fd5ba5aee..292bbeda7da 100644 --- a/addons/point_of_sale/wizard/__init__.py +++ b/addons/point_of_sale/wizard/__init__.py @@ -4,5 +4,4 @@ from . import pos_details from . import pos_payment from . import pos_close_session_wizard -from . import pos_session_check_product_wizard from . import pos_daily_sales_reports diff --git a/addons/point_of_sale/wizard/pos_session_check_product_wizard.py b/addons/point_of_sale/wizard/pos_session_check_product_wizard.py deleted file mode 100644 index 82caa30aeb5..00000000000 --- a/addons/point_of_sale/wizard/pos_session_check_product_wizard.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import models -from odoo.tools import convert - - -class PosSessionCheckProductWizard(models.TransientModel): - _name = 'pos.session.check_product_wizard' - _description = 'Verify if there are any products for the PoS' - - def load_demo_products(self): - convert.convert_file(self.env, 'point_of_sale', 'data/point_of_sale_onboarding.xml', None, mode='init', kind='data') - return self.open_ui() - - def open_ui(self): - config = self.env['pos.config'].browse(self.env.context.get('config_id')) - return config._action_to_open_ui() diff --git a/addons/point_of_sale/wizard/pos_session_check_product_wizard.xml b/addons/point_of_sale/wizard/pos_session_check_product_wizard.xml deleted file mode 100644 index b182d9fa0d1..00000000000 --- a/addons/point_of_sale/wizard/pos_session_check_product_wizard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - pos.session.check.product.wizard.form - pos.session.check_product_wizard - -
-

- You can add some from the Products menu, or linked any existing by flagging them as "Available in PoS". - Or you can add demo data for testing purpose. Please mind that this is an irreversible action. -

- -
-
-
-