Skip to content
Snippets Groups Projects
Commit 51b7960f authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] stock: routes in multi-company


- Create companies A & B
- Create a Dropship route for B
- Create a product P with route 'Dropship'
- Set the website under company A
- As a portal user, buy the product P on the website
- Do the payment

The SO is confirmed but the Dropship route for B is used despite the
fact that the website is under company A.

This happens because `_search_rule` is called as superuser: therefore,
routes from all companies are retrieved.

To prevent this, we add the company in the domain.

opw-2349094

closes odoo/odoo#60445

X-original-commit: 21559334b6bc2e5225df033a5064c7d622abf246
Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 6d4da47f
No related branches found
No related tags found
No related merge requests found
......@@ -368,7 +368,7 @@ class ProcurementGroup(models.Model):
actions_to_run = defaultdict(list)
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', '1')
procurement.values.setdefault('date_planned', fields.Datetime.now())
if (
......@@ -437,7 +437,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 [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment