diff --git a/addons/account/__terp__.py b/addons/account/__terp__.py index fc4c16319ff..bb73c2527c0 100644 --- a/addons/account/__terp__.py +++ b/addons/account/__terp__.py @@ -65,7 +65,6 @@ 'project/analytic_account_demo.xml', 'demo/account_minimal.xml', 'account_unit_test.xml', - 'demo/multi_company_demo.xml', ], 'installable': True, 'active': False, diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 451821c132d..cfbf14c68a2 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -422,7 +422,7 @@ class account_move_line(osv.osv): 'currency_id': _get_currency, 'journal_id': lambda self, cr, uid, c: c.get('journal_id', False), 'period_id': lambda self, cr, uid, c: c.get('period_id', False), - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.move.line', c) } _order = "date desc,id desc" _sql_constraints = [ diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 44d5257e38f..7c6dd6cf957 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -1078,6 +1078,7 @@ class account_invoice_line(osv.osv): 'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]), 'note': fields.text('Notes'), 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'), + 'company_id': fields.related('invoice_id','company_id',type='many2one',object='res.company',string='Company') } _defaults = { 'quantity': lambda *a: 1, diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 507135b70ee..1cc33b38a0d 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -270,7 +270,7 @@ class hr_timesheet_sheet(osv.osv): 'date_current' : lambda *a: time.strftime('%Y-%m-%d'), 'date_to' : _default_date_to, 'state': lambda *a: 'new', - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr_timesheet_sheet.sheet', c) } def _sheet_date(self, cr, uid, ids): diff --git a/addons/multi_company/__init__.py b/addons/multi_company/__init__.py new file mode 100644 index 00000000000..e96ecdf56e6 --- /dev/null +++ b/addons/multi_company/__init__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +import multi_company + + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/multi_company/__terp__.py b/addons/multi_company/__terp__.py new file mode 100644 index 00000000000..dac7349e7c4 --- /dev/null +++ b/addons/multi_company/__terp__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## + + +{ + 'name': 'Multi Company', + 'version': '1.0', + 'category': 'Custom', + 'description': " ", + 'author': 'Tiny', + 'depends': ['base'], + 'update_xml': [ + 'multi_company_view.xml', + ], + 'demo_xml': ['multi_company_demo.xml'], + 'installable': True, + 'active': True, + 'certificate': '', +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/multi_company/multi_company.py b/addons/multi_company/multi_company.py new file mode 100644 index 00000000000..e735bf91b30 --- /dev/null +++ b/addons/multi_company/multi_company.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## +from mx import DateTime +import time +import netsvc +from osv import fields, osv +from tools import config +from tools.translate import _ +import tools + +class multi_company_default(osv.osv): + _name = 'multi_company.default' + _order = 'sequence,id' + _columns = { + 'sequence': fields.integer('Sequence'), + 'name': fields.char('Name', size=32, required=True), + 'company_id': fields.many2one('res.company', 'Main Company', required=True), + 'company_dest_id': fields.many2one('res.company', 'Default Company', required=True), + 'object_id': fields.many2one('ir.model', 'Object', required=True), + 'expression': fields.char('Expression', size=32, required=True), + } + _defaults = { + 'expression': lambda *a: 'True', + 'sequence': lambda *a: 1 + } +multi_company_default() + +class res_company(osv.osv): + _inherit = 'res.company' + + def _company_default_get(self, cr, uid, object=False, context={}): + + proxy = self.pool.get('multi_company.default') + ids = proxy.search(cr, uid, [('object_id.name', '=', object)]) + for rule in proxy.browse(cr, uid, ids, context): + user = self.pool.get('res.user').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: diff --git a/addons/account/demo/multi_company_demo.xml b/addons/multi_company/multi_company_demo.xml similarity index 100% rename from addons/account/demo/multi_company_demo.xml rename to addons/multi_company/multi_company_demo.xml diff --git a/addons/multi_company/multi_company_view.xml b/addons/multi_company/multi_company_view.xml new file mode 100644 index 00000000000..d2d26c48591 --- /dev/null +++ b/addons/multi_company/multi_company_view.xml @@ -0,0 +1,45 @@ + + + + + multi_company.default.tree + multi_company.default + tree + + + + + + + + + + + + + multi_company.default.form + multi_company.default + form + +
+ + + + + + + + +
+ + + Multi Company + ir.actions.act_window + multi_company.default + form + + + + +
+
diff --git a/addons/product/product.py b/addons/product/product.py index b43814fe37d..e640628dbf9 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -743,6 +743,7 @@ class product_supplierinfo(osv.osv): 'qty': lambda *a: 0.0, 'sequence': lambda *a: 1, 'delay': lambda *a: 1, + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.supplierinfo', c) } _order = 'sequence' product_supplierinfo() diff --git a/addons/project/project.py b/addons/project/project.py index 47c6ee01cad..4eb85cbee31 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -125,7 +125,7 @@ class project(osv.osv): 'priority': lambda *a: 1, 'date_start': lambda *a: time.strftime('%Y-%m-%d'), 'state': lambda *a: 'open', - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'project.project', c) } _order = "parent_id,priority,name" @@ -314,7 +314,7 @@ class task(osv.osv): 'active': lambda *a: True, 'date_start': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 'project_id': _default_project, - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'project.task', c) } _order = "sequence, priority, date_deadline, id" diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 67f3fc95ef2..b260f7c24d0 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -206,6 +206,7 @@ class purchase_order(osv.osv): 'invoiced': lambda *a: 0, 'partner_address_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').address_get(cr, uid, [context['partner_id']], ['default'])['default'], 'pricelist_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').browse(cr, uid, context['partner_id']).property_product_pricelist_purchase.id, + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'purchase.order', c) } _name = "purchase.order" _description = "Purchase order" @@ -448,6 +449,7 @@ class purchase_order_line(osv.osv): 'notes': fields.text('Notes'), 'order_id': fields.many2one('purchase.order', 'Order Ref', select=True, required=True, ondelete='cascade'), 'account_analytic_id':fields.many2one('account.analytic.account', 'Analytic Account',), + 'company_id': fields.related('order_id','company_id',type='many2one',object='res.company',string='Company') } _defaults = { 'product_qty': lambda *a: 1.0 diff --git a/addons/sale/sale.py b/addons/sale/sale.py index b2ee4b984ee..717b5d4540e 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -254,7 +254,7 @@ class sale_order(osv.osv): 'invoice_quantity': fields.selection([('order', 'Ordered Quantities'), ('procurement', 'Shipped Quantities')], 'Invoice on', help="The sale order will automatically create the invoice proposition (draft invoice). Ordered and delivered quantities may not be the same. You have to choose if you invoice based on ordered or shipped quantities. If the product is a service, shipped quantities means hours spent on the associated tasks.", required=True), 'payment_term': fields.many2one('account.payment.term', 'Payment Term'), - 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position') + 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'), } _defaults = { 'picking_policy': lambda *a: 'direct', @@ -767,6 +767,7 @@ class sale_order_line(osv.osv): 'state': fields.selection([('draft', 'Draft'), ('confirmed', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled'), ('exception', 'Exception')], 'Status', required=True, readonly=True), 'order_partner_id': fields.related('order_id', 'partner_id', type='many2one', relation='res.partner', string='Customer'), 'salesman_id':fields.related('order_id','user_id',type='many2one',relation='res.users',string='Salesman'), + 'company_id': fields.related('order_id','company_id',type='many2one',object='res.company',string='Company') } _order = 'sequence, id' _defaults = {