[IMP] product: Pricelist creation on Company creation if new currency

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
This commit is contained in:
Yannick Tivisse
2016-03-09 14:13:08 +01:00
parent 2432483e14
commit aed779b0ad
3 changed files with 39 additions and 1 deletions
+1
View File
@@ -3,6 +3,7 @@
import res_config
import product
import pricelist
import res_company
import report
import partner
import wizard
+27
View File
@@ -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
+11 -1
View File
@@ -107,6 +107,16 @@
<menuitem action="action_currency_form" id="menu_action_currency_form" parent="menu_localisation" sequence="3" groups="base.group_multi_currency"/>
<record id="action_currency_form_company" model="ir.actions.act_window">
<field name="name">Currencies</field>
<field name="res_model">res.currency</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="view_currency_search"/>
<field name="context">{'active_test': False}</field>
<field name="target">new</field>
</record>
<!-- We override the view res_company here because the action wasn't defined before -->
<record id="action_view_company_form_link_2_currencies" model="ir.ui.view">
<field name="name">res.company.form</field>
@@ -116,7 +126,7 @@
<xpath expr="//field[@id='company_currency']" position="after">
<label for="id"/>
<p class="text-muted">
Click <a type="action" name="%(base.action_currency_form)d">here</a> to activate a new currency.
Activate <a type="action" name="%(base.action_currency_form_company)d">here</a> a new currency before creating a new company.
</p>
</xpath>
</field>