Skip to content

Commit 807751a

Browse files
committed
[FIX] base: fix mixing currency in company/pricelist
A company should have at least a pricelist having the same currency, that's common sense. This was causing problems in tests on 10.0-nightly, where the main pricelist was created in EUR, then the localization module was setting the right currency on the company without any reflection on the pricelist. To avoid this problem, when we write the currency on a company, we reflect that change on the main pricelist if it's the only company in the system. Otherwise as we can't decide which pricelist modify, we just create a new one, which should be ok.
1 parent bf8b359 commit 807751a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

addons/product/models/res_company.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,30 @@ def create(self, vals):
2525
'fields_id': field.id
2626
})
2727
return new_company
28+
29+
@api.multi
30+
def write(self, values):
31+
# When we modify the currency of the company, we reflect the change on the list0 pricelist, if
32+
# that pricelist is not used by another company. Otherwise, we create a new pricelist for the
33+
# given currency.
34+
ProductPricelist = self.env['product.pricelist']
35+
currency_id = values.get('currency_id')
36+
main_pricelist = self.env.ref('product.list0', False)
37+
if currency_id and main_pricelist:
38+
nb_companies = self.search_count([])
39+
for company in self:
40+
if main_pricelist.company_id == company or (main_pricelist.company_id.id is False and nb_companies == 1):
41+
main_pricelist.write({'currency_id': currency_id})
42+
else:
43+
pricelist = ProductPricelist.create({
44+
'name': company.name,
45+
'currency_id': currency_id,
46+
})
47+
field = self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_product_pricelist')])
48+
self.env['ir.property'].create({
49+
'name': 'property_product_pricelist',
50+
'company_id': company.id,
51+
'value_reference': 'product.pricelist,%s' % pricelist.id,
52+
'fields_id': field.id
53+
})
54+
return super(ResCompany, self).write(values)

0 commit comments

Comments
 (0)