From aed779b0adcfd6863f1392c57c2b6c72e07c9422 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 8 Mar 2016 16:44:42 +0100 Subject: [PATCH] [IMP] product: Pricelist creation on Company creation if new currency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When working in multi-company, and each company using its own currency, a pricelist for the second company should be created. For instance, our default company is in Belgium -> € and there is a default pricelist in €. Then you create a second company in US -> $. It is impossible for the us company to sell in its own country because there is no $ pricelist. When creating the second company, if the currency is different than the first company one, the default pricelist in the currency should be created. In all the cases, a ir.property should be created to link the 'property_product_pricelist' on the 'res.partner' to the new company. Furthemore, a small usability improvement. The currency should be activated before creating the company. So we change the label to indicate that behavior and make the action in target new to prevent the creation flow to be broken --- addons/product/__init__.py | 1 + addons/product/res_company.py | 27 +++++++++++++++++++ openerp/addons/base/res/res_currency_view.xml | 12 ++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 addons/product/res_company.py diff --git a/addons/product/__init__.py b/addons/product/__init__.py index dc12a13f0dc..6dcf856c740 100644 --- a/addons/product/__init__.py +++ b/addons/product/__init__.py @@ -3,6 +3,7 @@ import res_config import product import pricelist +import res_company import report import partner import wizard diff --git a/addons/product/res_company.py b/addons/product/res_company.py new file mode 100644 index 00000000000..49d02111519 --- /dev/null +++ b/addons/product/res_company.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, _ + + +class ResCompany(models.Model): + _inherit = "res.company" + + @api.model + def create(self, vals): + new_company = super(ResCompany, self).create(vals) + ProductPricelist = self.env['product.pricelist'] + pricelist = ProductPricelist.search([('currency_id', '=', new_company.currency_id.id), ('company_id', '=', False)], limit=1) + if not pricelist: + pricelist = ProductPricelist.create({ + 'name': new_company.name, + 'currency_id': new_company.currency_id.id, + }) + field_id = self.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_product_pricelist')]) + self.env['ir.property'].create({ + 'name': 'property_product_pricelist', + 'company_id': new_company.id, + 'value_reference': 'product.pricelist,%s' % pricelist.id, + 'fields_id': field_id.id + }) + return new_company diff --git a/openerp/addons/base/res/res_currency_view.xml b/openerp/addons/base/res/res_currency_view.xml index f31343b7e6f..0d35818912e 100644 --- a/openerp/addons/base/res/res_currency_view.xml +++ b/openerp/addons/base/res/res_currency_view.xml @@ -107,6 +107,16 @@ + + Currencies + res.currency + form + tree,form + + {'active_test': False} + new + + res.company.form @@ -116,7 +126,7 @@