[MERGE] merge from trunk addons

bzr revid: mra@mra-laptop-20100923082443-541a8tfmlnwfn9wh
This commit is contained in:
Mustufa Rangwala
2010-09-23 13:54:43 +05:30
3 changed files with 15 additions and 96 deletions
+14 -14
View File
@@ -35,16 +35,16 @@ class account_analytic_account(osv.osv):
cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id IN %s" , (tuple(ids2),))
currency = dict(cr.fetchall())
res_currency= self.pool.get('res.currency')
for id in ids:
if id not in ids2:
for account in self.browse(cr, uid, ids, context=context):
if account.id not in ids2:
continue
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child != id:
res.setdefault(id, 0.0)
if currency[child]!=currency[id]:
res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context)
for child in account.child_ids:
if child.id != account.id:
res.setdefault(account.id, 0.0)
if currency[child.id] != currency[account.id]:
res[account.id] += res_currency.compute(cr, uid, currency[child.id], currency[account.id], res.get(child.id, 0.0), context=context)
else:
res[id] += res.get(child, 0.0)
res[account.id] += res.get(child.id, 0.0)
cur_obj = res_currency.browse(cr, uid, currency.values(), context=context)
cur_obj = dict([(o.id, o) for o in cur_obj])
@@ -145,13 +145,13 @@ class account_analytic_account(osv.osv):
for account_id, sum in cr.fetchall():
res[account_id] = sum
for id in ids:
if id not in parent_ids:
for account in self.browse(cr, uid, ids, context=context):
if account.id not in parent_ids:
continue
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child != id:
res.setdefault(id, 0.0)
res[id] += res.get(child, 0.0)
for child in account.child_ids:
if child.id != account.id:
res.setdefault(account.id, 0.0)
res[account.id] += res.get(child.id, 0.0)
return dict([(i, res[i]) for i in ids])
def name_get(self, cr, uid, ids, context=None):
+1 -78
View File
@@ -113,87 +113,10 @@ class res_users(osv.osv):
_inherit = 'res.users'
_description = 'User'
def _parent_compute(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
result = {}
obj_dept = self.pool.get('hr.department')
for user_id in ids:
emp_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', user_id)], context=context)
cr.execute('SELECT emp.department_id FROM hr_employee AS emp \
JOIN resource_resource AS res ON res.id = emp.resource_id \
JOIN hr_department as dept ON dept.id = emp.department_id \
WHERE res.user_id = %s AND emp.department_id IS NOT NULL AND dept.manager_id IS NOT NULL', (user_id,))
ids_dept = [x[0] for x in cr.fetchall()]
parent_ids = []
if ids_dept:
data_dept = obj_dept.read(cr, uid, ids_dept, ['manager_id'], context=context)
parent_ids = map(lambda x: x['manager_id'][0], data_dept)
cr.execute('SELECT res.user_id FROM hr_employee AS emp JOIN resource_resource AS res ON res.id=emp.resource_id \
WHERE emp.id IN %s AND res.user_id IS NOT NULL', (tuple(parent_ids),))
parent_ids = [x[0] for x in cr.fetchall()]
result[user_id] = parent_ids
return result
def _parent_search(self, cr, uid, obj, name, args, context=None):
if context is None:
context = {}
parent = []
for arg in args:
if arg[0] == 'parent_id':
parent = arg[2]
child_ids = self._child_compute(cr, uid, parent, name, args, context=context)
if not child_ids:
return [('id', 'in', [0])]
return [('id', 'in', child_ids.get(uid, []))]
def _child_compute(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
obj_dept = self.pool.get('hr.department')
obj_user = self.pool.get('res.users')
result = {}
for user_id in ids:
child_ids = []
cr.execute('SELECT dept.id FROM hr_department AS dept \
LEFT JOIN hr_employee AS emp ON dept.manager_id = emp.id \
WHERE emp.id IN \
(SELECT emp.id FROM hr_employee \
JOIN resource_resource r ON r.id = emp.resource_id WHERE r.user_id=' + str(user_id) + ') ')
mgnt_dept_ids = [x[0] for x in cr.fetchall()]
ids_dept = obj_dept.search(cr, uid, [('id', 'child_of', mgnt_dept_ids)], context=context)
if ids_dept:
data_dept = obj_dept.read(cr, uid, ids_dept, ['member_ids'], context=context)
childs = map(lambda x: x['member_ids'], data_dept)
childs = tools.flatten(childs)
childs = obj_user.search(cr, uid, [('id', 'in', childs),('active', '=', True)], context=context)
if user_id in childs:
childs.remove(user_id)
child_ids.extend(tools.flatten(childs))
set = {}
map(set.__setitem__, child_ids, [])
child_ids = set.keys()
result[user_id] = child_ids
return result
def _child_search(self, cr, uid, obj, name, args, context=None):
if context is None:
context = {}
parent = []
for arg in args:
if arg[0] == 'child_ids':
parent = arg[2]
child_ids = self._child_compute(cr, uid, parent, name, args, context=context)
if not child_ids:
return [('id', 'in', [0])]
return [('id', 'in', child_ids.get(uid, []))]
_columns = {
'parent_id': fields.function(_parent_compute, relation='res.users', fnct_search=_parent_search, method=True, string="Managers", type='many2many'),
'child_ids': fields.function(_child_compute, relation='res.users', fnct_search=_child_search, method=True, string="Subordinates", type='many2many'),
'context_department_id': fields.many2one('hr.department', 'Departments'),
}
res_users()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-4
View File
@@ -87,10 +87,6 @@
<notebook position="inside">
<page string="Departments" groups="base.group_extended">
<field name="context_department_id" completion="1" widget="selection" string="Department"/>
<separator string="Managers" colspan="4"/>
<field name="parent_id" nolabel="1" colspan="4"/>
<separator string="Subordinates" colspan="4"/>
<field name="child_ids" nolabel="1" colspan="4"/>
</page>
</notebook>
</field>