From ad0ed2c4d809c927047836dd8f7318c7751205e8 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 7 May 2014 16:17:25 +0200 Subject: [PATCH] [FIX] code cleanup (addon hr_timesheet_sheet) remove try/except/statement that should not be here, uses search_count when appropriate, and remove a now useless one2many field bzr revid: ged@openerp.com-20140507141725-h2z9u72roscf407n --- .../hr_timesheet_sheet/hr_timesheet_sheet.py | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index b771714c9b7..fe677561b2c 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -134,15 +134,15 @@ class hr_timesheet_sheet(osv.osv): return hr_employee.attendance_action_change(cr, uid, employee_ids, context=context) def _count_all(self, cr, uid, ids, field_name, arg, context=None): - res = dict(map(lambda x: (x,{'timesheet_activity_count': 0, 'attendance_count': 0,}), ids)) - try: - for datas in self.browse(cr, uid, ids, context=context): - res[datas.id] = {'timesheet_activity_count': len(datas.timesheet_activity_ids), - 'attendance_count': len(datas.attendances_ids), - } - except: - pass - return res + Timesheet = self.pool['hr.analytic.timesheet'] + Attendance = self.pool['hr.attendance'] + return { + sheet_id: { + 'timesheet_activity_count': Timesheet.search_count(cr,uid, [('sheet_id','=', sheet_id)], context=context), + 'attendance_count': Attendance.search_count(cr,uid, [('sheed_id', '=', sheet_id)], context=context) + } + for sheet_id in ids + } _columns = { 'name': fields.char('Note', size=64, select=1, @@ -174,7 +174,6 @@ class hr_timesheet_sheet(osv.osv): 'account_ids': fields.one2many('hr_timesheet_sheet.sheet.account', 'sheet_id', 'Analytic accounts', readonly=True), 'company_id': fields.many2one('res.company', 'Company'), 'department_id':fields.many2one('hr.department','Department'), - 'timesheet_activity_ids': fields.one2many('hr.analytic.timesheet', 'sheet_id', 'Timesheet Activities'), 'timesheet_activity_count': fields.function(_count_all, type='integer', string='Timesheet Activities', multi=True), 'attendance_count': fields.function(_count_all, type='integer', string="Attendances", multi=True), } @@ -610,17 +609,14 @@ class hr_employee(osv.osv): _description = 'Employee' def _timesheet_count(self, cr, uid, ids, field_name, arg, context=None): - res = dict(map(lambda x: (x,0), ids)) - try: - for employee in self.browse(cr, uid, ids, context=context): - res[employee.id] = len(employee.timesheet_ids) - except: - pass - return res + Sheet = self.pool['hr_timesheet_sheet.sheet'] + return { + employee_id: Sheet.search_count(cr,uid, [('employee_id', '=', employee_id)], context=context) + for employee_id in ids + } _columns = { - 'timesheet_ids': fields.one2many('hr_timesheet_sheet.sheet', 'employee_id', 'Timesheets'), - 'timesheet_count': fields.function(_timesheet_count, type='integer', string='Timsheets'), + 'timesheet_count': fields.function(_timesheet_count, type='integer', string='Timesheets'), } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: