diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index 8202d3e3a0a..00650716e7d 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -391,7 +391,7 @@ class ProcurementGroup(models.Model): actions_to_run = defaultdict(list) procurement_errors = [] for procurement in procurements: - procurement.values.setdefault('company_id', self.env.company) + procurement.values.setdefault('company_id', procurement.location_id.company_id) procurement.values.setdefault('priority', '0') procurement.values.setdefault('date_planned', fields.Datetime.now()) if ( @@ -461,7 +461,14 @@ class ProcurementGroup(models.Model): @api.model def _get_rule_domain(self, location, values): - return [('location_id', '=', location.id), ('action', '!=', 'push')] + domain = ['&', ('location_id', '=', location.id), ('action', '!=', 'push')] + # In case the method is called by the superuser, we need to restrict the rules to the + # ones of the company. This is not useful as a regular user since there is a record + # rule to filter out the rules based on the company. + if self.env.su and values.get('company_id'): + domain_company = ['|', ('company_id', '=', False), ('company_id', 'child_of', values['company_id'].ids)] + domain = expression.AND([domain, domain_company]) + return domain def _merge_domain(self, values, rule, group_id): return [