From 0728b447a6205528bfa20690ef208a604f25091a Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Fri, 13 Oct 2023 12:43:30 +0200 Subject: [PATCH] [FIX] loyalty: default product for reward in multi company Steps to reproduce: ------------------- - being in a multi-company environment; - have one product made that is first in alphabetical order of "Internal Reference" throughout the database (e.g. [AAA]); - make this product specific to one of the companies (set the "Company" field on the product template) - go into a different company within the database (not the one set on this product); - create a new discount & loyalty record, and set the "Program Type" to "Discount Code". Issue: ------ An access rights error occurs. Cause: ------ When creating a `promo_code` program, we use the first product that can be sold in the default reward values. Solution: --------- Take into account the company in the domain that retrieves the default product. opw-3538516 closes odoo/odoo#139008 X-original-commit: d80c28c78bf3237e2526a6370f9c6c0b0f8dc232 Signed-off-by: Thomas Lefebvre (thle) --- addons/loyalty/models/loyalty_program.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/loyalty/models/loyalty_program.py b/addons/loyalty/models/loyalty_program.py index eb9f831296f..848a41df1c9 100644 --- a/addons/loyalty/models/loyalty_program.py +++ b/addons/loyalty/models/loyalty_program.py @@ -216,7 +216,7 @@ class LoyaltyProgram(models.Model): def _program_type_default_values(self): # All values to change when program_type changes # NOTE: any field used in `rule_ids`, `reward_ids` and `communication_plan_ids` MUST be present in the kanban view for it to work properly. - first_sale_product = self.env['product.product'].search([('sale_ok', '=', True)], limit=1) + first_sale_product = self.env['product.product'].search([('company_id', 'in', [False, self.env.company.id]), ('sale_ok', '=', True)], limit=1) return { 'coupons': { 'applies_on': 'current',