From 47c60db4a06174baea43c0fda0dbf6c262a1676d Mon Sep 17 00:00:00 2001 From: norlinhenrik Date: Sun, 8 Jan 2017 10:31:09 +0100 Subject: [PATCH] [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 --- addons/product/models/res_partner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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},