from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
-from osv import fields, osv
-from tools.translate import _
-import netsvc
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
class hr_timesheet_sheet(osv.osv):
_name = "hr_timesheet_sheet.sheet"
self.check_employee_attendance_state(cr, uid, sheet.id, context=context)
di = sheet.user_id.company_id.timesheet_max_difference
if (abs(sheet.total_difference) < di) or not di:
- wf_service = netsvc.LocalService("workflow")
- wf_service.trg_validate(uid, 'hr_timesheet_sheet.sheet', sheet.id, 'confirm', cr)
- self.confirm_send_note(cr, uid, ids, context=context)
+ self.signal_confirm(cr, uid, [sheet.id])
else:
raise osv.except_osv(_('Warning!'), _('Please verify that the total difference of the sheet is lower than %.2f.') %(di,))
return True
- def button_cancel(self, cr, uid, ids, context=None):
- for sheet in self.browse(cr, uid, ids, context=context):
- if sheet.employee_id and sheet.employee_id.user_id:
- self.message_subscribe_users(cr, uid, [sheet.id], user_ids=[sheet.employee_id.user_id.id], context=context)
- wf_service = netsvc.LocalService("workflow")
- wf_service.trg_validate(uid, 'hr_timesheet_sheet.sheet', sheet.id, 'cancel', cr)
- self.cancel_send_note(cr, uid, ids, context=context)
- return True
-
def attendance_action_change(self, cr, uid, ids, context=None):
hr_employee = self.pool.get('hr.employee')
employee_ids = []
'date_to' : _default_date_to,
'state': 'new',
'employee_id': _default_employee,
- 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr_timesheet_sheet.sheet', context=c),
+ 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr_timesheet_sheet.sheet', context=c)
}
def _sheet_date(self, cr, uid, ids, forced_user_id=False, context=None):
def action_set_to_draft(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'draft'})
- wf_service = netsvc.LocalService('workflow')
- for id in ids:
- wf_service.trg_create(uid, self._name, id, cr)
+ self.create_workflow(cr, uid, ids)
return True
def name_get(self, cr, uid, ids, context=None):
def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
department_id = False
if employee_id:
- department_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context).department_id.id
- return {'value': {'department_id': department_id}}
+ empl_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
+ department_id = empl_id.department_id.id
+ user_id = empl_id.user_id.id
+ return {'value': {'department_id': department_id, 'user_id': user_id,}}
# ------------------------------------------------
# OpenChatter methods and notifications
# ------------------------------------------------
-
- def _needaction_domain_get(self, cr, uid, ids, context=None):
+
+ def _needaction_domain_get(self, cr, uid, context=None):
emp_obj = self.pool.get('hr.employee')
empids = emp_obj.search(cr, uid, [('parent_id.user_id', '=', uid)], context=context)
+ if not empids:
+ return False
dom = ['&', ('state', '=', 'confirm'), ('employee_id', 'in', empids)]
return dom
- def confirm_send_note(self, cr, uid, ids, context=None):
- for obj in self.browse(cr, uid, ids, context=context):
- self.message_post(cr, uid, [obj.id], body=_("Timesheet has been submitted by %s.") % (obj.employee_id.name), subtype="hr_timesheet_sheet.mt_submit_timesheet", context=context)
-
- def cancel_send_note(self, cr, uid, ids, context=None):
- user_name = self.pool.get("res.users").browse(cr, uid, uid, context=context).name
- for obj in self.browse(cr, uid, ids, context=context):
- self.message_post(cr, uid, [obj.id], body=_("Timesheet has been refused by %s.") % (user_name), subtype="hr_timesheet_sheet.mt_refuse_timesheet", context=context)
-
-hr_timesheet_sheet()
class account_analytic_line(osv.osv):
_inherit = "account.analytic.line"