For Timesheets access, add a record rule with ['|',('employee_id.user_id','=',user.id),('employee_id.parent_id.user_id','=',user.id)]
in domain filter field.
Adding the employee_id field is not sufficient, you should fill it by overriding the on_change_user_id
method, I suppose that your employees are linked to users and you have added employee_id
field in hr.analytic.timesheet form view and tree view.
In .py file:
def on_change_user_id(self, cr, uid, ids, user_id):
if not user_id:
return {}
context = {'user_id': user_id}
emp = self.pool.get("hr.employee").search(cr,uid,[('user_id','=',user_id)])
return {'value': {
'product_id': self. _getEmployeeProduct(cr, uid, context),
'product_uom_id': self._getEmployeeUnit(cr, uid, context),
'general_account_id': self._getGeneralAccount(cr, uid, context),
'journal_id': self._getAnalyticJournal(cr, uid, context),
'employee_id': emp and emp[0],
}}
You should also fill the employee_id field when you are creating Timesheet Activities form timesheet form by overrinding the create method:
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
emp_obj = self.pool.get('hr.employee')
emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id') or uid)], context=context)
vals['employee_id'] = emp_id and emp_id[0]
ename = ''
if emp_id:
ename = emp_obj.browse(cr, uid, emp_id[0], context=context).name
if not vals.get('journal_id',False):
raise osv.except_osv(_('Warning!'), _('No \'Analytic Journal\' is defined for employee %s \nDefine an employee for the selected user and assign an \'Analytic Journal\'!')%(ename,))
if not vals.get('account_id',False):
raise osv.except_osv(_('Warning!'), _('No analytic account is defined on the project.\nPlease set one or we cannot automatically fill the timesheet.'))
return super(hr_analytic_timesheet, self).create(cr, uid, vals, context=context)
At this moment, the same rule can be applied on Timesheet Activities
and Timesheets
Hello. Did u managed to resolve this problem ?
"I try to add this line to hr.analytic.timesheet model 'employee_id': fields.many2one('hr.employee', 'Employee', required=True)"
Where did you modify this. What file path... or menu ?