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"
if not new_user_id:
raise osv.except_osv(_('Error!'), _('In order to create a timesheet for this employee, you must assign it to a user.'))
if not self._sheet_date(cr, uid, ids, forced_user_id=new_user_id):
- raise osv.except_osv(_('Error!'), _('You cannot have 2 timesheets that overlaps!\nYou should use the menu \'My Timesheet\' to avoid this problem.'))
+ raise osv.except_osv(_('Error!'), _('You cannot have 2 timesheets that overlap!\nYou should use the menu \'My Timesheet\' to avoid this problem.'))
if not self.pool.get('hr.employee').browse(cr, uid, vals['employee_id']).product_id:
raise osv.except_osv(_('Error!'), _('In order to create a timesheet for this employee, you must link the employee to a product.'))
if not self.pool.get('hr.employee').browse(cr, uid, vals['employee_id']).journal_id:
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.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
_constraints = [
- (_sheet_date, 'You cannot have 2 timesheets that overlaps !\nPlease use the menu \'My Current Timesheet\' to avoid this problem.', ['date_from','date_to']),
+ (_sheet_date, 'You cannot have 2 timesheets that overlap!\nPlease use the menu \'My Current Timesheet\' to avoid this problem.', ['date_from','date_to']),
]
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,}}
-hr_timesheet_sheet()
+ # ------------------------------------------------
+ # OpenChatter methods and notifications
+ # ------------------------------------------------
+ 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
-class hr_timesheet_line(osv.osv):
- _inherit = "hr.analytic.timesheet"
+
+class account_analytic_line(osv.osv):
+ _inherit = "account.analytic.line"
def _get_default_date(self, cr, uid, context=None):
if context is None:
context = {}
- if 'date' in context:
- return context['date']
- return time.strftime('%Y-%m-%d')
+ #get the default date (should be: today)
+ res = super(account_analytic_line, self)._get_default_date(cr, uid, context=context)
+ #if we got the dates from and to from the timesheet and if the default date is in between, we use the default
+ #but if the default isn't included in those dates, we use the date start of the timesheet as default
+ if context.get('timesheet_date_from') and context.get('timesheet_date_to'):
+ if context['timesheet_date_from'] <= res <= context['timesheet_date_to']:
+ return res
+ return context.get('timesheet_date_from')
+ #if we don't get the dates from the timesheet, we return the default value from super()
+ return res
+
+
+class hr_timesheet_line(osv.osv):
+ _inherit = "hr.analytic.timesheet"
def _sheet(self, cursor, user, ids, name, args, context=None):
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
},
),
}
- _defaults = {
- 'date': _get_default_date,
- }
def _check_sheet_state(self, cr, uid, ids, context=None):
if context is None: