summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Snauwaert <csn@openerp.com>2017-03-09 13:16:46 +0100
committerCedric Snauwaert <csn@openerp.com>2017-03-09 13:16:56 +0100
commit787e1037cdca48fe361ae65d790056a3d57e6b67 (patch)
treebfc7e0893d4d8e755bfb4058c505260f73735432
parentd5d24a2971dc684fed6a6219c569353917c42a14 (diff)
[FIX] product: fix default pricelist creation
Correct several issues with the automatic pricelist creation: - multiple creation of same pricelists because company not set on new pricelist - avoid creating pricelist if currency did not changed or if we already have a pricelist with the same currency - improve name of new pricelist
-rw-r--r--addons/product/models/res_company.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/addons/product/models/res_company.py b/addons/product/models/res_company.py
index a2147257a0f..3d8d0dcfc70 100644
--- a/addons/product/models/res_company.py
+++ b/addons/product/models/res_company.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import api, models
+from odoo import api, models, _
class ResCompany(models.Model):
@@ -37,12 +37,27 @@ class ResCompany(models.Model):
if currency_id and main_pricelist:
nb_companies = self.search_count([])
for company in self:
- if main_pricelist.company_id == company or (main_pricelist.company_id.id is False and nb_companies == 1):
+ existing_pricelist = ProductPricelist.search(
+ [('company_id', 'in', (False, company.id)),
+ ('currency_id', '=', currency_id)])
+ if existing_pricelist:
+ continue
+ if currency_id == company.currency_id.id:
+ continue
+ currency_match = main_pricelist.currency_id == company.currency_id
+ company_match = (main_pricelist.company_id == company or
+ (main_pricelist.company_id.id is False and nb_companies == 1))
+ if currency_match and company_match:
main_pricelist.write({'currency_id': currency_id})
else:
+ params = {
+ 'currency': self.env['res.currency'].browse(currency_id).name,
+ 'company': company.name
+ }
pricelist = ProductPricelist.create({
- 'name': company.name,
+ 'name': _("Default %(currency)s pricelist for %(company)s") % params,
'currency_id': currency_id,
+ 'company_id': company.id,
})
field = self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_product_pricelist')])
self.env['ir.property'].create({