commit
5c1672ba27
|
@ -19,7 +19,5 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import multi_company
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -36,8 +36,7 @@
|
|||
],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'security/ir.model.access.csv',
|
||||
'multi_company_view.xml',
|
||||
#'security/ir.model.access.csv',
|
||||
],
|
||||
'demo_xml': [
|
||||
'multi_company_demo.xml'
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
"""
|
||||
The multicompany module add management to easily custom value by default
|
||||
for each company
|
||||
"""
|
||||
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
from tools.translate import _
|
||||
|
||||
class multi_company_default(osv.osv):
|
||||
"""
|
||||
Manage multi company default value
|
||||
"""
|
||||
_name = 'multi_company.default'
|
||||
_description = 'Default multi company'
|
||||
_order = 'company_id,sequence,id'
|
||||
|
||||
_columns = {
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'name': fields.char('Name', size=32, required=True, help='Name it to easily find a record'),
|
||||
'company_id': fields.many2one('res.company', 'Main Company', required=True,
|
||||
help='Company where the user is connected'),
|
||||
'company_dest_id': fields.many2one('res.company', 'Default Company', required=True,
|
||||
help='Company to store the current record'),
|
||||
'object_id': fields.many2one('ir.model', 'Object', required=True,
|
||||
help='Object affect by this rules'),
|
||||
'expression': fields.char('Expression', size=32, required=True,
|
||||
help='Expression, must be True to match'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'expression': lambda *a: 'True',
|
||||
'sequence': lambda *a: 100,
|
||||
}
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
"""
|
||||
Add (copy) in the name when duplicate record
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
if not default:
|
||||
default = {}
|
||||
company = self.browse(cr, uid, id, context=context)
|
||||
default = default.copy()
|
||||
default['name'] = company.name + _(' (copy)')
|
||||
return super(multi_company_default, self).copy(cr, uid, id, default, context=context)
|
||||
|
||||
multi_company_default()
|
||||
|
||||
class res_company(osv.osv):
|
||||
"""
|
||||
Change method to retrieve the company by default
|
||||
"""
|
||||
_inherit = 'res.company'
|
||||
|
||||
def _company_default_get(self, cr, uid, object=False, context=None):
|
||||
"""
|
||||
Check if the object for this company have a default value
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
proxy = self.pool.get('multi_company.default')
|
||||
ids = proxy.search(cr, uid, [('object_id.model', '=', object)])
|
||||
for rule in proxy.browse(cr, uid, ids, context):
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
if eval(rule.expression, {'context': context, 'user': user}):
|
||||
return rule.company_dest_id.id
|
||||
return super(res_company, self)._company_default_get(cr, uid, object, context)
|
||||
|
||||
res_company()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,74 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_inventory_tree" model="ir.ui.view">
|
||||
<field name="name">multi_company.default.tree</field>
|
||||
<field name="model">multi_company.default</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="8"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Multi Company">
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="object_id"/>
|
||||
<field name="expression" />
|
||||
<field name="sequence"/>
|
||||
<field name="company_dest_id"/>
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_inventory_form" model="ir.ui.view">
|
||||
<field name="name">multi_company.default.form</field>
|
||||
<field name="model">multi_company.default</field>
|
||||
<field name="type">form</field>
|
||||
<field name="priority" eval="8"/>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Multi Company">
|
||||
<group col="6" colspan="4">
|
||||
<field name="name" colspan="6"/>
|
||||
<separator string="Matching" colspan="6"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="object_id"/>
|
||||
<field name="company_dest_id"/>
|
||||
<separator string="Condition" colspan="6"/>
|
||||
<field name="expression" colspan="4"/>
|
||||
<field name="sequence"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_inventory_search" model="ir.ui.view">
|
||||
<field name="name">multi_company.default.search</field>
|
||||
<field name="model">multi_company.default</field>
|
||||
<field name="type">search</field>
|
||||
<field name="priority" eval="8"/>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Multi Company">
|
||||
<field name="name" select="1"/>
|
||||
<field name="company_id" select="1" widget="selection"/>
|
||||
<field name="company_dest_id" select="1" widget="selection"/>
|
||||
<field name="object_id" select="1"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_inventory_form" model="ir.actions.act_window">
|
||||
<field name="name">Default Company per Object</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">multi_company.default</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="search_view_id" ref="view_inventory_search"/>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_custom_multicompany"
|
||||
name="Multi company"
|
||||
parent="base.menu_custom"
|
||||
sequence="50"/>
|
||||
|
||||
<menuitem id="menu_action_inventory_form"
|
||||
action="action_inventory_form"
|
||||
parent="menu_custom_multicompany"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,2 +1 @@
|
|||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_multi_company_default user","multi_company_default User","multi_company.model_multi_company_default","base.group_user",1,0,0,0
|
||||
|
|
|
Loading…
Reference in New Issue