From 84764e62f5d9c3b72c5f592738fc80deb2d12fbd Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Wed, 22 Nov 2023 09:44:46 +0100 Subject: [PATCH] [REV] point_of_sale, pos_discount: move discount data to pos_discount This reverts commit 430f4904ed47778b4c45c30befaef467cbdfce5b. This should not be done in stable, for 3 reasons: 1: There is no migration scripts, so every people that will migrate from previous version will have a second product discount created in their DB 2: Existing DB that will activate discount will have 2 products discounts 3: It breaks an industry module that depends of this data For those reasons, I'll revert this commit before it is deployed next week. To correctly do your changes, you just need to do it in master and create a migration script that will rename the xml_id. closes odoo/odoo#143104 Signed-off-by: Pierre Masereel (pim) --- 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, 30 insertions(+), 26 deletions(-) delete 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 b92ce78e479..38652a1fc32 100644 --- a/addons/l10n_in_pos/data/product_demo.xml +++ b/addons/l10n_in_pos/data/product_demo.xml @@ -20,6 +20,10 @@ 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 54e93561756..ccedddc8836 100644 --- a/addons/point_of_sale/data/point_of_sale_data.xml +++ b/addons/point_of_sale/data/point_of_sale_data.xml @@ -36,6 +36,20 @@ 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 092f5159628..ae71811854c 100644 --- a/addons/point_of_sale/tests/test_frontend.py +++ b/addons/point_of_sale/tests/test_frontend.py @@ -91,8 +91,9 @@ 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 - cls.tip)._write({'active': False}) + (all_pos_product - discount - cls.tip)._write({'active': False}) # In DESKS categ: Desk Pad pos_categ_desks = env.ref('point_of_sale.pos_category_desks') @@ -333,8 +334,13 @@ 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 33ed82994e1..aac04eaf626 100644 --- a/addons/pos_discount/__manifest__.py +++ b/addons/pos_discount/__manifest__.py @@ -16,7 +16,6 @@ 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 deleted file mode 100644 index 0e7453e7ef5..00000000000 --- a/addons/pos_discount/data/pos_discount_data.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - 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 cdaa371eb6d..dbb90999138 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("pos_discount.product_product_consumable", raise_if_not_found=False) + product = self.env.ref("point_of_sale.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('pos_discount.product_product_consumable', raise_if_not_found=False) or self.env['product.product'] + default_discount_product = self.env.ref('point_of_sale.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 35a260a45f3..6a1c6d75af2 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("pos_discount.product_product_consumable", raise_if_not_found=False) or self.env['product.product'] + default_product = self.env.ref("point_of_sale.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):