From 65b70827c4f754082cc7d29f173c42488656a663 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sun, 13 Jun 2010 00:00:05 +0200 Subject: [PATCH] fix_and_better_access_rights bzr revid: fp@tinyerp.com-20100612220005-4a33xqgs8bvvoa7x --- .../account/wizard/account_automatic_reconcile.py | 3 +- .../account_budget/wizard/account_budget_spread.py | 7 +- addons/auction/report/auction_invoice.py | 3 +- addons/crm/report/crm_phonecall_report_view.xml | 2 +- addons/hr/security/ir.model.access.csv | 1 + addons/hr_attendance/report/bymonth.py | 6 +- addons/hr_attendance/report/timesheet.py | 135 ++++++++++---------- addons/hr_attendance/security/ir.model.access.csv | 2 + .../wizard/hr_attendance_sign_in_out.py | 41 +++--- .../wizard/hr_attendance_sign_in_out_view.xml | 56 ++++---- addons/hr_contract/security/ir.model.access.csv | 3 + addons/mrp/mrp_view.xml | 2 +- 12 files changed, 127 insertions(+), 134 deletions(-) diff --git a/addons/account/wizard/account_automatic_reconcile.py b/addons/account/wizard/account_automatic_reconcile.py index 2370c6d..a1798ae 100644 --- a/addons/account/wizard/account_automatic_reconcile.py +++ b/addons/account/wizard/account_automatic_reconcile.py @@ -134,7 +134,6 @@ class account_automatic_reconcile(osv.osv_memory): return (reconciled, len(credits)+len(debits)) def reconcile(self, cr, uid, ids, context=None): - service = netsvc.LocalService("object_proxy") move_line_obj = self.pool.get('account.move.line') obj_model = self.pool.get('ir.model.data') if context is None: @@ -240,4 +239,4 @@ class account_automatic_reconcile(osv.osv_memory): account_automatic_reconcile() -# 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/account_budget/wizard/account_budget_spread.py b/addons/account_budget/wizard/account_budget_spread.py index ab2eb3d..f8a627c 100644 --- a/addons/account_budget/wizard/account_budget_spread.py +++ b/addons/account_budget/wizard/account_budget_spread.py @@ -32,13 +32,12 @@ class account_budget_spread(osv.osv_memory): } def check_spread(self, cr, uid, ids, context=None): - service = netsvc.LocalService("object_proxy") if context is None: context = {} - data = self.read(cr, uid, ids, [])[0] - res = service.execute(cr.dbname, uid, 'account.budget.post', 'spread', context['active_ids'], data['fiscalyear'], data['amount']) + data = self.browse(cr, uid, ids, context=context)[0] + res = self.pool.get('account.budget.post').spread(cr, uid, context['active_ids'], data.fiscalyear.id, data.amount) return {} account_budget_spread() -# 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/auction/report/auction_invoice.py b/addons/auction/report/auction_invoice.py index f367d8d..b8c5082 100644 --- a/addons/auction/report/auction_invoice.py +++ b/addons/auction/report/auction_invoice.py @@ -27,8 +27,7 @@ class auction_invoice(report_int): report_int.__init__(self, name) def create(self,cr, uid, ids, datas, context): - service = netsvc.LocalService("object_proxy") - lots = service.execute(cr.dbname,uid, 'auction.lots', 'read', ids, ['ach_inv_id']) + lots = self.pool.get('auction.lots').read(cr,uid, ids, ['ach_inv_id'], context=context) invoices = {} for l in lots: diff --git a/addons/crm/report/crm_phonecall_report_view.xml b/addons/crm/report/crm_phonecall_report_view.xml index 597d06f..f1f5eb4 100644 --- a/addons/crm/report/crm_phonecall_report_view.xml +++ b/addons/crm/report/crm_phonecall_report_view.xml @@ -187,7 +187,7 @@ - diff --git a/addons/hr/security/ir.model.access.csv b/addons/hr/security/ir.model.access.csv index 95fca26..3d05e4d 100644 --- a/addons/hr/security/ir.model.access.csv +++ b/addons/hr/security/ir.model.access.csv @@ -1,6 +1,7 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_hr_employee_category","hr.employee.category","model_hr_employee_category","hr.group_hr_user",1,0,0,0 "access_hr_employee","hr.employee","model_hr_employee","hr.group_hr_user",1,1,1,1 +"access_hr_employee_resource","resource.resource","resource.model_resource_resource","hr.group_hr_user",1,1,1,1 "access_hr_department","hr.department","model_hr_department","hr.group_hr_user",1,0,0,0 "access_hr_employee_category_manager","hr.employee.category.manager","model_hr_employee_category","hr.group_hr_manager",1,1,1,1 "access_hr_department_manager","hr.department.manager","model_hr_department","hr.group_hr_manager",1,1,1,1 diff --git a/addons/hr_attendance/report/bymonth.py b/addons/hr_attendance/report/bymonth.py index 8f9b0ea..e30d410 100644 --- a/addons/hr_attendance/report/bymonth.py +++ b/addons/hr_attendance/report/bymonth.py @@ -39,14 +39,10 @@ def hour2str(h): class report_custom(report_rml): def create_xml(self, cr, uid, ids, datas, context): - service = netsvc.LocalService('object_proxy') - month = DateTime.DateTime(datas['form']['year'], datas['form']['month'], 1) - user_xml = ['%s' % month2name[month.month], '%s' % month.year] - for employee_id in ids: - emp = service.execute(cr.dbname, uid, 'hr.employee', 'read', [employee_id])[0] + emp = self.pool.get('hr.employee').read(cr, uid, 'read', [employee_id], ['name'])[0] stop, days_xml = False, [] user_repr = ''' diff --git a/addons/hr_attendance/report/timesheet.py b/addons/hr_attendance/report/timesheet.py index f5af46d..9b428a6 100644 --- a/addons/hr_attendance/report/timesheet.py +++ b/addons/hr_attendance/report/timesheet.py @@ -32,81 +32,80 @@ one_week = DateTime.RelativeDateTime(days=7) num2day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] def to_hour(h): - return int(h), int(round((h - int(h)) * 60, 0)) + return int(h), int(round((h - int(h)) * 60, 0)) class report_custom(report_rml): - def create_xml(self, cr, uid, ids, datas, context): - service = netsvc.LocalService('object_proxy') + def create_xml(self, cr, uid, ids, datas, context): - start_date = DateTime.strptime(datas['form']['init_date'], '%Y-%m-%d') - end_date = DateTime.strptime(datas['form']['end_date'], '%Y-%m-%d') - first_monday = start_date - DateTime.RelativeDateTime(days=start_date.day_of_week) - last_monday = end_date + DateTime.RelativeDateTime(days=7 - end_date.day_of_week) + start_date = DateTime.strptime(datas['form']['init_date'], '%Y-%m-%d') + end_date = DateTime.strptime(datas['form']['end_date'], '%Y-%m-%d') + first_monday = start_date - DateTime.RelativeDateTime(days=start_date.day_of_week) + last_monday = end_date + DateTime.RelativeDateTime(days=7 - end_date.day_of_week) - if last_monday < first_monday: - first_monday, last_monday = last_monday, first_monday + if last_monday < first_monday: + first_monday, last_monday = last_monday, first_monday - user_xml = [] + user_xml = [] - for employee_id in ids: - emp = service.execute(cr.dbname, uid, 'hr.employee', 'read', [employee_id], ['id', 'name'])[0] - monday, n_monday = first_monday, first_monday + one_week - stop, week_xml = False, [] - user_repr = ''' - - %s - %%s - - ''' % toxml(emp['name']) - while monday != last_monday: - #### Work hour calculation - sql = ''' - select action, att.name - from hr_employee as emp inner join hr_attendance as att - on emp.id = att.employee_id - where att.name between %s and %s and emp.id = %s - order by att.name - ''' - for idx in range(7): - cr.execute(sql, (monday.strftime('%Y-%m-%d %H:%M:%S'), (monday + DateTime.RelativeDateTime(days=idx+1)).strftime('%Y-%m-%d %H:%M:%S'), employee_id)) - attendances = cr.dictfetchall() - week_wh = {} - # Fake sign ins/outs at week ends, to take attendances across week ends into account - # XXX this is wrong for the first sign-in ever and the last sign out to this date - if attendances and attendances[0]['action'] == 'sign_out': - attendances.insert(0, {'name': monday.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_in'}) - if attendances and attendances[-1]['action'] == 'sign_in': - attendances.append({'name' : n_monday.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_out'}) - # sum up the attendances' durations - for att in attendances: - dt = DateTime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') - if att['action'] == 'sign_out': - week_wh[ldt.day_of_week] = week_wh.get(ldt.day_of_week, 0) + (dt - ldt).hours - ldt = dt + for employee_id in ids: + emp = self.pool.get('hr.employee').read(cr, uid, [employee_id], ['id', 'name'])[0] + monday, n_monday = first_monday, first_monday + one_week + stop, week_xml = False, [] + user_repr = ''' + + %s + %%s + + ''' % toxml(emp['name']) + while monday != last_monday: + #### Work hour calculation + sql = ''' + select action, att.name + from hr_employee as emp inner join hr_attendance as att + on emp.id = att.employee_id + where att.name between %s and %s and emp.id = %s + order by att.name + ''' + for idx in range(7): + cr.execute(sql, (monday.strftime('%Y-%m-%d %H:%M:%S'), (monday + DateTime.RelativeDateTime(days=idx+1)).strftime('%Y-%m-%d %H:%M:%S'), employee_id)) + attendances = cr.dictfetchall() + week_wh = {} + # Fake sign ins/outs at week ends, to take attendances across week ends into account + # XXX this is wrong for the first sign-in ever and the last sign out to this date + if attendances and attendances[0]['action'] == 'sign_out': + attendances.insert(0, {'name': monday.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_in'}) + if attendances and attendances[-1]['action'] == 'sign_in': + attendances.append({'name' : n_monday.strftime('%Y-%m-%d %H:%M:%S'), 'action':'sign_out'}) + # sum up the attendances' durations + for att in attendances: + dt = DateTime.strptime(att['name'], '%Y-%m-%d %H:%M:%S') + if att['action'] == 'sign_out': + week_wh[ldt.day_of_week] = week_wh.get(ldt.day_of_week, 0) + (dt - ldt).hours + ldt = dt - # Week xml representation - week_repr = ['', '%s' % monday.strftime('%Y-%m-%d'), '%s' % n_monday.strftime('%Y-%m-%d')] - for idx in range(7): - week_repr.append('<%s>' % num2day[idx]) - if idx in week_wh: - week_repr.append('%sh%02d' % to_hour(week_wh[idx])) - week_repr.append('' % num2day[idx]) - week_repr.append('') - week_repr.append('%sh%02d' % to_hour(reduce(lambda x,y:x+y, week_wh.values(), 0))) - week_repr.append('') - week_repr.append('') - if len(week_repr) > 21: # 21 = minimal length of week_repr - week_xml.append('\n'.join(week_repr)) - - monday, n_monday = n_monday, n_monday + one_week - user_xml.append(user_repr % '\n'.join(week_xml)) - - xml = ''' - - %s - - ''' % '\n'.join(user_xml) - return self.post_process_xml_data(cr, uid, xml, context) + # Week xml representation + week_repr = ['', '%s' % monday.strftime('%Y-%m-%d'), '%s' % n_monday.strftime('%Y-%m-%d')] + for idx in range(7): + week_repr.append('<%s>' % num2day[idx]) + if idx in week_wh: + week_repr.append('%sh%02d' % to_hour(week_wh[idx])) + week_repr.append('' % num2day[idx]) + week_repr.append('') + week_repr.append('%sh%02d' % to_hour(reduce(lambda x,y:x+y, week_wh.values(), 0))) + week_repr.append('') + week_repr.append('') + if len(week_repr) > 21: # 21 = minimal length of week_repr + week_xml.append('\n'.join(week_repr)) + + monday, n_monday = n_monday, n_monday + one_week + user_xml.append(user_repr % '\n'.join(week_xml)) + + xml = ''' + + %s + + ''' % '\n'.join(user_xml) + return self.post_process_xml_data(cr, uid, xml, context) report_custom('report.hr.attendance.allweeks', 'hr.employee', '', 'addons/hr_attendance/report/timesheet.xsl') # vim:noexpandtab:tw=0 diff --git a/addons/hr_attendance/security/ir.model.access.csv b/addons/hr_attendance/security/ir.model.access.csv index 6150427..54a15a7 100644 --- a/addons/hr_attendance/security/ir.model.access.csv +++ b/addons/hr_attendance/security/ir.model.access.csv @@ -3,3 +3,5 @@ "access_hr_action_reason_employee","hr action reason employee","model_hr_action_reason","hr.group_hr_manager",1,1,1,1 "access_hr_attendance_employee","hr attendance employee","model_hr_attendance","hr_attendance.group_hr_attendance",1,1,1,1 "access_hr_sign_in_out","hr attendance sign in out","model_hr_sign_in_out","hr_attendance.group_hr_attendance",1,1,1,1 +"access_hr_attendance_employee","hr employee attendance sign in out","hr.model_hr_employee","hr_attendance.group_hr_attendance",1,0,0,0 +"access_hr_attendance_resource","hr resource attendance sign in out","resource.model_resource_resource","hr_attendance.group_hr_attendance",1,0,0,0 diff --git a/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py b/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py index 9ad2729..aaaefc0 100644 --- a/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py +++ b/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py @@ -33,16 +33,14 @@ class hr_si_so_ask(osv.osv_memory): 'emp_id': fields.char('Empoyee ID', size=32, required=True, readonly=True), } def _get_empname(self, cr, uid, context=None): - service = netsvc.LocalService('object_proxy') - emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)]) + emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if emp_id: - employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0] + employee = self.pool.get('hr.employee').browse(cr, uid, emp_id, context=context)[0].name return employee['name'] return '' def _get_empid(self, cr, uid, context=None): - service = netsvc.LocalService('object_proxy') - emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)]) + emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if emp_id: return emp_id[0] return False @@ -74,11 +72,10 @@ class hr_sign_in_out(osv.osv_memory): } def _get_empid(self, cr, uid, context=None): - service = netsvc.LocalService('object_proxy') - emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)]) + emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if emp_id: - employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0] - return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0]} + employee = self.pool.get('hr.employee').browse(cr, uid, emp_id, context=context)[0] + return {'name': employee.name, 'state': employee.state, 'emp_id': emp_id[0]} return {} def default_get(self, cr, uid, fields_list, context=None): @@ -88,15 +85,15 @@ class hr_sign_in_out(osv.osv_memory): return res def si_check(self, cr, uid, ids, context=None): - service = netsvc.LocalService('object_proxy') obj_model = self.pool.get('ir.model.data') + att_obj = self.pool.get('hr.attendance') data = self.read(cr, uid, ids, [])[0] emp_id = data['emp_id'] - att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id)], limit=1, order='name desc') - last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id) + att_id = att_obj.search(cr, uid, [('employee_id', '=', emp_id)], limit=1, order='name desc') + last_att = att_obj.browse(cr, uid, att_id) if last_att: last_att = last_att[0] - cond = not last_att or last_att['action'] == 'sign_out' + cond = not last_att or last_att.action == 'sign_out' if cond: return self.sign_in(cr, uid, data, context) else: @@ -113,12 +110,12 @@ class hr_sign_in_out(osv.osv_memory): } def so_check(self, cr, uid, ids, context=None): - service = netsvc.LocalService('object_proxy') obj_model = self.pool.get('ir.model.data') data = self.read(cr, uid, ids, [])[0] + att_obj = self.pool.get('hr.attendance') emp_id = data['emp_id'] - att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id),('action','!=','action')], limit=1, order='name desc') - last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id) + att_id = att_obj.search(cr, uid, [('employee_id', '=', emp_id),('action','!=','action')], limit=1, order='name desc') + last_att = att_obj.browse(cr, uid, att_id, context=context) if last_att: last_att = last_att[0] if not att_id and not last_att: @@ -151,35 +148,33 @@ class hr_sign_in_out(osv.osv_memory): } def sign_in(self, cr, uid, data, context=None): - service = netsvc.LocalService('object_proxy') emp_id = data['emp_id'] if 'last_time' in data: if data['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'): raise osv.except_osv(_('UserError'), _('The sign-out date must be in the past')) - service.execute(cr.dbname, uid, 'hr.attendance', 'create', { + self.pool.get('hr.attendance').create(cr, uid, { 'name': data['last_time'], 'action': 'sign_out', 'employee_id': emp_id }) try: - success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_in') + success = self.pool.get('hr.employee').attendance_action_change(cr, uid, [emp_id], 'sign_in') except: raise osv.except_osv(_('UserError'), _('A sign-in must be right after a sign-out !')) return {} # To do: Return Success message def sign_out(self, cr, uid, data, context=None): - service = netsvc.LocalService('object_proxy') emp_id = data['emp_id'] if 'last_time' in data: if data['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'): raise osv.except_osv(_('UserError'), _('The Sign-in date must be in the past')) - service.execute(cr.dbname, uid, 'hr.attendance', 'create', {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id}) + self.pool.get('hr.attendance').create(cr, uid, {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id}) try: - success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_out') + success = self.pool.get('hr.employee').attendance_action_change(cr, uid, [emp_id], 'sign_out') except: raise osv.except_osv(_('UserError'), _('A sign-out must be right after a sign-in !')) return {} # To do: Return Success message hr_sign_in_out() -# 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_attendance/wizard/hr_attendance_sign_in_out_view.xml b/addons/hr_attendance/wizard/hr_attendance_sign_in_out_view.xml index d5253df..443983d 100644 --- a/addons/hr_attendance/wizard/hr_attendance_sign_in_out_view.xml +++ b/addons/hr_attendance/wizard/hr_attendance_sign_in_out_view.xml @@ -1,21 +1,21 @@ - + hr.sign.in.out.form hr.sign.in.out form
- - - - - + + + + + -