[IMP]account,hr_timesheet_sheet,product,project,purchase,sale modules: company_id [ADD] multi_company module.

bzr revid: gpa@gpa-desktop-20091120134742-xzwscqyhzxsbijt5
This commit is contained in:
gpa 2009-11-20 19:17:42 +05:30
parent d0e4ea79a6
commit ac0348f28a
13 changed files with 181 additions and 6 deletions

View File

@ -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,

View File

@ -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 = [

View File

@ -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,

View File

@ -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):

View File

@ -0,0 +1,27 @@
# -*- 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/>.
#
##############################################################################
import multi_company
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,38 @@
# -*- 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/>.
#
##############################################################################
{
'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:

View File

@ -0,0 +1,61 @@
# -*- 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/>.
#
##############################################################################
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:

View File

@ -0,0 +1,45 @@
<?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="arch" type="xml">
<tree string="Multi Company">
<field name="sequence"/>
<field name="name"/>
<field name="company_id"/>
<field name="company_dest_id"/>
<field name="object_id"/>
<field name="expression" />
</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="arch" type="xml">
<form string="Multi Company">
<field name="sequence"/>
<field name="name"/>
<field name="company_id"/>
<field name="company_dest_id"/>
<field name="object_id"/>
<field name="expression" />
</form>
</field>
</record>
<record id="action_inventory_form" model="ir.actions.act_window">
<field name="name">Multi Company</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">multi_company.default</field>
<field name="view_type">form</field>
</record>
<menuitem action="action_inventory_form" id="menu_action_inventory_form" parent="base.menu_action_res_company_tree"/>
</data>
</openerp>

View File

@ -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()

View File

@ -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"

View File

@ -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

View File

@ -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 = {