import time
from datetime import datetime
-from dateutil.relativedelta import relativedelta
+from dateutil.relativedelta import relativedelta, MO
from osv import fields, osv
from tools.translate import _
def _total_day(self, cr, uid, ids, name, args, context=None):
res = {}
- if context is None:
- context = {}
cr.execute('SELECT sheet.id, day.total_attendance, day.total_timesheet, day.total_difference\
FROM hr_timesheet_sheet_sheet AS sheet \
LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
def _total(self, cr, uid, ids, name, args, context=None):
res = {}
- if context is None:
- context = {}
cr.execute('SELECT s.id, COALESCE(SUM(d.total_attendance),0), COALESCE(SUM(d.total_timesheet),0), COALESCE(SUM(d.total_difference),0) \
FROM hr_timesheet_sheet_sheet s \
LEFT JOIN hr_timesheet_sheet_sheet_day d \
result = {}
link_emp = {}
emp_ids = []
- if context is None:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
result[sheet.id] = 'none'
return super(hr_timesheet_sheet, self).write(cr, uid, ids, vals, *args, **argv)
def button_confirm(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
self.check_employee_attendance_state(cr, uid, sheet.id, context)
di = sheet.user_id.company_id.timesheet_max_difference
return True
def date_today(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
if datetime.today() <= datetime.strptime(sheet.date_from, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}, context=context)
return True
def date_previous(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
if datetime.strptime(sheet.date_current, '%Y-%m-%d') <= datetime.strptime(sheet.date_from, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}, context=context)
return True
def date_next(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
if datetime.strptime(sheet.date_current, '%Y-%m-%d') >= datetime.strptime(sheet.date_to, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}, context=context)
return True
def button_dummy(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
if datetime.strptime(sheet.date_current, '%Y-%m-%d') <= datetime.strptime(sheet.date_from, '%Y-%m-%d'):
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_from,}, context=context)
self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}, context=context)
return True
- def sign_in(self, cr, uid, ids, context=None):
+ def sign(self, cr, uid, ids, typ, context=None):
emp_obj = self.pool.get('hr.employee')
+ sheet = self.browse(cr, uid, ids, context=context)[0]
if context is None:
context = {}
- if not self.browse(cr, uid, ids, context=context)[0].date_current == time.strftime('%Y-%m-%d'):
+ if not sheet.date_current == time.strftime('%Y-%m-%d'):
raise osv.except_osv(_('Error !'), _('You can not sign in from an other date than today'))
- emp_ids = emp_obj.search(cr, uid, [('user_id', '=', uid)], context=context)
+ emp_id = sheet.employee_id.id
context['sheet_id']=ids[0]
- emp_obj.attendance_action_change(cr, uid, emp_ids, type='sign_in', context=context,)
+ emp_obj.attendance_action_change(cr, uid, [emp_id], type=typ, context=context,)
return True
+ def sign_in(self, cr, uid, ids, context=None):
+ return self.sign(cr,uid,ids,'sign_in',context=None)
+
def sign_out(self, cr, uid, ids, context=None):
- emp_obj = self.pool.get('hr.employee')
- if context is None:
- context = {}
- if not self.browse(cr, uid, ids, context=context)[0].date_current == time.strftime('%Y-%m-%d'):
- raise osv.except_osv(_('Error !'), _('You can not sign out from an other date than today'))
- emp_ids = emp_obj.search(cr, uid, [('user_id', '=', uid)])
- context['sheet_id']=ids[0]
- emp_obj.attendance_action_change(cr, uid, emp_ids, type='sign_out', context=context,)
- return True
+ return self.sign(cr,uid,ids,'sign_out',context=None)
_columns = {
'name': fields.char('Description', size=64, select=1,
'user_id': fields.related('employee_id', 'user_id', type="many2one", relation="res.users", store=True, string="User", required=False, readonly=True),#fields.many2one('res.users', 'User', required=True, select=1, states={'confirm':[('readonly', True)], 'done':[('readonly', True)]}),
'date_from': fields.date('Date from', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
'date_to': fields.date('Date to', required=True, select=1, readonly=True, states={'new':[('readonly', False)]}),
- 'date_current': fields.date('Current date', required=True),
+ 'date_current': fields.date('Current date', required=True, select=1),
'timesheet_ids' : one2many_mod('hr.analytic.timesheet', 'sheet_id',
'Timesheet lines', domain=[('date', '=', time.strftime('%Y-%m-%d'))],
readonly=True, states={
'draft': [('readonly', False)],
'new': [('readonly', False)]}
),
- 'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True, states={'draft':[('readonly',False)],'new':[('readonly',False)]}),
+ 'attendances_ids' : one2many_mod2('hr.attendance', 'sheet_id', 'Attendances', readonly=True,),
'state' : fields.selection([
('new', 'New'),
('draft','Draft'),
}
def _default_date_from(self,cr, uid, context=None):
- if context is None:
- context = {}
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
r = user.company_id and user.company_id.timesheet_range or 'month'
if r=='month':
return time.strftime('%Y-%m-01')
elif r=='week':
- return (datetime.today() + relativedelta(weekday=0, weeks=-1)).strftime('%Y-%m-%d')
+ return (datetime.today() + relativedelta(weekday=MO(-1))).strftime('%Y-%m-%d')
elif r=='year':
return time.strftime('%Y-01-01')
return time.strftime('%Y-%m-%d')
}
def _sheet_date(self, cr, uid, ids, forced_user_id=False, context=None):
- if not context:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
new_user_id = forced_user_id or sheet.user_id and sheet.user_id.id
if new_user_id:
return True
def _date_current_check(self, cr, uid, ids, context=None):
- if not context:
- context = {}
for sheet in self.browse(cr, uid, ids, context=context):
if sheet.date_current < sheet.date_from or sheet.date_current > sheet.date_to:
return False
return True
def name_get(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
if not len(ids):
return []
return [(r['id'], r['date_from'] + ' - ' + r['date_to']) \
context=context, load='_classic_write')]
def unlink(self, cr, uid, ids, context=None):
- if context is None:
- context = {}
sheets = self.read(cr, uid, ids, ['state','total_attendance'], context=context)
for sheet in sheets:
if sheet['state'] in ('confirm', 'done'):
def _sheet(self, cursor, user, ids, name, args, context=None):
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
- if context is None:
- context = {}
cursor.execute('SELECT l.id, COALESCE(MAX(s.id), 0) \
FROM hr_timesheet_sheet_sheet s \
LEFT JOIN (hr_analytic_timesheet l \
return res
def _sheet_search(self, cursor, user, obj, name, args, context=None):
- if context is None:
- context = {}
if not len(args):
return []
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
return time.strftime('%Y-%m-%d %H:%M:%S')
def _sheet(self, cursor, user, ids, name, args, context=None):
- if context is None:
- context = {}
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
cursor.execute("SELECT a.id, COALESCE(MAX(s.id), 0) \
FROM hr_timesheet_sheet_sheet s \
return []
sheet_obj = self.pool.get('hr_timesheet_sheet.sheet')
- if context is None:
- context = {}
i = 0
while i < len(args):
fargs = args[i][0].split('.', 1)
_columns = {
'name': fields.date('Date', readonly=True),
'sheet_id': fields.many2one('hr_timesheet_sheet.sheet', 'Sheet', readonly=True, select="1"),
- 'total_timesheet': fields.float('Project Timesheet', readonly=True),
+ 'total_timesheet': fields.float('Total Timesheet', readonly=True),
'total_attendance': fields.float('Attendance', readonly=True),
'total_difference': fields.float('Difference', readonly=True),
}