From aaaaddd4f529c0df73e7786ba926bcc831a5fae7 Mon Sep 17 00:00:00 2001 From: "Adrien Guilliams (adgu)" Date: Tue, 19 Dec 2023 15:25:10 +0100 Subject: [PATCH] [FIX] point_of_sale: fix pos created when download pos restaurant Prior to this commit, when creating a database with pos_restaurant, a classic point_of_sale was created with the name Shop but without all the settings of the previous Shop that was archived by the installation of pos_restaurant. We do not want this so we remove this behaviour. We also fix another bug. The bug is that, if a starting pos config is archived and that the user wants to download the demo data from the frontend after that, the server will raise an error. This is because the pos config is archived and the pos session will try to create orders and use payment methods from the archived pos config. We also fix this in this commit by not taking into account the point_of_sale_onboarding_main_config.xml file if the pos config is inactive. closes odoo/odoo#146833 Signed-off-by: Joseph Caburnay (jcb) --- addons/point_of_sale/models/pos_config.py | 8 ++++++-- addons/point_of_sale/models/pos_session.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 29607cf982b..5541ac64535 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -6,7 +6,7 @@ from uuid import uuid4 import pytz from odoo import api, fields, models, _, Command -from odoo.osv.expression import OR +from odoo.osv.expression import OR, AND from odoo.exceptions import ValidationError, UserError @@ -612,7 +612,11 @@ class PosConfig(models.Model): if not companies: companies = self.env['res.company'].search([]) for company in companies.filtered('chart_template'): - pos_configs = self.search([('company_id', '=', company.id), ('module_pos_restaurant', '=', False)]) + domain = AND([ + [('company_id', '=', company.id), ('module_pos_restaurant', '=', False)], + OR([[('active', '=', True)], [('active', '=', False)]]), + ]) + pos_configs = self.search(domain) if not pos_configs: self = self.with_company(company) pos_configs = self.env['pos.config'].create({ diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 0c9f6979129..d68f69a6523 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -2241,7 +2241,7 @@ class PosSession(models.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', raise_if_not_found=False) - if shop_config: + if shop_config and shop_config.active: 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({