From 34be74d3df001fb35d77c78f6bd7da9a937b1d50 Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Thu, 23 Sep 2010 09:52:53 +0200 Subject: [PATCH 01/13] [IMP] hr: performance improvement: removed 2 not used fields (parent_id, child_ids) bzr revid: olt@tinyerp.com-20100923075253-kolxfmlzlo2kj51p --- addons/hr/hr_department.py | 79 +------------------------------- addons/hr/hr_department_view.xml | 4 -- 2 files changed, 1 insertion(+), 82 deletions(-) diff --git a/addons/hr/hr_department.py b/addons/hr/hr_department.py index 21946469ce4..ec6f276e670 100644 --- a/addons/hr/hr_department.py +++ b/addons/hr/hr_department.py @@ -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: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr/hr_department_view.xml b/addons/hr/hr_department_view.xml index c2bb6ac7390..7626c501167 100644 --- a/addons/hr/hr_department_view.xml +++ b/addons/hr/hr_department_view.xml @@ -87,10 +87,6 @@ - - - - From c1dcd713577406b48a6095e121dd7374edfc5290 Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Thu, 23 Sep 2010 09:53:54 +0200 Subject: [PATCH 02/13] [IMP] analytic: performance improvement: using browse instead of search for children computation bzr revid: olt@tinyerp.com-20100923075354-jispscmrhfhhwmy4 --- addons/analytic/analytic.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index eef25f665d8..b97edb9a546 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -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): From 07b88cb8da2d6e3d9a13fc5afff69c1b95c14a0a Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Thu, 23 Sep 2010 14:47:34 +0530 Subject: [PATCH 03/13] [FIX]: add the missing field to the payslip model bzr revid: mga@tinyerp.com-20100923091734-7niyoorw5hmryo58 --- addons/hr_payroll/hr_payroll.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 7a6eaf14b58..48ffc1f6b20 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -784,6 +784,7 @@ class hr_payslip(osv.osv): 'contract_id':fields.many2one('hr.contract', 'Contract', required=False), 'igross': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'inet': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), + 'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d'), From cc4ee88766573321b927c3cbf061d303856240ce Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Thu, 23 Sep 2010 15:30:36 +0530 Subject: [PATCH 04/13] [FIX]: solve the usability issue in psyslip view bzr revid: mga@tinyerp.com-20100923100036-mtbc9m87t39fpya9 --- addons/hr_payroll/hr_payroll_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index fbfa2d1aad5..d833612e383 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -500,12 +500,12 @@ +