From 430f4904ed47778b4c45c30befaef467cbdfce5b Mon Sep 17 00:00:00 2001 From: "Adrien Guilliams (adgu)" Date: Tue, 14 Nov 2023 11:35:51 +0100 Subject: [PATCH] [IMP] point_of_sale, pos_discount: move discount data to pos_discount Prior to this commit, the discount product was created at the installation of the point_of_sale module which does not make sense as this product is only used in the pos_discount module. We change this in this commit to also prevent the discount product to be shown in the frontend of the PoS when the user does not have the pos_discount module installed and abling him to download demo data on the flight if he does not have other products available. closes odoo/odoo#142831 Signed-off-by: Joseph Caburnay (jcb) --- addons/l10n_in_pos/data/product_demo.xml | 4 ---- .../point_of_sale/data/point_of_sale_data.xml | 14 -------------- addons/point_of_sale/tests/test_frontend.py | 12 +++--------- addons/pos_discount/__manifest__.py | 1 + .../pos_discount/data/pos_discount_data.xml | 19 +++++++++++++++++++ addons/pos_discount/models/pos_config.py | 4 ++-- .../models/res_config_settings.py | 2 +- 7 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 addons/pos_discount/data/pos_discount_data.xml diff --git a/addons/l10n_in_pos/data/product_demo.xml b/addons/l10n_in_pos/data/product_demo.xml index 38652a1fc32..b92ce78e479 100644 --- a/addons/l10n_in_pos/data/product_demo.xml +++ b/addons/l10n_in_pos/data/product_demo.xml @@ -20,10 +20,6 @@ 3921.90.99 Other plates, sheets film , foil and strip, of plastics - - 8443.32.90 - Other, capable of connecting to an automatic data processing machine or to a network - 9403 Other furniture and parts thereof. 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 ccedddc8836..54e93561756 100644 --- a/addons/point_of_sale/data/point_of_sale_data.xml +++ b/addons/point_of_sale/data/point_of_sale_data.xml @@ -36,20 +36,6 @@ Shop - - Discount - True - 0.00 - 0.00 - 0.00 - consu - - - - DISC - False - - True diff --git a/addons/point_of_sale/tests/test_frontend.py b/addons/point_of_sale/tests/test_frontend.py index ae71811854c..092f5159628 100644 --- a/addons/point_of_sale/tests/test_frontend.py +++ b/addons/point_of_sale/tests/test_frontend.py @@ -91,9 +91,8 @@ class TestPointOfSaleHttpCommon(AccountTestInvoicingHttpCommon): # Archive all existing product to avoid noise during the tours all_pos_product = env['product.product'].search([('available_in_pos', '=', True)]) - discount = env.ref('point_of_sale.product_product_consumable') cls.tip = env.ref('point_of_sale.product_product_tip') - (all_pos_product - discount - cls.tip)._write({'active': False}) + (all_pos_product - cls.tip)._write({'active': False}) # In DESKS categ: Desk Pad pos_categ_desks = env.ref('point_of_sale.pos_category_desks') @@ -334,13 +333,8 @@ class TestPointOfSaleHttpCommon(AccountTestInvoicingHttpCommon): 'applied_on': '0_product_variant', 'min_quantity': 1, 'product_id': cls.wall_shelf.id, - }), (0, 0, { - 'compute_price': 'fixed', - 'fixed_price': 2, - 'applied_on': '0_product_variant', - 'min_quantity': 2, - 'product_id': env.ref('point_of_sale.product_product_consumable').id, - })], + }), + ], }) env['product.pricelist'].create({ diff --git a/addons/pos_discount/__manifest__.py b/addons/pos_discount/__manifest__.py index aac04eaf626..33ed82994e1 100644 --- a/addons/pos_discount/__manifest__.py +++ b/addons/pos_discount/__manifest__.py @@ -16,6 +16,7 @@ discount to a customer. """, 'depends': ['point_of_sale'], 'data': [ + 'data/pos_discount_data.xml', 'views/res_config_settings_views.xml', 'views/pos_config_views.xml', ], diff --git a/addons/pos_discount/data/pos_discount_data.xml b/addons/pos_discount/data/pos_discount_data.xml new file mode 100644 index 00000000000..0e7453e7ef5 --- /dev/null +++ b/addons/pos_discount/data/pos_discount_data.xml @@ -0,0 +1,19 @@ + + + + + Discount + True + 0.00 + 0.00 + 0.00 + consu + + + + DISC + False + + + + diff --git a/addons/pos_discount/models/pos_config.py b/addons/pos_discount/models/pos_config.py index dbb90999138..cdaa371eb6d 100644 --- a/addons/pos_discount/models/pos_config.py +++ b/addons/pos_discount/models/pos_config.py @@ -22,7 +22,7 @@ class PosConfig(models.Model): .mapped('config_id') ) # Do not modify configs where an opened session exists. - product = self.env.ref("point_of_sale.product_product_consumable", raise_if_not_found=False) + product = self.env.ref("pos_discount.product_product_consumable", raise_if_not_found=False) for conf in (configs - open_configs): conf.discount_product_id = product if conf.module_pos_discount and product and (not product.company_id or product.company_id == conf.company_id) else False @@ -34,5 +34,5 @@ class PosConfig(models.Model): def _get_special_products(self): res = super()._get_special_products() - default_discount_product = self.env.ref('point_of_sale.product_product_consumable', raise_if_not_found=False) or self.env['product.product'] + default_discount_product = self.env.ref('pos_discount.product_product_consumable', raise_if_not_found=False) or self.env['product.product'] return res | self.env['pos.config'].search([]).mapped('discount_product_id') | default_discount_product diff --git a/addons/pos_discount/models/res_config_settings.py b/addons/pos_discount/models/res_config_settings.py index 6a1c6d75af2..35a260a45f3 100644 --- a/addons/pos_discount/models/res_config_settings.py +++ b/addons/pos_discount/models/res_config_settings.py @@ -13,7 +13,7 @@ class ResConfigSettings(models.TransientModel): @api.depends('company_id', 'pos_module_pos_discount', 'pos_config_id') def _compute_pos_discount_product_id(self): - default_product = self.env.ref("point_of_sale.product_product_consumable", raise_if_not_found=False) or self.env['product.product'] + default_product = self.env.ref("pos_discount.product_product_consumable", raise_if_not_found=False) or self.env['product.product'] for res_config in self: discount_product = res_config.pos_config_id.discount_product_id or default_product if res_config.pos_module_pos_discount and (not discount_product.company_id or discount_product.company_id == res_config.company_id):