summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornorlinhenrik <henrik.norl@gmail.com>2017-01-08 10:31:09 +0100
committerMartin Trigaux <mat@odoo.com>2017-01-16 11:55:07 +0100
commit47c60db4a06174baea43c0fda0dbf6c262a1676d (patch)
tree246140eec8e538ed2f8b7ff74e974f9b37b674f4
parentb74e02b847badc75bc16f85ae42713ba0ac42006 (diff)
[FIX] product: set the correct company in property
`set_multi` uses the company of the current user. As the property is created in sudo, the company of the admin may be different than the one of the current user. Before this commit, setting a different pricelist on a partner when logged in a different company than the admin, the change had no apparent effect (was creating a property for the admin's company). Set `force_company` in the context to always set the one on the current user. set_multi ignores if the same as the global rule to avoid bloating the table. Closes #14984
-rw-r--r--addons/product/models/res_partner.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/addons/product/models/res_partner.py b/addons/product/models/res_partner.py
index 8dc745eea1a..d307bd6ab09 100644
--- a/addons/product/models/res_partner.py
+++ b/addons/product/models/res_partner.py
@@ -31,7 +31,8 @@ class Partner(models.Model):
# update at each change country, and so erase old pricelist
if self.property_product_pricelist or (actual and default_for_country and default_for_country.id != actual.id):
- self.env['ir.property'].sudo().set_multi(
+ # keep the company of the current user before sudo
+ self.env['ir.property'].with_context(force_company=self.env.user.company_id.id).sudo().set_multi(
'property_product_pricelist',
self._name,
{self.id: self.property_product_pricelist or default_for_country.id},