[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
This commit is contained in:
norlinhenrik
2017-01-16 11:55:07 +01:00
committed by Martin Trigaux
parent b74e02b847
commit 47c60db4a0
+2 -1
View File
@@ -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},