- try:
- res = super(hr_analytic_timesheet, self).create(cr, uid, vals, context)
- return res
- except Exception,e:
- if '"journal_id" viol' in e.args[0]:
- raise except_orm(_('ValidateError'),
- _('No analytic journal available for this employee.\nDefine an employee for the selected user and assign an analytic journal.'))
- elif '"account_id" viol' in e.args[0]:
- raise except_orm(_('ValidateError'),
- _('No analytic account defined on the project.\nPlease set one or we can not automatically fill the timesheet.'))
- else:
- raise except_orm(_('UnknownError'), str(e))
+ emp_obj = self.pool.get('hr.employee')
+ emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
+ 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 !'), _('Analytic journal is not 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 defined on the project.\nPlease set one or we can not automatically fill the timesheet.'))
+ return super(hr_analytic_timesheet, self).create(cr, uid, vals, context=context)