Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- ##############################################################################
- #
- # OpenERP, Open Source Management Solution
- # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- from __future__ import division
- import time
- import math
- import random
- from openerp.osv import fields, osv
- from openerp.tools.translate import _
- from datetime import datetime ,timedelta
- from dateutil.relativedelta import relativedelta
- from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
- from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
- from datetime import datetime
- import xlwt
- from xlwt import Workbook, XFStyle, Borders, Pattern, Font, Alignment, easyxf
- import cStringIO
- import base64, urllib
- class hr_calculate_salary(osv.osv_memory):
- _name = 'hr.calculate.salary1'
- _columns = {
- 'employee_id': fields.many2one('hr.employee','Employee', size=32, ),
- 'holiday_list_id': fields.many2one('holiday.list','Months', size=32, ),
- 'date': fields.date("Date",),
- 'by_month': fields.boolean('By Month'),
- 'address_id' : fields.many2one('res.partner','Working Address'),
- 'category': fields.selection([('worker', 'Worker'), ('staff', 'Staff'), ('contractor', 'Contractor')], 'Category',),
- }
- _defaults={
- #'by_month':True,
- }
- def get_month_year(self ,cr ,uid ,ids ,date ,context=False):
- dict={'holiday_id':[],'day':False,'month':False,'year_id':False}
- tm_tuple = datetime.strptime(str(date),'%Y-%m-%d').timetuple()
- month1 = tm_tuple.tm_mon
- #print "month1............",month1
- year = tm_tuple.tm_year
- #print "year...........",year
- if int(month1) in [1,3,5,7,8,10,12]:
- month = 31
- if int(month1) in [4,6,9,11]:
- month = 30
- if int(month1) in [2]:
- if int(year) % 4 == 0:
- month = 29
- else:
- month = 28
- year_ids=self.pool.get('holiday.year').search(cr ,uid ,[('name','=',int(year))])
- if not year_ids:
- raise osv.except_osv(_('Warning !'),_("First ,Create a holiday year = %s." % (year)))
- holiday_id=self.pool.get('holiday.list').search(cr ,uid ,[('month','=',int(month1)),('year_id','=',year_ids and year_ids[0])])
- if not holiday_id:
- raise osv.except_osv(_('Warning !'),_("No Holidays are defined for month= %s and year = %s." % (month1,int(year))))
- #print "holiday_id................",holiday_id
- dict.update({'holiday_id':holiday_id,'month':month1,'year_id':year_ids,'day':tm_tuple.tm_mday})
- return dict
- def float_time_convert_main(self,float_val):
- factor = float_val < 0 and -1 or 1
- val = abs(float_val)
- return (factor * int(math.floor(val)), int(round((val % 1) * 60)))
- def float_time_convert(self,float_val):
- factor = float_val < 0 and -1 or 1
- val = abs(float_val)
- str_time=str(val % 1).split('.')[1]
- #print "str_time.......",str_time
- return (factor * int(math.floor(val)), int(str_time))
- def calculate_time(self, cr, uid, ids, date, start, end):
- #print "start.........end..",start,end
- time1 = time2 = '00:00'
- val1=self.float_time_convert(float(start))
- #print "val1.........",val1
- if val1 and len(str(val1[1])) == 1:
- time1 = str(val1[0]) +':'+ '0' + str(val1[1])
- if val1 and len(str(val1[1])) == 2:
- time1 = str(val1[0]) +':'+str(val1[1])
- start_hr = val1[0]
- start_time = str(date) +' '+ str(time1) + ':00'
- val2=self.float_time_convert(float(end))
- #print "val2..........",val2
- if val2 and len(str(val2[1])) == 1:
- time2 = str(val2[0]) +':'+ '0' + str(val2[1])
- if val2 and len(str(val2[1])) == 2:
- time2 = str(val2[0]) +':'+str(val2[1])
- end_hr = val2[0]
- #print "start_time...........",start_time
- start_time1 = datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S').timetuple()
- year = start_time1.tm_year
- mon = start_time1.tm_mon
- day = start_time1.tm_mday
- hour = start_time1.tm_hour
- min = start_time1.tm_min
- sec = start_time1.tm_sec
- hour1 = hour
- mon1 = mon
- day1 = day
- year1 = year
- #===========================================================================
- if int(start_hr) > int(end_hr):
- day2 = day + 1
- if mon in [1,3,5,7,8,10,12]:
- if day >= 31:
- day2 = 1
- mon2 = mon + 1
- year2 = year
- if mon2 > 12:
- year2 = year + 1
- mon2 = 1
- else:
- mon2 = mon
- year2 = year
- elif mon in [4,6,9,11]:
- if day >= 30:
- day2 = 1
- mon2 = mon + 1
- year2 = year
- else:
- mon2 = mon
- year2 = year
- elif mon == 2:
- if year % 4 == 0:
- if day >= 29:
- day2 = 1
- mon2 = mon + 1
- year2 = year
- else:
- mon2 = mon
- year2 = year
- else:
- if day >= 28:
- day2 = 1
- mon2 = mon + 1
- year2 = year
- else:
- mon2 = mon
- year2 = year
- time2_split = time2.split(':')
- hour2 = int(end_hr)
- min2 = int(time2_split[1])
- else:
- time2_split = time2.split(':')
- hour2 = int(end_hr)
- min2 = int(time2_split[1])
- mon2 = mon
- day2 = day
- year2 = year
- if (hour + 22) > 24:
- hour = abs(24 - (hour + 22))
- day = day + 1
- if mon in [1,3,5,7,8,10,12]:
- if day > 31:
- day = 1
- mon = mon + 1
- if mon > 12:
- year = year + 1
- mon = 1
- elif mon in [4,6,9,11]:
- if day > 30:
- day = 1
- mon = mon + 1
- elif mon == 2:
- if year % 4 == 0:
- if day > 29:
- day = 1
- mon = mon + 1
- else:
- if day > 28:
- day = 1
- mon = mon + 1
- else:
- hour = hour + 22
- if len(str(mon1)) < 2:
- mon1 = '0'+str(mon1)
- if len(str(day1)) < 2:
- day1 = '0'+str(day1)
- if len(str(mon2)) < 2:
- mon2 = '0'+str(mon2)
- if len(str(day2)) < 2:
- day2 = '0'+str(day2)
- if len(str(mon)) < 2:
- mon = '0'+str(mon)
- if len(str(day)) < 2:
- day = '0'+str(day)
- start_time = str(year1) +'-'+str(mon1)+'-'+str(day1) +' '+ str(hour1)+':'+str(min)+':'+str(sec)
- end_time = str(year2) +'-'+str(mon2)+'-'+str(day2) +' '+ str(hour2)+':'+str(min2)+':'+str('00')
- final_time = str(year) +'-'+str(mon)+'-'+str(day) +' '+ str(hour)+':'+str(min)+':'+str(sec)
- working_time = (datetime.strptime(end_time,'%Y-%m-%d %H:%M:%S') - datetime.strptime(start_time,'%Y-%m-%d %H:%M:%S'))
- working_hour = working_time.total_seconds()/3600
- timing = {
- 'start_time':start_time,
- 'end_time':end_time,
- 'final_time':final_time,
- 'working_hour':working_hour,
- }
- return timing
- def working_hours_on_day(self, cr, uid, resource_calendar_id, day, context=None):
- shift = {
- 'start':0.0,
- 'end':0.0,
- }
- count = 0
- print "Working day "
- for working_day in resource_calendar_id.attendance_ids:
- if count > 1:
- continue
- count += 1
- val1 = self.float_time_convert_main(working_day.hour_from)
- #print "val1.............",val1
- if val1 and len(str(val1[1])) == 1:
- time1 = str(val1[0]) +'.'+str(val1[1]) + '0'
- if val1 and len(str(val1[1])) == 2:
- time1 = str(val1[0]) +'.'+str(val1[1])
- val2 = self.float_time_convert_main(working_day.hour_to)
- #print "val2............",val2
- if val2 and len(str(val2[1])) == 1:
- time2 = str(val2[0]) +'.'+ str(val2[1]) + '0'
- if val2 and len(str(val2[1])) == 2:
- time2 = str(val2[0]) +'.'+str(val2[1])
- shift.update({'start':time1,'end':time2})
- return shift
- def working_hours_on_day_weekly(self, cr, uid, resource_calendar_id, day, context=None):
- shift = {
- 'start':0.0,
- 'end':0.0,
- }
- count = 0
- print "Working day "
- val1 = self.float_time_convert_main(resource_calendar_id.hour_from)
- #print "val1.............",val1
- if val1 and len(str(val1[1])) == 1:
- time1 = str(val1[0]) +'.'+str(val1[1]) + '0'
- if val1 and len(str(val1[1])) == 2:
- time1 = str(val1[0]) +'.'+str(val1[1])
- val2 = self.float_time_convert_main(resource_calendar_id.hour_to)
- #print "val2............",val2
- if val2 and len(str(val2[1])) == 1:
- time2 = str(val2[0]) +'.'+ str(val2[1]) + '0'
- if val2 and len(str(val2[1])) == 2:
- time2 = str(val2[0]) +'.'+str(val2[1])
- shift.update({'start':time1,'end':time2})
- print "========================",shift
- return shift
- def calculate_ot(self ,cr ,uid ,ids ,context=False):
- att_obj = self.pool.get('hr.attendance')
- emp_obj = self.pool.get('hr.employee')
- punch_obj = self.pool.get('hr.punch.card')
- ot_obj = self.pool.get('ot.history')
- employee_id = self.browse(cr ,uid , ids[0]).employee_id
- print "employee_id..........",employee_id
- salary_date= self.browse(cr ,uid , ids[0]).date
- print "salary_date...........",salary_date
- salary_month= self.browse(cr ,uid , ids[0]).holiday_list_id
- print "salary_month...........",salary_month
- # ++++++++++++++ An Employeess For a Date ++++++++++++++++++++++++++++++
- if employee_id:
- if salary_date:
- dict = self.get_month_year(cr ,uid ,ids ,salary_date)
- print "dict................",dict
- ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #print "ot_ids...........",ot_ids
- punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- #print "punch_ids............",punch_ids
- shown_ot=0.0
- not_shown_ot=0.0
- for punch in punch_ids:
- for p in punch_obj.browse(cr ,uid ,[punch]):
- shown_ot += p.new_ot
- not_shown_ot +=p.extra_ot
- if ot_ids:
- ot_obj.write( cr ,uid ,ot_ids ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot})
- else:
- ot_obj.create(cr ,uid ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot,'employee_id':employee_id.id,'month_id':dict['holiday_id'] and dict['holiday_id'][0],})
- print salary_date
- elif salary_month:
- month1=salary_month.month
- print "month1.........",month1
- #print "month......... ",month1
- year=salary_month.year_id.name
- #print "year............",year
- year_ids=self.pool.get('holiday.year').search(cr ,uid ,[('name','=',int(year))])
- #print "year_ids...........",year_ids
- punch_ids=punch_obj.search(cr ,uid ,[('month','=',month1),('year_id','=',year_ids and year_ids[0]),('employee_id','=',employee_id.id)])
- #print "punch_ids............",punch_ids
- holiday_id=self.pool.get('holiday.list').search(cr ,uid ,[('month','=',int(month1)),('year_id','=',salary_month.year_id.id)])
- #print "holiday_id..........",holiday_id
- ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',holiday_id and holiday_id[0]),('employee_id','=',employee_id.id)])
- #print "ot_ids...........",ot_ids
- shown_ot=0.0
- not_shown_ot=0.0
- for punch in punch_ids:
- for p in punch_obj.browse(cr ,uid ,[punch]):
- shown_ot += p.new_ot
- not_shown_ot +=p.extra_ot
- if ot_ids:
- ot_obj.write( cr ,uid ,ot_ids ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot})
- else:
- ot_obj.create(cr ,uid ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot,'employee_id':employee_id.id,'month_id':holiday_id and holiday_id[0],})
- print salary_month
- else:
- if salary_date:
- dict = self.get_month_year(cr ,uid ,ids ,salary_date)
- print "dict................",dict
- emp_list=emp_obj.search(cr,uid,[])
- if 1 in emp_list:
- emp_list.remove(1)
- if emp_list:
- for emp_id in emp_list:
- for emp in emp_obj.browse(cr ,uid ,[emp_id]):
- ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',emp.id)])
- #print "ot_ids...........",ot_ids
- punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',emp.id)])
- #print "punch_ids............",punch_ids
- shown_ot=0.0
- not_shown_ot=0.0
- for punch in punch_ids:
- for p in punch_obj.browse(cr ,uid ,[punch]):
- shown_ot += p.new_ot
- not_shown_ot +=p.extra_ot
- if ot_ids:
- ot_obj.write( cr ,uid ,ot_ids ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot})
- else:
- ot_obj.create(cr ,uid ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot,'employee_id':emp.id,'month_id':dict['holiday_id'] and dict['holiday_id'][0],})
- #print salary_date
- elif salary_month :
- emp_list=emp_obj.search(cr,uid,[])
- if 1 in emp_list:
- emp_list.remove(1)
- month1=salary_month.month
- print "month......... ",month1
- year=salary_month.year_id.name
- #print "year............",year
- year_ids=self.pool.get('holiday.year').search(cr ,uid ,[('name','=',int(year))])
- if emp_list:
- for emp_id in emp_list:
- for emp in emp_obj.browse(cr ,uid ,[emp_id]):
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',month1),('employee_id','=',emp.id)])
- #print "ot_ids...........",ot_ids
- year_ids=self.pool.get('holiday.year').search(cr ,uid ,[('name','=',int(year))])
- punch_ids=punch_obj.search(cr ,uid ,[('month','=',month1),('year_id','=',year_ids and year_ids[0]),('employee_id','=',emp.id)])
- #print "punch_ids............",punch_ids
- holiday_id=self.pool.get('holiday.list').search(cr ,uid ,[('month','=',int(month1)),('year_id','=',salary_month.year_id.id)])
- ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',holiday_id and holiday_id[0]),('employee_id','=',employee_id.id)])
- shown_ot=0.0
- not_shown_ot=0.0
- for punch in punch_ids:
- for p in punch_obj.browse(cr ,uid ,[punch]):
- shown_ot += p.new_ot
- not_shown_ot +=p.extra_ot
- if ot_ids:
- ot_obj.write( cr ,uid ,ot_ids ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot})
- else:
- ot_obj.create(cr ,uid ,{'shown_ot':shown_ot,'extra_ot':not_shown_ot,'employee_id':emp.id,'month_id':holiday_id and holiday_id[0],})
- #print salary_date
- return True
- def timing_main_func(self ,cr ,uid ,ids ,working_hours,salary_date ,context=False):
- shift = {
- 'shift_start':0.0,
- 'shift_end':0.0,
- 'shift_final':0.0,
- }
- shift = self.working_hours_on_day(cr, uid, working_hours, salary_date, context)
- #print "shift............",shift
- start_time = datetime.strptime(str(datetime.strptime(str(salary_date),"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S')),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = str(hour) + '.' + str(min)
- #print "start_time..............",start_time,type(start_time)
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = str(hour) + '.' + str(min)
- #print "start_time......main........",start_time
- #print "end_time................",end_time
- salary_date = str(datetime.strptime(str(salary_date),"%Y-%m-%d").strftime('%Y-%m-%d'))
- #print "salary_date.............",salary_date
- timing_main = self.calculate_time(cr, uid, ids, salary_date, float(start_time), float(end_time))
- #print "timing_main..............",timing_main
- return timing_main
- def timing_main_weekly_func(self ,cr ,uid ,ids ,working_hours,salary_date ,context=False):
- shift = {
- 'shift_start':0.0,
- 'shift_end':0.0,
- 'shift_final':0.0,
- }
- shift = self.working_hours_on_day_weekly(cr, uid, working_hours, salary_date, context)
- #print "shift............",shift
- start_time = datetime.strptime(str(datetime.strptime(str(salary_date),"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S')),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = str(hour) + '.' + str(min)
- #print "start_time..............",start_time,type(start_time)
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = str(hour) + '.' + str(min)
- #print "start_time......main........",start_time
- #print "end_time................",end_time
- salary_date = str(datetime.strptime(str(salary_date),"%Y-%m-%d").strftime('%Y-%m-%d'))
- #print "salary_date.............",salary_date
- timing_main = self.calculate_time(cr, uid, ids, salary_date, float(start_time), float(end_time))
- #print "timing_main..............",timing_main
- return timing_main
- def calculate_punch_card123(self, cr, uid, ids, context=None):
- print "Gaurav"
- att_obj = self.pool.get('hr.attendance')
- punch_obj = self.pool.get('hr.punch.card')
- emp_obj = self.pool.get('hr.employee')
- cont_obj = self.pool.get('hr.contract')
- ot_obj = self.pool.get('ot.history')
- holiday_obj = self.pool.get('holiday.list')
- # ++++++++++++++++ Late Count (Gaurav) ++++++++++++++++++++++++++++
- cur_obj = self.browse(cr ,uid , ids)
- for line in self.browse(cr ,uid , ids):
- print "aaaaaaaaa",line.employee_id
- if line.employee_id:
- employee_id = line.employee_id
- print "=========",employee_id
- else:
- employee_id =False
- #print "employee_id..........",employee_id
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- salary_date= self.browse(cr ,uid , ids[0]).date
- #print "salary_date...........",salary_date
- salary_month= self.browse(cr ,uid , ids[0]).holiday_list_id
- #print "salary_month...........",salary_month
- # ++++++++++++++ An Employeess For a Date ++++++++++++++++++++++++++++++
- print "ewtwwwwwwwwwwwwwwwwww====employee_id======salary_date====="
- if employee_id :
- print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%====employee_id======salary_date====="
- if salary_date:
- print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%====employee_id==========="
- late_count = 0;
- ot_sum_gaurav = 0
- contract_ids = cont_obj.search(cr,uid,[('employee_id','=',employee_id.id)])
- if contract_ids:
- contract_data = cont_obj.browse(cr, uid, contract_ids)[0]
- else:
- raise osv.except_osv(_('Warning !'),_("Contract is missing for employee %s." % (employee_id.name)))
- #print "contract_data..............",contract_data,contract_data.working_hours.name
- if contract_data:
- category = employee_id.category
- timing_main= self.timing_main_func( cr ,uid ,ids ,contract_data.working_hours ,salary_date)
- #print "timing_main...........",timing_main
- total_punch = "select min(name + interval'5 hour 30 minutes') ,max(name + interval'5 hour 30 minutes') from hr_attendance where name + interval '5 hours 30 minute' >= to_timestamp('"+str(timing_main['start_time'])+"',\
- 'YYYY-MM-DD HH24:MI:SS')::timestamp - interval '1 hours 30 minute' and name + interval '5 hours 30 minute' < to_timestamp('"+str(timing_main['final_time'])+"','YYYY-MM-DD HH24:MI:SS')::timestamp and employee_id = \
- '"+str(employee_id.id)+"' "
- cr.execute(total_punch)
- total_punch_result = cr.fetchall()
- for data in total_punch_result:
- if len(data)>1 and data[0] != None and data[1] != None and data[0] != data[1]:
- #if total_punch_result and len(total_punch_result[0]) == 2 and total_punch_result[0][0] != None and total_punch_result[0][1] != None and total_punch_result[0][0] != total_punch_result[0][1]:
- in_punch = data[0]
- #print "in_punch....................",in_punch
- out_punch1 = data[1]
- #print "out_punch1..................",out_punch1
- #category =employee_id.category
- in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "in_time.........",in_time
- out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "out_time.........",out_time
- dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- #print "timing.................",timing
- lunch_mid = late = hard_absent = short_leave = hard_hd = False
- start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- working_main= False
- working_main_first_half = False
- working_main_second_half = False
- lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- elunch = lunch + timedelta(hours=4,minutes=30)
- # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- #print "shift............",shift
- start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "start_time..............",start_time,type(start_time)
- end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "end_time................",end_time
- if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- actual_start = start_time
- else:
- actual_start = in_punch
- #print "actual_start............",actual_start
- if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- actual_end = end_time
- else:
- actual_end = out_punch1
- #print "actual_end.............",actual_end
- # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- #if category == 'staff':
- if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=30)):
- hard_absent =True
- #print "setting absent1...hard_absent =True......."
- working_main='A'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2,minutes=1)):
- #print "setting hd1..........."
- working_main='HD'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- print "setting P1 and late.....492......12"
- working_main ='P'
- late_count = late_count+1
- print "+++++++++++++++++++++++++++++==================================",late_count,in_punch
- late=True
- print "+++++++++++++++++++++++++++++==================================",late_count,in_punch,employee_id.id
- if late_count>=3 and category=='staff':
- working_main ='A'
- leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- if leave_obj1:
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- punch_in_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_in_hd= punch_in_hd.strftime("%Y-%m-%d 00:01:00")
- punch_out_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_out_hd = punch_out_hd.strftime("%Y-%m-%d 00:01:00")
- print "==================================",punch_in_hd,punch_out_hd
- error
- if cl_status[5]['remaining_leaves']>=0.5:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- print "Hiii",create_id
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif ml_status[2]['remaining_leaves']>=0.5:
- print "Ml"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif el_status[6]['remaining_leaves']>=0.5:
- print "El"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- working_main = 'P'
- else:
- #print "setting P1..........."
- working_main ='P'
- if not in_punch and not out_punch1:
- working_main = "A"
- #continue
- #print "working_main..........",working_main
- # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- hard_hd = short_leave = False
- if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- if late_count>=3 and category=='staff':
- print "Late Count Reseted$$$$$$$$$$$$$$$$$$$$$$$",late_count
- working_main = 'A'
- #print "hard hd true....."
- else:
- working_main = 'HD'
- hard_hd = True
- #print "hard_hd......setting...",hard_hd
- elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') )) and \
- (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))):
- #print "short leave true....."
- short_leave = True
- # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # missing = new_hrs_miss = 0.0
- # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # missing = value.total_seconds()
- # #print "missing................",missing
- # miss_min = float(missing / 60)
- # print "miss_min............",miss_min
- # miss_hr = float(miss_min / 60)
- # #print "miss_hr.................",miss_hr
- # miss_hr = divmod(miss_hr,1)[0]
- # #print "miss_hr.................",miss_hr
- # if miss_hr:
- # #print "miss_hr...............",miss_hr
- # nw_min = miss_min - miss_hr * 60
- # #print "nw_min...1............",nw_min
- # else:
- # nw_min = miss_min
- # #print "nw_min......2.........",nw_min
- # nw_min = round(nw_min,0)
- # if nw_min > 5 and nw_min <= 35:
- # nm_min = 0.5
- # elif nw_min > 35:
- # miss_hr = miss_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # print "miss_hr............",miss_hr
- # print "nm_min..............",nm_min
- # new_hrs_miss = miss_hr + nm_min
- # print "new_hrs_miss................",new_hrs_miss
- # if new_hrs_miss < 4.0:
- # working_main ="A"
- # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # working_main ="HD"
- # elif new_hrs_miss >= 6.0 :
- # working_main ="A"
- # print "working_main............",working_main
- # ++++ START TIME & END TIME +++++++++++++++++++
- st= ed= False
- if in_punch:
- st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- if out_punch1:
- ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- #print "ed.................",ed
- #if category == 'staff':
- if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- lunch_mid =True
- # if category != 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- #print "lunch_mid...........",lunch_mid
- # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- new_hrs=0.0
- ot_hr = 0
- ot_min = 0
- if st and ed:
- # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- punch_min = float(working_hour.total_seconds() / 60)
- if lunch_mid:
- punch_min = punch_min - 30.0
- punch_hr = float(punch_min / 60)
- punch_hr = divmod(punch_hr,1)[0]
- if punch_hr:
- nw_min = punch_min - punch_hr * 60
- else:
- nw_min = punch_min
- if nw_min > 24 and nw_min < 55:
- nm_min = 0.5
- elif nw_min >= 55:
- punch_hr = punch_hr + 1
- nm_min = 0.0
- else:
- nm_min = 0.0
- new_hrs = punch_hr + nm_min
- #print "new_hrs..........",new_hrs,type(new_hrs)
- # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- #print "over_time.............",over_time
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- #print "actual ot new_hrs1.........",new_hrs1
- ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot = 0.0
- if ot > 2.0 and ot_sum_gaurav<16:
- extra_ot= float(float(ot -2.0))
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot= 2.0
- if ot_sum_gaurav>15:
- extra_ot= float(float(ot))
- ot = 0.0
- # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- val1=self.float_time_convert_main(ot)
- hr=0
- #print "val1...............",val1
- time1 = 0.0
- if val1 and len(str(val1[1])) == 1:
- hr = 0
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- if val1 and len(str(val1[1])) == 2:
- if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- hr = 0
- else:
- hr = 5
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- ot = time1
- #print "new ot...........",ot
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- #print "new extra_ot..............",extra_ot
- # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- print "working_main............",working_main
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 6.0:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 6.0 :
- working_main = 'P'
- if category == 'worker':
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 7.5:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 7.5 :
- working_main = 'P'
- #print "working setting P....",working_main
- print "hard_absent ,hard_hd ..short_leave.. ",hard_absent ,hard_hd,short_leave
- if working_main == 'P' and hard_hd:
- working_main = 'HD'
- # if working_main == 'HD' and hard_absent:
- # working_main = 'A'
- #print "working main....",working_main
- if new_hrs1 < 0:
- new_hrs1 = 0
- if working_main == 'A':
- short_leave = False
- late = False
- print "working main..working hour...ot.",working_main,new_hrs,new_hrs1
- # print "end_time.............",end_time,type(end_time)
- # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- out_punch2 = out_punch1
- else:
- random_second = random.randrange(1, 59, 1)
- random_min = random.randrange(1, 10, 1)
- if ot_min >= 5 :
- random_min += 30
- else:
- random_min += 0
- #print "random_min..........",random_min
- out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- #print "out_punch2.............",str(out_punch2)
- #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print "out_punch2..........",str(out_punch2)
- in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- #print "ot hr ,ot min......",ot_hr, ot_min
- if category == 'staff':
- extra_ot = 0.0
- ot = 0.0
- if category != 'staff':
- short_leave = False
- late = False
- # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- holiday_flag = False
- if late_count >=3:
- late_count =0
- try:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- #print "deleted ...punch card .............",cr.fetchall()
- #print "going................."
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag = True
- if holiday_flag :
- working_main ='L'
- short_leave = False
- late = False
- if holiday_flag and (category =='worker' or category=='contractor'):
- print "ooooooooooooooooooooooootttttttttMy Block",
- working_main ='L'
- punch_min1 = float(working_hour.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- extra_ot = new_hrs1
- new_hrs = 0
- ot = 0
- print "Punch hr",punch_hr1,new_hrs1
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- 'out_punch2':str(out_punch2),'late':late,})
- print "=========================NEW PUNCH CREATED===========================",created_id
- except Exception,e:
- print "Exception Punch Card Creation...........", e.args
- pass
- else:
- print "IN and Out Pair attendance not found for emp on date......",employee_id.name,salary_date
- return True
- # ++++++++++++++ SINGLE Employee for Whole Month ++++++++++++++++++++++++++++++
- else:
- late_count = 0
- week_days = 0
- week_day = 0
- week_off_first = True
- print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%==============="
- short_leave_late = 0
- ot_sum_gaurav = 0
- month1=salary_month.month
- print "month......... ",month1
- year=salary_month.year_id.name
- print "year............",year
- if int(month1) in [1,3,5,7,8,10,12]:
- month = 31
- if int(month1) in [4,6,9,11]:
- month = 30
- if int(month1) in [2]:
- if int(year) % 4 == 0:
- month = 29
- else:
- month = 28
- day_from = str(year) + '-' + str(month1) + '-' + '01'
- day_from = datetime.strptime(day_from,"%Y-%m-%d")
- print "day_from..............",day_from
- day_to = str(year) + '-' + str(month1) + '-' + str(month)
- day_to = datetime.strptime(day_to,"%Y-%m-%d")
- #print "day_to.....................",day_to
- next_date = day_from
- contract_ids = cont_obj.search(cr,uid,[('employee_id','=',employee_id.id)])
- if contract_ids:
- contract_data = cont_obj.browse(cr, uid, contract_ids)[0]
- else:
- raise osv.except_osv(_('Warning !'),_("Contract is missing for employee %s." % (employee_id.name)))
- #print "contract_data..............",contract_data
- for day in range(0, month):
- #print "next_date.............",next_date
- if contract_data:
- week_day +=1
- termination_date = self.pool.get('hr.employee').browse(cr,uid,employee_id.id).termination_date
- joining_date = self.pool.get('hr.employee').browse(cr,uid,employee_id.id).joining_date
- salary_date = next_date.strftime('%Y-%m-%d')
- flag = 0
- if contract_data.weekly_shedule_id:
- for each in contract_data.weekly_shedule_id.attendance_ids:
- flag = 0
- # print "Gaurav==========123",salary_date,each.dt_from,each.date_to
- date_from_week = datetime.strptime(each.dt_from,DEFAULT_SERVER_DATE_FORMAT).date()
- date_to_week = datetime.strptime(each.date_to,DEFAULT_SERVER_DATE_FORMAT).date()
- salary_date_week = datetime.strptime(str(salary_date),DEFAULT_SERVER_DATE_FORMAT).date()
- time_diff = date_to_week - date_from_week
- diff_day = time_diff.days + (float(time_diff.seconds) / 86400)
- diff_day = round(math.ceil(diff_day))
- # print "Diffre========================",diff_day
- next_date_week = date_from_week
- for day in range(0, int(diff_day+1)):
- if datetime.strptime((next_date_week.strftime('%Y-%m-%d')),"%Y-%m-%d").date() == salary_date_week:
- print "Hello",
- flag=1
- break
- next_date_week += timedelta(days=1)
- if flag == 1:
- print "====Each=========",each,salary_date
- timing_main= self.timing_main_weekly_func( cr ,uid ,ids ,each ,salary_date)
- print "==========Custom======",timing_main
- else:
- timing_main= self.timing_main_func( cr ,uid ,ids ,contract_data.working_hours ,salary_date)
- print "hjhjhjhjhjhjhj",timing_main
- # print "salary_date.............",salary_date
- # att_list=att_obj.search(cr,uid,[('employee_id','=',employee_id.id),('day','=',salary_date)])
- # print "att_list..............",att_list
- category = employee_id.category
- # print "Gaurav====================Working Hours",timing_main
- #print "timing_main...........",timing_main
- total_punch = "select min(name + interval'5 hour 30 minutes') ,max(name + interval'5 hour 30 minutes') from hr_attendance where name + interval '5 hours 30 minute' >= to_timestamp('"+str(timing_main['start_time'])+"',\
- 'YYYY-MM-DD HH24:MI:SS')::timestamp - interval '1 hours 30 minute' and name + interval '5 hours 30 minute' < to_timestamp('"+str(timing_main['final_time'])+"','YYYY-MM-DD HH24:MI:SS')::timestamp and employee_id = \
- '"+str(employee_id.id)+"' "
- cr.execute(total_punch)
- total_punch_result = cr.fetchall()
- # print "Gaurav====================Working Hours",timing_main,total_punch_result
- for data in total_punch_result:
- print "=======================================data",data
- if len(data)>1 and data[0] != None and data[1] != None and data[0] != data[1] and joining_date <= salary_date:
- #if total_punch_result and len(total_punch_result[0]) == 2 and total_punch_result[0][0] != None and total_punch_result[0][1] != None and total_punch_result[0][0] != total_punch_result[0][1]:
- if termination_date:
- if termination_date>=salary_date:
- in_punch = data[0]
- #print "in_punch....................",in_punch
- out_punch1 = data[1]
- #print "out_punch1..................",out_punch1
- #category =employee_id.category
- in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "in_time.........",in_time
- out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "out_time.........",out_time
- dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- #print "timing.................",timing
- lunch_mid = late = hard_absent = short_leave = hard_hd = False
- start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- working_main= False
- working_main_first_half = False
- working_main_second_half = False
- unpaid_flag=False
- third_late = False
- second_short = False
- lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- elunch = lunch + timedelta(hours=4,minutes=30)
- # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- if contract_data.weekly_shedule_id:
- for each in contract_data.weekly_shedule_id.attendance_ids:
- flag = 0
- # print "Gaurav==========123",salary_date,each.dt_from,each.date_to
- date_from_week = datetime.strptime(each.dt_from,DEFAULT_SERVER_DATE_FORMAT).date()
- date_to_week = datetime.strptime(each.date_to,DEFAULT_SERVER_DATE_FORMAT).date()
- salary_date_week = datetime.strptime(str(salary_date),DEFAULT_SERVER_DATE_FORMAT).date()
- time_diff = date_to_week - date_from_week
- diff_day = time_diff.days + (float(time_diff.seconds) / 86400)
- diff_day = round(math.ceil(diff_day))
- # print "Diffre========================",diff_day
- next_date_week = date_from_week
- for day in range(0, int(diff_day+1)):
- if datetime.strptime((next_date_week.strftime('%Y-%m-%d')),"%Y-%m-%d").date() == salary_date_week:
- # print "Hello",
- flag=1
- break
- next_date_week += timedelta(days=1)
- if flag == 1:
- # print "====Each=========",each,salary_date
- shift = self.working_hours_on_day_weekly(cr, uid, each, salary_date, context)
- else:
- shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- # print "shift............",shift,salary_date
- start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # print "start_time..............",start_time,type(start_time)
- end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "end_time................",end_time
- if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- actual_start = start_time
- else:
- actual_start = in_punch
- #print "actual_start............",actual_start
- if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- actual_end = end_time
- else:
- actual_end = out_punch1
- #print "actual_end.............",actual_end
- # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- #if category == 'staff':
- if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=32)):
- hard_absent =True
- #print "setting absent1...hard_absent =True......."
- working_main='A'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2,minutes=1)):
- #print "setting hd1..........."
- working_main='HD'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- print "setting P1 and late..859.........12",in_punch
- # working_main ='P'
- late=True
- late_count = late_count+1
- print "+++++++++++++++++++++++++++++==================================",late_count,in_punch,employee_id.id
- holiday_flag_1=False
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag_1 = True
- if late_count>=3 and category=='staff' and holiday_flag_1==False:
- working_main ='HD'
- punch_in_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_in_hd= punch_in_hd.strftime("%Y-%m-%d 04:00:30")
- punch_out_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_out_hd = punch_out_hd.strftime("%Y-%m-%d 08:10:30")
- print "==================================",punch_in_hd,punch_out_hd
- leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- if leave_obj1:
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- if cl_status[5]['remaining_leaves']>=0.5:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- print "Hiii",create_id
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif ml_status[2]['remaining_leaves']>=0.5:
- print "Ml"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif el_status[6]['remaining_leaves']>=0.5:
- print "El"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- unpaid_flag = True
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- working_main = 'P'
- else:
- #print "setting P1..........."
- working_main ='P'
- if not in_punch and not out_punch1:
- working_main = "A"
- #continue
- #print "working_main..........",working_main
- # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- hard_hd = short_leave = False
- if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- if late_count>=3 and category=='staff':
- print "Late Count Reseted$$$$$$$$$$$$$$$$$$$$$$$",late_count
- working_main = 'HD'
- else:
- #print "hard hd true....."
- working_main = 'HD'
- hard_hd = True
- #print "hard_hd......setting...",hard_hd
- elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') )) and \
- (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=5))):
- #print "short leave true....."
- short_leave = True
- short_leave_late = short_leave_late + 1
- # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # missing = new_hrs_miss = 0.0
- # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # missing = value.total_seconds()
- # #print "missing................",missing
- # miss_min = float(missing / 60)
- # print "miss_min............",miss_min
- # miss_hr = float(miss_min / 60)
- # #print "miss_hr.................",miss_hr
- # miss_hr = divmod(miss_hr,1)[0]
- # #print "miss_hr.................",miss_hr
- # if miss_hr:
- # #print "miss_hr...............",miss_hr
- # nw_min = miss_min - miss_hr * 60
- # #print "nw_min...1............",nw_min
- # else:
- # nw_min = miss_min
- # #print "nw_min......2.........",nw_min
- # nw_min = round(nw_min,0)
- # if nw_min > 5 and nw_min <= 35:
- # nm_min = 0.5
- # elif nw_min > 35:
- # miss_hr = miss_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # print "miss_hr............",miss_hr
- # print "nm_min..............",nm_min
- # new_hrs_miss = miss_hr + nm_min
- # print "new_hrs_miss................",new_hrs_miss
- # if new_hrs_miss < 4.0:
- # working_main ="A"
- # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # working_main ="HD"
- # elif new_hrs_miss >= 6.0 :
- # working_main ="A"
- # print "working_main............",working_main
- # ++++ START TIME & END TIME +++++++++++++++++++
- st= ed= False
- if in_punch:
- st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- if out_punch1:
- ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- #print "ed.................",ed
- #if category == 'staff':
- if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- lunch_mid =True
- # if category != 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- #print "lunch_mid...........",lunch_mid
- # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- new_hrs=0.0
- ot_hr = 0
- ot_min = 0
- if st and ed:
- # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- punch_min = float(working_hour.total_seconds() / 60)
- if category == 'worker' and category=='contractor':
- if lunch_mid:
- punch_min = punch_min - 30.0
- punch_hr = float(punch_min / 60)
- punch_hr = divmod(punch_hr,1)[0]
- if punch_hr:
- nw_min = punch_min - punch_hr * 60
- else:
- nw_min = punch_min
- if nw_min > 24 and nw_min < 55:
- nm_min = 0.5
- elif nw_min >= 55:
- punch_hr = punch_hr + 1
- nm_min = 0.0
- else:
- nm_min = 0.0
- new_hrs = punch_hr + nm_min
- #print "new_hrs..........",new_hrs,type(new_hrs)
- # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- #print "over_time.............",over_time
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- #print "actual ot new_hrs1.........",new_hrs1
- ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot = 0.0
- if ot > 2.0:
- extra_ot= float(float(ot -2.0))
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot= 2.0
- # if ot > 2.0 and ot_sum_gaurav<16:
- # extra_ot= float(float(ot -2.0))
- # #print "ot setting to 2.0...extra_ot...........",extra_ot
- # ot= 2.0
- # if ot_sum_gaurav>15.5:
- # extra_ot= float(float(ot))
- # ot = 0.0
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- print "33333333333333333333333333##################",ot,extra_ot,new_hrs1,ot_sum_gaurav
- ot_sum_gaurav = ot_sum_gaurav+ot
- # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- val1=self.float_time_convert_main(ot)
- hr=0
- #print "val1...............",val1
- time1 = 0.0
- if val1 and len(str(val1[1])) == 1:
- hr = 0
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- if val1 and len(str(val1[1])) == 2:
- if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- hr = 0
- else:
- hr = 5
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- ot = time1
- #print "new ot...........",ot
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- #print "new extra_ot..............",extra_ot
- # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- print "working_main............",working_main
- if category == 'worker' or category == 'contractor' :
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 7.5:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 7.5 :
- working_main = 'P'
- #print "working setting P....",working_main
- if working_main == 'HD' and working_main == 'A':
- working_main = 'A'
- print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%===========fjjjjjjjh====",short_leave_late,short_leave,working_main
- if category == 'staff':
- if new_hrs <= 3.0:
- working_main = 'A'
- # print "===================================",working_main
- # error
- if short_leave_late >= 2 and short_leave == True and category == 'staff':
- second_short = True
- working_main = 'HD'
- working_main_second_half = 'A'
- working_main_first_half ='P'
- if late_count >= 3 and late==True and category == 'staff' and (working_main=='HD' or working_main=='P'):
- third_late = True
- if unpaid_flag == True:
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- else:
- working_main = 'P'
- working_main_first_half = 'L'
- working_main_second_half = 'P'
- print "hard_absent ,hard_hd ..short_leave.. ",hard_absent ,hard_hd,short_leave_late
- if working_main == 'P' and hard_hd:
- working_main = 'HD'
- # if working_main == 'HD' and hard_absent:
- # working_main = 'A'
- #print "working main....",working_main
- if new_hrs1 < 0:
- new_hrs1 = 0
- in_punch_sun = False
- out_punch_sun = False
- if working_main == 'A':
- short_leave = False
- late = False
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_qty = 0.0
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- if leave_search and leave_qty == 0.5:
- working_main_first_half = 'A'
- working_main_second_half= 'L'
- working_main = 'HD'
- in_punch_sun = True
- out_punch_sun = True
- elif leave_search and leave_qty > 0.5:
- working_main_first_half = 'L'
- working_main_second_half= 'L'
- working_main = 'L'
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main_first_half = 'A'
- working_main_second_half= 'A'
- working_main = 'A'
- if working_main == 'P' and third_late==False:
- working_main_first_half = 'P'
- working_main_second_half= 'P'
- if working_main == 'HD' and third_late==False:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date = leave_date + timedelta(hours=03,minutes=00)
- leave_date1 = leave_date + timedelta(hours=23,minutes=00)
- leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- print "time", leave_date
- leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','>=',str(leave_date)),('date_to','<=',str(leave_date1)),('holiday_status_id','!=',9),('employee_id','=',employee_id.id)])
- print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_list:
- leave_qty = self.pool.get('hr.holidays').browse(cr,uid,leave_list[0]).number_of_days_temp
- in_punch_time_in = datetime.strptime(in_punch, DATETIME_FORMAT)
- out_punch_time_out = datetime.strptime(out_punch1, DATETIME_FORMAT)
- time_from = datetime.strptime(str(in_punch_time_in),'%Y-%m-%d %H:%M:%S').timetuple()
- time_to = datetime.strptime(str(out_punch_time_out),'%Y-%m-%d %H:%M:%S').timetuple()
- if (time_from.tm_hour >= 8 and time_from.tm_hour<=17) and (time_to.tm_hour<=17):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_first_half = 'P'
- working_main_second_half= 'L'
- else:
- working_main_first_half= 'P'
- working_main_second_half= 'A'
- elif (time_from.tm_hour >= 10 and time_from.tm_hour<=18) and (time_to.tm_hour<=23):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_second_half = 'P'
- working_main_first_half = 'L'
- else:
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- print "working main..working hour...ot.",working_main,new_hrs,new_hrs1,ot,ot_sum_gaurav
- # print "end_time.............",end_time,type(end_time)
- # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- out_punch2 = out_punch1
- else:
- random_second = random.randrange(1, 59, 1)
- random_min = random.randrange(1, 10, 1)
- if ot_min >= 5 :
- random_min += 30
- else:
- random_min += 0
- #print "random_min..........",random_min
- out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- #print "out_punch2.............",str(out_punch2)
- #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print "out_punch2..........",str(out_punch2)
- in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- #print "ot hr ,ot min......",ot_hr, ot_min
- if (category == 'worker' or category == 'contractor') and (working_main == 'A' or working_main=='L'):
- extra_ot = 0.0
- ot = 0.0
- new_hrs1 = 0.0
- if category == 'staff':
- extra_ot = 0.0
- ot = 0.0
- if category != 'staff':
- short_leave = False
- late = False
- # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- holiday_flag = False
- try:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- #print "deleted ...punch card .............",cr.fetchall()
- #print "going................."
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag = True
- if holiday_flag == True and category == 'staff':
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first =False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- print "========================AAAAAAAAAA==============",int(full_day[0][0]),int((half_day[0][0])/2),total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- if holiday_flag == True and (category =='worker' or category=='contractor'):
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first =False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- # print "======================================",start_date,end_date,total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half ='WO'
- working_main_second_half = 'WO'
- punch_min1 = float(working_hour.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- extra_ot = new_hrs1
- new_hrs = 0
- ot = 0
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- punch_min1 = float(working_hour.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- extra_ot = new_hrs1
- new_hrs = 0
- ot = 0
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- in_punch_sun = True
- out_punch_sun = True
- print "Punch hr",punch_hr1,new_hrs1
- if in_punch_sun == True and out_punch_sun== True:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch)})
- else:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- 'out_punch2':str(out_punch2),'in_punch_custom':str(in_punch),'late':late,})
- print "=========================NEW PUNCH CREATED===========================",created_id
- except Exception,e:
- print "Exception Punch Card Creation...........", e.args
- pass
- else:
- in_punch = data[0]
- #print "in_punch....................",in_punch
- out_punch1 = data[1]
- #print "out_punch1..................",out_punch1
- #category =employee_id.category
- in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "in_time.........",in_time
- out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "out_time.........",out_time
- dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- #print "timing.................",timing
- lunch_mid = late = hard_absent = short_leave = hard_hd = False
- start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- working_main= False
- working_main_first_half = False
- working_main_second_half = False
- unpaid_flag=False
- third_late = False
- second_short = False
- lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- elunch = lunch + timedelta(hours=4,minutes=30)
- # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- if contract_data.weekly_shedule_id:
- for each in contract_data.weekly_shedule_id.attendance_ids:
- flag = 0
- # print "Gaurav==========123",salary_date,each.dt_from,each.date_to
- date_from_week = datetime.strptime(each.dt_from,DEFAULT_SERVER_DATE_FORMAT).date()
- date_to_week = datetime.strptime(each.date_to,DEFAULT_SERVER_DATE_FORMAT).date()
- salary_date_week = datetime.strptime(str(salary_date),DEFAULT_SERVER_DATE_FORMAT).date()
- time_diff = date_to_week - date_from_week
- diff_day = time_diff.days + (float(time_diff.seconds) / 86400)
- diff_day = round(math.ceil(diff_day))
- # print "Diffre========================",diff_day
- next_date_week = date_from_week
- for day in range(0, int(diff_day+1)):
- if datetime.strptime((next_date_week.strftime('%Y-%m-%d')),"%Y-%m-%d").date() == salary_date_week:
- # print "Hello",
- flag=1
- break
- next_date_week += timedelta(days=1)
- if flag == 1:
- # print "====Each=========",each,salary_date
- shift = self.working_hours_on_day_weekly(cr, uid, each, salary_date, context)
- else:
- shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- # print "shift............",shift,salary_date
- start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # print "start_time..............",start_time,type(start_time)
- end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "end_time................",end_time
- if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- actual_start = start_time
- else:
- actual_start = in_punch
- #print "actual_start............",actual_start
- if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- actual_end = end_time
- else:
- actual_end = out_punch1
- #print "actual_end.............",actual_end
- # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- #if category == 'staff':
- if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=32)):
- hard_absent =True
- #print "setting absent1...hard_absent =True......."
- working_main='A'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2,minutes=1)):
- #print "setting hd1..........."
- working_main='HD'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- print "setting P1 and late..859.........12",in_punch
- # working_main ='P'
- late=True
- late_count = late_count+1
- print "+++++++++++++++++++++++++++++==================================",late_count,in_punch,employee_id.id
- holiday_flag_1=False
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag_1 = True
- if late_count>=3 and category=='staff' and holiday_flag_1==False:
- working_main ='HD'
- punch_in_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_in_hd= punch_in_hd.strftime("%Y-%m-%d 04:00:30")
- punch_out_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_out_hd = punch_out_hd.strftime("%Y-%m-%d 08:10:30")
- print "==================================",punch_in_hd,punch_out_hd
- leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- if leave_obj1:
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- if cl_status[5]['remaining_leaves']>=0.5:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- print "Hiii",create_id
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif ml_status[2]['remaining_leaves']>=0.5:
- print "Ml"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif el_status[6]['remaining_leaves']>=0.5:
- print "El"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- unpaid_flag = True
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- working_main = 'P'
- else:
- #print "setting P1..........."
- working_main ='P'
- if not in_punch and not out_punch1:
- working_main = "A"
- #continue
- #print "working_main..........",working_main
- # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- hard_hd = short_leave = False
- if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- if late_count>=3 and category=='staff':
- print "Late Count Reseted$$$$$$$$$$$$$$$$$$$$$$$",late_count
- working_main = 'HD'
- else:
- #print "hard hd true....."
- working_main = 'HD'
- hard_hd = True
- #print "hard_hd......setting...",hard_hd
- elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') )) and \
- (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=5))):
- #print "short leave true....."
- short_leave = True
- short_leave_late = short_leave_late + 1
- # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # missing = new_hrs_miss = 0.0
- # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # missing = value.total_seconds()
- # #print "missing................",missing
- # miss_min = float(missing / 60)
- # print "miss_min............",miss_min
- # miss_hr = float(miss_min / 60)
- # #print "miss_hr.................",miss_hr
- # miss_hr = divmod(miss_hr,1)[0]
- # #print "miss_hr.................",miss_hr
- # if miss_hr:
- # #print "miss_hr...............",miss_hr
- # nw_min = miss_min - miss_hr * 60
- # #print "nw_min...1............",nw_min
- # else:
- # nw_min = miss_min
- # #print "nw_min......2.........",nw_min
- # nw_min = round(nw_min,0)
- # if nw_min > 5 and nw_min <= 35:
- # nm_min = 0.5
- # elif nw_min > 35:
- # miss_hr = miss_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # print "miss_hr............",miss_hr
- # print "nm_min..............",nm_min
- # new_hrs_miss = miss_hr + nm_min
- # print "new_hrs_miss................",new_hrs_miss
- # if new_hrs_miss < 4.0:
- # working_main ="A"
- # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # working_main ="HD"
- # elif new_hrs_miss >= 6.0 :
- # working_main ="A"
- # print "working_main............",working_main
- # ++++ START TIME & END TIME +++++++++++++++++++
- st= ed= False
- if in_punch:
- st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- if out_punch1:
- ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- #print "ed.................",ed
- #if category == 'staff':
- if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- lunch_mid =True
- # if category != 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- #print "lunch_mid...........",lunch_mid
- # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- new_hrs=0.0
- ot_hr = 0
- ot_min = 0
- if st and ed:
- # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- punch_min = float(working_hour.total_seconds() / 60)
- if category == 'worker' and category=='contractor':
- if lunch_mid:
- punch_min = punch_min - 30.0
- punch_hr = float(punch_min / 60)
- punch_hr = divmod(punch_hr,1)[0]
- if punch_hr:
- nw_min = punch_min - punch_hr * 60
- else:
- nw_min = punch_min
- if nw_min > 24 and nw_min < 55:
- nm_min = 0.5
- elif nw_min >= 55:
- punch_hr = punch_hr + 1
- nm_min = 0.0
- else:
- nm_min = 0.0
- new_hrs = punch_hr + nm_min
- #print "new_hrs..........",new_hrs,type(new_hrs)
- # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- #print "over_time.............",over_time
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- #print "actual ot new_hrs1.........",new_hrs1
- ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot = 0.0
- if ot > 2.0:
- extra_ot= float(float(ot -2.0))
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot= 2.0
- # if ot > 2.0 and ot_sum_gaurav<16:
- # extra_ot= float(float(ot -2.0))
- # #print "ot setting to 2.0...extra_ot...........",extra_ot
- # ot= 2.0
- # if ot_sum_gaurav>15.5:
- # extra_ot= float(float(ot))
- # ot = 0.0
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- print "33333333333333333333333333##################",ot,extra_ot,new_hrs1,ot_sum_gaurav
- ot_sum_gaurav = ot_sum_gaurav+ot
- # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- val1=self.float_time_convert_main(ot)
- hr=0
- #print "val1...............",val1
- time1 = 0.0
- if val1 and len(str(val1[1])) == 1:
- hr = 0
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- if val1 and len(str(val1[1])) == 2:
- if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- hr = 0
- else:
- hr = 5
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- ot = time1
- #print "new ot...........",ot
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- #print "new extra_ot..............",extra_ot
- # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- print "working_main............",working_main
- if category == 'worker' or category == 'contractor' :
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 7.5:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 7.5 :
- working_main = 'P'
- #print "working setting P....",working_main
- if working_main == 'HD' and working_main == 'A':
- working_main = 'A'
- print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%===========fjjjjjjjh====",short_leave_late,short_leave,working_main
- if category == 'staff':
- if new_hrs <= 3.0:
- working_main = 'A'
- # print "===================================",working_main
- # error
- if short_leave_late >= 2 and short_leave == True and category == 'staff':
- second_short = True
- working_main = 'HD'
- working_main_second_half = 'A'
- working_main_first_half ='P'
- if late_count >= 3 and late==True and category == 'staff' and (working_main=='HD' or working_main=='P'):
- third_late = True
- if unpaid_flag == True:
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- else:
- working_main = 'P'
- working_main_first_half = 'L'
- working_main_second_half = 'P'
- print "hard_absent ,hard_hd ..short_leave.. ",hard_absent ,hard_hd,short_leave_late
- if working_main == 'P' and hard_hd:
- working_main = 'HD'
- # if working_main == 'HD' and hard_absent:
- # working_main = 'A'
- #print "working main....",working_main
- if new_hrs1 < 0:
- new_hrs1 = 0
- in_punch_sun = False
- out_punch_sun = False
- if working_main == 'A':
- short_leave = False
- late = False
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- if leave_search and leave_qty == 0.5:
- working_main_first_half = 'A'
- working_main_second_half= 'L'
- working_main = 'HD'
- in_punch_sun = True
- out_punch_sun = True
- elif leave_search and leave_qty > 0.5:
- working_main_first_half = 'L'
- working_main_second_half= 'L'
- working_main = 'L'
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main_first_half = 'A'
- working_main_second_half= 'A'
- working_main = 'A'
- if working_main == 'P' and third_late==False:
- working_main_first_half = 'P'
- working_main_second_half= 'P'
- if working_main == 'HD' and third_late==False :
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date = leave_date + timedelta(hours=03,minutes=00)
- leave_date1 = leave_date + timedelta(hours=23,minutes=00)
- leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- print "time", leave_date
- leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','>=',str(leave_date)),('date_to','<=',str(leave_date1)),('holiday_status_id','!=',9),('employee_id','=',employee_id.id)])
- print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_list:
- leave_qty = self.pool.get('hr.holidays').browse(cr,uid,leave_list[0]).number_of_days_temp
- in_punch_time_in = datetime.strptime(in_punch, DATETIME_FORMAT)
- out_punch_time_out = datetime.strptime(out_punch1, DATETIME_FORMAT)
- time_from = datetime.strptime(str(in_punch_time_in),'%Y-%m-%d %H:%M:%S').timetuple()
- time_to = datetime.strptime(str(out_punch_time_out),'%Y-%m-%d %H:%M:%S').timetuple()
- if (time_from.tm_hour >= 8 and time_from.tm_hour<=17) and (time_to.tm_hour<=17):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_first_half = 'P'
- working_main_second_half= 'L'
- else:
- working_main_first_half= 'P'
- working_main_second_half= 'A'
- elif (time_from.tm_hour >= 10 and time_from.tm_hour<=18) and (time_to.tm_hour<=23):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_second_half = 'P'
- working_main_first_half = 'L'
- else:
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- print "working main..working hour...ot.",working_main,new_hrs,new_hrs1,ot,ot_sum_gaurav
- # print "end_time.............",end_time,type(end_time)
- # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- out_punch2 = out_punch1
- else:
- random_second = random.randrange(1, 59, 1)
- random_min = random.randrange(1, 10, 1)
- if ot_min >= 5 :
- random_min += 30
- else:
- random_min += 0
- #print "random_min..........",random_min
- out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- #print "out_punch2.............",str(out_punch2)
- #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print "out_punch2..........",str(out_punch2)
- in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- #print "ot hr ,ot min......",ot_hr, ot_min
- if (category == 'worker' or category == 'contractor') and (working_main == 'A' or working_main=='L'):
- extra_ot = 0.0
- ot = 0.0
- new_hrs1 = 0.0
- if category == 'staff':
- extra_ot = 0.0
- ot = 0.0
- if category != 'staff':
- short_leave = False
- late = False
- # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- holiday_flag = False
- try:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- #print "deleted ...punch card .............",cr.fetchall()
- #print "going................."
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag = True
- if holiday_flag == True and category == 'staff':
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- print "========================AAAAAAAAAA==============",int(full_day[0][0]),int((half_day[0][0])/2),total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- if holiday_flag == True and (category =='worker' or category=='contractor'):
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- # print "======================================",start_date,end_date,total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half ='WO'
- working_main_second_half = 'WO'
- over_time=datetime.strptime(str( datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") + timedelta(hours=5,minutes=30)),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_start),"%Y-%m-%d %H:%M:%S")
- print "over_time.............",over_time,out_punch1,actual_start
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- print "actual ot new_hrs1.........",new_hrs1
- # ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot= float(float(new_hrs1))
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- ot = 0.0
- new_hrs = 0.0
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- over_time=datetime.strptime(str( datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") + timedelta(hours=5,minutes=30)),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_start),"%Y-%m-%d %H:%M:%S")
- print "over_time.............",over_time,out_punch1,actual_start
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- print "actual ot new_hrs1.........",new_hrs1
- # ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot= float(float(new_hrs1))
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- ot = 0.0
- new_hrs = 0.0
- in_punch_sun = True
- out_punch_sun = True
- print "Punch hr",punch_hr1,new_hrs1
- if in_punch_sun == True and out_punch_sun== True:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch)})
- else:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- 'out_punch2':str(out_punch2),'in_punch_custom':str(in_punch),'late':late,})
- print "=========================NEW PUNCH CREATED===========================",created_id
- except Exception,e:
- print "Exception Punch Card Creation...........", e.args
- pass
- else:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- cr.execute(""" select h_line.leave_date,h_line.national_holiday from holiday_list_lines as h_line left join holiday_list as h_list on (h_line.holiday_id = h_list.id)
- where h_list.month ='"""+str(salary_month.month)+"""' and h_list.year_id ='"""+str(salary_month.year_id.id)+"""' group by h_line.leave_date,h_line.national_holiday
- """)
- temp1 = cr.fetchall()
- sunday_list = {}
- flag = False
- for each in temp1:
- sunday_list.update({each[0]:each[1]})
- for key,val in sunday_list.items():
- print "=========",week_days
- if salary_date == key and val == False and joining_date <= salary_date:
- if termination_date:
- if termination_date >=salary_date:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working = 'L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- print "=====================AAA=================",int(full_day[0][0]),float((half_day[0][0])/2),start_date,end_date,total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main = 'WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- print "Sunday======================================="
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'S'
- working_main_first_half = 'S'
- working_main_second_half = 'S'
- print "Sunday======================================="
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L' ) and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- print "=========================",half_day[0][0]/2,int(half_day[0][0])/2
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- print "========================AAAAAAAAAA==============",leave_first
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- print "========================AAAAAAAAAA==============",leave_first,week_off_first,total_day_week,leave_first
- print "=====================AAA=================",int(full_day[0][0]),float((half_day[0][0])/2),start_date,end_date,total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main = 'WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- print "Sunday======================================="
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'S'
- working_main_first_half = 'S'
- working_main_second_half = 'S'
- print "Sunday=======================================",total_day_week,end_date
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- elif salary_date == key and val == True and joining_date <= salary_date :
- if termination_date :
- if termination_date >= salary_date:
- working_main = 'H'
- working_main_first_half = 'H'
- working_main_second_half = 'H'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'H'
- working_main_first_half = 'H'
- working_main_second_half = 'H'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- if salary_date not in sunday_list.keys() and joining_date <= salary_date :
- if termination_date:
- if termination_date >= salary_date:
- leave_qty = 0.0
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- print "select date_from,number_of_days_temp,date_to from hr_holidays where (date_from <= '"+time_to+"' and date_to >='"+time_from+"') and employee_id = '"+str(employee_id.id)+"'"
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- print "leave_search",leave_search
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- print "===============Leave",leave_qty
- if leave_qty > 0.5:
- week_days +=1
- working_main = 'L'
- working_main_first_half = 'L'
- working_main_second_half = 'L'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- elif leave_qty == 0.5:
- week_days +=1
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'A'
- working_main_first_half = 'A'
- working_main_second_half = 'A'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- leave_qty = 0.0
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- print "select date_from,number_of_days_temp,date_to from hr_holidays where (date_from <= '"+time_to+"' and date_to >='"+time_from+"') and employee_id = '"+str(employee_id.id)+"'"
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- print "leave_search",leave_search
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- print "===============Leave",leave_qty
- if leave_qty > 0.5:
- week_days +=1
- working_main = 'L'
- working_main_first_half = 'L'
- working_main_second_half = 'L'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- elif leave_qty == 0.5:
- week_days +=1
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'A'
- working_main_first_half = 'A'
- working_main_second_half = 'A'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- print "IN and Out Pair attendance not found for emp on date......",employee_id,salary_date
- next_date += timedelta(days=1)
- # ++++++++++++++ All EMPLOYEES FOR A DATE ++++++++++++++++++++++++++++++
- elif salary_date:
- print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%============salary_date==="
- emp_list=emp_obj.search(cr,uid,[('active','=',True)])
- #print "emp_list..............",emp_list
- # month1=salary_month.month
- # print "month......... ",month1
- # year=salary_month.year_id.name
- # print "year............",year
- # if int(month1) in [1,3,5,7,8,10,12]:
- # month = 31
- # if int(month1) in [4,6,9,11]:
- # month = 30
- # if int(month1) in [2]:
- # if int(year) % 4 == 0:
- # month = 29
- # else:
- # month = 28
- if 1 in emp_list:
- emp_list.remove(1)
- if emp_list:
- for emp in emp_list:
- late_count = 0;
- ot_sum_gaurav = 0
- employee_id=emp_obj.browse(cr ,uid ,emp )
- category = employee_id.category
- att_list=att_obj.search(cr,uid,[('employee_id','=',employee_id.id),('day','=',salary_date)])
- print "att_list.........",att_list
- # day_from = str(year) + '-' + str(month1) + '-' + '01'
- # day_from = datetime.strptime(day_from,"%Y-%m-%d")
- # print "day_from..............",day_from
- # day_to = str(year) + '-' + str(month1) + '-' + str(month)
- # day_to = datetime.strptime(day_to,"%Y-%m-%d")
- # print "day_to.....................",day_to
- # next_date = day_from.strftime('%Y-%m-%d')
- contract_ids = cont_obj.search(cr,uid,[('employee_id','=',employee_id.id)])
- if contract_ids:
- contract_data = cont_obj.browse(cr, uid, contract_ids)[0]
- else:
- raise osv.except_osv(_('Warning !'),_("Contract is missing for employee %s." % (employee_id.name)))
- #print "contract_data..............",contract_data
- # for day in range(0, month):
- # print "next_date.............",next_date
- if contract_data:
- #salary_date = next_date.strftime('%Y-%m-%d')
- category = employee_id.category
- timing_main= self.timing_main_func( cr ,uid ,ids ,contract_data.working_hours ,salary_date)
- #print "timing_main...........",timing_main
- total_punch = "select min(name + interval'5 hour 30 minutes') ,max(name + interval'5 hour 30 minutes') from hr_attendance where name + interval '5 hours 30 minute' >= to_timestamp('"+str(timing_main['start_time'])+"',\
- 'YYYY-MM-DD HH24:MI:SS')::timestamp - interval '1 hours 30 minute' and name + interval '5 hours 30 minute' < to_timestamp('"+str(timing_main['final_time'])+"','YYYY-MM-DD HH24:MI:SS')::timestamp and employee_id = \
- '"+str(employee_id.id)+"' "
- cr.execute(total_punch)
- total_punch_result = cr.fetchall()
- for data in total_punch_result:
- if len(data)>1 and data[0] != None and data[1] != None and data[0] != data[1]:
- #if total_punch_result and len(total_punch_result[0]) == 2 and total_punch_result[0][0] != None and total_punch_result[0][1] != None and total_punch_result[0][0] != total_punch_result[0][1]:
- in_punch = data[0]
- #print "in_punch....................",in_punch
- out_punch1 = data[1]
- #print "out_punch1..................",out_punch1
- #category =employee_id.category
- in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "in_time.........",in_time
- out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "out_time.........",out_time
- dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- #print "timing.................",timing
- lunch_mid = late = hard_absent = short_leave = hard_hd = False
- start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- working_main= False
- lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- elunch = lunch + timedelta(hours=4,minutes=30)
- # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- #print "shift............",shift
- start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "start_time..............",start_time,type(start_time)
- end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "end_time................",end_time
- if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- actual_start = start_time
- else:
- actual_start = in_punch
- #print "actual_start............",actual_start
- if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- actual_end = end_time
- else:
- actual_end = out_punch1
- #print "actual_end.............",actual_end
- # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- #if category == 'staff':
- if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=30)):
- hard_absent =True
- #print "setting absent1...hard_absent =True......."
- working_main='A'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2,minutes=1)):
- #print "setting hd1..........."
- working_main='HD'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- print "setting P1 and late..1230........."
- working_main ='P'
- late_count = late_count+1
- print "+++++++++++++++++++++++++++++==================================",late_count
- late=True
- print "+++++++++++++++++++++++++++++==================================",late_count,in_punch,employee_id.id
- if late_count>=3 and category=='staff':
- working_main ='HD'
- leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- if leave_obj1:
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- if cl_status[5]['remaining_leaves']>=0.5:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- print "Hiii",create_id
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif ml_status[2]['remaining_leaves']>=0.5:
- print "Ml"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif el_status[6]['remaining_leaves']>=0.5:
- print "El"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- working_main = 'P'
- else:
- #print "setting P1..........."
- working_main ='P'
- if not in_punch and not out_punch1:
- working_main = "A"
- #continue
- #print "working_main..........",working_main
- # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- hard_hd = short_leave = False
- if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- if late_count>=3 and category=='staff':
- print "Late Count Reseted$$$$$$$$$$$$$$$$$$$$$$$",late_count
- working_main = 'A'
- else:
- working_main = 'HD'
- hard_hd = True
- #print "hard_hd......setting...",hard_hd
- elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') )) and \
- (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))):
- #print "short leave true....."
- short_leave = True
- # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # missing = new_hrs_miss = 0.0
- # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # missing = value.total_seconds()
- # #print "missing................",missing
- # miss_min = float(missing / 60)
- # print "miss_min............",miss_min
- # miss_hr = float(miss_min / 60)
- # #print "miss_hr.................",miss_hr
- # miss_hr = divmod(miss_hr,1)[0]
- # #print "miss_hr.................",miss_hr
- # if miss_hr:
- # #print "miss_hr...............",miss_hr
- # nw_min = miss_min - miss_hr * 60
- # #print "nw_min...1............",nw_min
- # else:
- # nw_min = miss_min
- # #print "nw_min......2.........",nw_min
- # nw_min = round(nw_min,0)
- # if nw_min > 5 and nw_min <= 35:
- # nm_min = 0.5
- # elif nw_min > 35:
- # miss_hr = miss_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # print "miss_hr............",miss_hr
- # print "nm_min..............",nm_min
- # new_hrs_miss = miss_hr + nm_min
- # print "new_hrs_miss................",new_hrs_miss
- # if new_hrs_miss < 4.0:
- # working_main ="A"
- # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # working_main ="HD"
- # elif new_hrs_miss >= 6.0 :
- # working_main ="A"
- # print "working_main............",working_main
- # ++++ START TIME & END TIME +++++++++++++++++++
- st= ed= False
- if in_punch:
- st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- if out_punch1:
- ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- #print "ed.................",ed
- #if category == 'staff':
- if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- lunch_mid =True
- # if category != 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- #print "lunch_mid...........",lunch_mid
- # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- new_hrs=0.0
- ot_hr = 0
- ot_min = 0
- if st and ed:
- # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- punch_min = float(working_hour.total_seconds() / 60)
- if lunch_mid:
- punch_min = punch_min - 30.0
- punch_hr = float(punch_min / 60)
- punch_hr = divmod(punch_hr,1)[0]
- if punch_hr:
- nw_min = punch_min - punch_hr * 60
- else:
- nw_min = punch_min
- if nw_min > 24 and nw_min < 55:
- nm_min = 0.5
- elif nw_min >= 55:
- punch_hr = punch_hr + 1
- nm_min = 0.0
- else:
- nm_min = 0.0
- new_hrs = punch_hr + nm_min
- #print "new_hrs..........",new_hrs,type(new_hrs)
- # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- #print "over_time.............",over_time
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- #print "actual ot new_hrs1.........",new_hrs1
- ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot = 0.0
- if ot > 2.0 and ot_sum_gaurav<16:
- extra_ot= float(float(ot -2.0))
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot= 2.0
- if ot_sum_gaurav>16:
- extra_ot= float(float(ot))
- ot = 0.0
- # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- val1=self.float_time_convert_main(ot)
- hr=0
- #print "val1...............",val1
- time1 = 0.0
- if val1 and len(str(val1[1])) == 1:
- hr = 0
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- if val1 and len(str(val1[1])) == 2:
- if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- hr = 0
- else:
- hr = 5
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- ot = time1
- #print "new ot...........",ot
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- #print "new extra_ot..............",extra_ot
- # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- print "working_main............",working_main
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 6.0:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 6.0 :
- working_main = 'P'
- if category == 'worker':
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 7.5:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 7.5 :
- working_main = 'P'
- #print "working setting P....",working_main
- print "hard_absent ,hard_hd ..short_leave.. ",hard_absent ,hard_hd,short_leave
- if working_main == 'P' and hard_hd:
- working_main = 'HD'
- # if working_main == 'HD' and hard_absent:
- # working_main = 'A'
- #print "working main....",working_main
- if new_hrs1 < 0:
- new_hrs1 = 0
- if working_main == 'A':
- short_leave = False
- late = False
- print "working main..working hour...ot.",working_main,new_hrs,new_hrs1
- # print "end_time.............",end_time,type(end_time)
- # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- out_punch2 = out_punch1
- else:
- random_second = random.randrange(1, 59, 1)
- random_min = random.randrange(1, 10, 1)
- if ot_min >= 5 :
- random_min += 30
- else:
- random_min += 0
- #print "random_min..........",random_min
- out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- #print "out_punch2.............",str(out_punch2)
- #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print "out_punch2..........",str(out_punch2)
- in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- #print "ot hr ,ot min......",ot_hr, ot_min
- if category == 'staff':
- extra_ot = 0.0
- ot = 0.0
- if category != 'staff':
- short_leave = False
- late = False
- # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- holiday_flag = False
- if late_count >=3:
- late_count =0
- try:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- #print "deleted ...punch card .............",cr.fetchall()
- #print "going................."
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag = True
- if holiday_flag :
- working_main ='L'
- short_leave = False
- late = False
- if holiday_flag and (category =='worker' or category=='contractor'):
- print "ooooooooooooooooooooooootttttttttMy Block",
- working_main ='L'
- punch_min1 = float(working_hour.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- extra_ot = new_hrs1
- new_hrs = 0
- ot = 0
- print "Punch hr",punch_hr1,new_hrs1
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- 'out_punch2':str(out_punch2),'late':late,})
- print "=========================NEW PUNCH CREATED===========================",created_id
- except Exception,e:
- print "Exception Punch Card Creation...........", e.args
- pass
- else:
- print "IN and Out Pair attendance not found for emp on date......",employee_id.name,salary_date
- #+++++++++++++++++++ ALL EMPLOYEES FOR WHOLE MONTH +++++++++++++++++
- else:
- #return True
- week_days = 0
- week_day = 0
- cur_obj = self.browse(cr ,uid , ids[0])
- address_id = cur_obj.address_id
- category_id = self.browse(cr ,uid , ids[0]).category
- emp_list=emp_obj.search(cr,uid,[('active','=',True),('category','=',category_id)])
- # emp_list=emp_obj.search(cr,uid,[('active','=',False),('termination_date','>','2015-03-31'),('joining_date','<','2015-05-01'),('category','=','contractor')])
- # emp_list = [34]
- # emp_list.append(emp_list_false)
- if 1 in emp_list:
- emp_list.remove(1)
- for emp in emp_obj.search(cr,uid,[('category','=',False)]):
- if emp in emp_list:
- emp_list.remove(emp)
- i = 0
- for each in emp_list:
- i = i+1
- employee_id = self.pool.get('hr.employee').browse(cr,uid,each)
- late_count = 0;
- week_off_first = True
- short_leave_late = 0
- ot_sum_gaurav = 0
- month1=salary_month.month
- year=salary_month.year_id.name
- if int(month1) in [1,3,5,7,8,10,12]:
- month = 31
- if int(month1) in [4,6,9,11]:
- month = 30
- if int(month1) in [2]:
- if int(year) % 4 == 0:
- month = 29
- else:
- month = 28
- day_from = str(year) + '-' + str(month1) + '-' + '01'
- day_from = datetime.strptime(day_from,"%Y-%m-%d")
- day_to = str(year) + '-' + str(month1) + '-' + str(month)
- day_to = datetime.strptime(day_to,"%Y-%m-%d")
- #print "day_to.....................",day_to
- next_date = day_from
- contract_ids = cont_obj.search(cr,uid,[('employee_id','=',employee_id.id)])
- if contract_ids:
- contract_data = cont_obj.browse(cr, uid, contract_ids)[0]
- else:
- raise osv.except_osv(_('Warning !'),_("Contract is missing for employee %s." % (employee_id.name)))
- #print "contract_data..............",contract_data
- for day in range(0, month):
- #print "next_date.............",next_date
- if contract_data:
- week_day +=1
- termination_date = self.pool.get('hr.employee').browse(cr,uid,employee_id.id).termination_date
- joining_date = self.pool.get('hr.employee').browse(cr,uid,employee_id.id).joining_date
- salary_date = next_date.strftime('%Y-%m-%d')
- print "Employee==========================N0",i,"Employee code",employee_id.name,salary_date
- flag = 0
- if contract_data.weekly_shedule_id:
- for each in contract_data.weekly_shedule_id.attendance_ids:
- flag = 0
- # print "Gaurav==========123",salary_date,each.dt_from,each.date_to
- date_from_week = datetime.strptime(each.dt_from,DEFAULT_SERVER_DATE_FORMAT).date()
- date_to_week = datetime.strptime(each.date_to,DEFAULT_SERVER_DATE_FORMAT).date()
- salary_date_week = datetime.strptime(str(salary_date),DEFAULT_SERVER_DATE_FORMAT).date()
- time_diff = date_to_week - date_from_week
- diff_day = time_diff.days + (float(time_diff.seconds) / 86400)
- diff_day = round(math.ceil(diff_day))
- # print "Diffre========================",diff_day
- next_date_week = date_from_week
- for day in range(0, int(diff_day+1)):
- if datetime.strptime((next_date_week.strftime('%Y-%m-%d')),"%Y-%m-%d").date() == salary_date_week:
- print "Hello",
- flag=1
- break
- next_date_week += timedelta(days=1)
- if flag == 1:
- print "====Each=========",each,salary_date
- timing_main= self.timing_main_weekly_func( cr ,uid ,ids ,each ,salary_date)
- print "==========Custom======",timing_main
- else:
- timing_main= self.timing_main_func( cr ,uid ,ids ,contract_data.working_hours ,salary_date)
- print "hjhjhjhjhjhjhj",timing_main
- # print "salary_date.............",salary_date
- # att_list=att_obj.search(cr,uid,[('employee_id','=',employee_id.id),('day','=',salary_date)])
- # print "att_list..............",att_list
- category = employee_id.category
- # print "Gaurav====================Working Hours",timing_main
- #print "timing_main...........",timing_main
- total_punch = "select min(name + interval'5 hour 30 minutes') ,max(name + interval'5 hour 30 minutes') from hr_attendance where name + interval '5 hours 30 minute' >= to_timestamp('"+str(timing_main['start_time'])+"',\
- 'YYYY-MM-DD HH24:MI:SS')::timestamp - interval '1 hours 30 minute' and name + interval '5 hours 30 minute' < to_timestamp('"+str(timing_main['final_time'])+"','YYYY-MM-DD HH24:MI:SS')::timestamp and employee_id = \
- '"+str(employee_id.id)+"' "
- cr.execute(total_punch)
- total_punch_result = cr.fetchall()
- # print "Gaurav====================Working Hours",timing_main,total_punch_result
- for data in total_punch_result:
- if len(data)>1 and data[0] != None and data[1] != None and data[0] != data[1] and joining_date <= salary_date:
- #if total_punch_result and len(total_punch_result[0]) == 2 and total_punch_result[0][0] != None and total_punch_result[0][1] != None and total_punch_result[0][0] != total_punch_result[0][1]:
- if termination_date:
- if termination_date>=salary_date:
- in_punch = data[0]
- #print "in_punch....................",in_punch
- out_punch1 = data[1]
- #print "out_punch1..................",out_punch1
- #category =employee_id.category
- in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "in_time.........",in_time
- out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "out_time.........",out_time
- dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- #print "timing.................",timing
- lunch_mid = late = hard_absent = short_leave = hard_hd = False
- start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- working_main= False
- working_main_first_half = False
- working_main_second_half = False
- unpaid_flag=False
- third_late = False
- second_short = False
- lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- elunch = lunch + timedelta(hours=4,minutes=30)
- # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- if contract_data.weekly_shedule_id:
- for each in contract_data.weekly_shedule_id.attendance_ids:
- flag = 0
- # print "Gaurav==========123",salary_date,each.dt_from,each.date_to
- date_from_week = datetime.strptime(each.dt_from,DEFAULT_SERVER_DATE_FORMAT).date()
- date_to_week = datetime.strptime(each.date_to,DEFAULT_SERVER_DATE_FORMAT).date()
- salary_date_week = datetime.strptime(str(salary_date),DEFAULT_SERVER_DATE_FORMAT).date()
- time_diff = date_to_week - date_from_week
- diff_day = time_diff.days + (float(time_diff.seconds) / 86400)
- diff_day = round(math.ceil(diff_day))
- # print "Diffre========================",diff_day
- next_date_week = date_from_week
- for day in range(0, int(diff_day+1)):
- if datetime.strptime((next_date_week.strftime('%Y-%m-%d')),"%Y-%m-%d").date() == salary_date_week:
- # print "Hello",
- flag=1
- break
- next_date_week += timedelta(days=1)
- if flag == 1:
- # print "====Each=========",each,salary_date
- shift = self.working_hours_on_day_weekly(cr, uid, each, salary_date, context)
- else:
- shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- # print "shift............",shift,salary_date
- start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # print "start_time..............",start_time,type(start_time)
- end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "end_time................",end_time
- if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- actual_start = start_time
- else:
- actual_start = in_punch
- #print "actual_start............",actual_start
- if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- actual_end = end_time
- else:
- actual_end = out_punch1
- #print "actual_end.............",actual_end
- # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- #if category == 'staff':
- if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=32)):
- hard_absent =True
- #print "setting absent1...hard_absent =True......."
- working_main='A'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2,minutes=1)):
- #print "setting hd1..........."
- working_main='HD'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- print "setting P1 and late..859.........12",in_punch
- # working_main ='P'
- late=True
- late_count = late_count+1
- print "+++++++++++++++++++++++++++++==================================",late_count,in_punch,employee_id.id
- holiday_flag_1=False
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag_1 = True
- if late_count>=3 and category=='staff' and holiday_flag_1==False:
- working_main ='HD'
- punch_in_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_in_hd= punch_in_hd.strftime("%Y-%m-%d 04:00:30")
- punch_out_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_out_hd = punch_out_hd.strftime("%Y-%m-%d 08:10:30")
- leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- if leave_obj1:
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- if cl_status[5]['remaining_leaves']>=0.5:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- print "Hiii",create_id
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif ml_status[2]['remaining_leaves']>=0.5:
- print "Ml"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif el_status[6]['remaining_leaves']>=0.5:
- print "El"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- unpaid_flag = True
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- working_main = 'P'
- else:
- #print "setting P1..........."
- working_main ='P'
- if not in_punch and not out_punch1:
- working_main = "A"
- #continue
- #print "working_main..........",working_main
- # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- hard_hd = short_leave = False
- if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- if late_count>=3 and category=='staff':
- working_main = 'HD'
- else:
- #print "hard hd true....."
- working_main = 'HD'
- hard_hd = True
- #print "hard_hd......setting...",hard_hd
- elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') )) and \
- (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=5))):
- #print "short leave true....."
- short_leave = True
- short_leave_late = short_leave_late + 1
- # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # missing = new_hrs_miss = 0.0
- # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # missing = value.total_seconds()
- # #print "missing................",missing
- # miss_min = float(missing / 60)
- # print "miss_min............",miss_min
- # miss_hr = float(miss_min / 60)
- # #print "miss_hr.................",miss_hr
- # miss_hr = divmod(miss_hr,1)[0]
- # #print "miss_hr.................",miss_hr
- # if miss_hr:
- # #print "miss_hr...............",miss_hr
- # nw_min = miss_min - miss_hr * 60
- # #print "nw_min...1............",nw_min
- # else:
- # nw_min = miss_min
- # #print "nw_min......2.........",nw_min
- # nw_min = round(nw_min,0)
- # if nw_min > 5 and nw_min <= 35:
- # nm_min = 0.5
- # elif nw_min > 35:
- # miss_hr = miss_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # print "miss_hr............",miss_hr
- # print "nm_min..............",nm_min
- # new_hrs_miss = miss_hr + nm_min
- # print "new_hrs_miss................",new_hrs_miss
- # if new_hrs_miss < 4.0:
- # working_main ="A"
- # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # working_main ="HD"
- # elif new_hrs_miss >= 6.0 :
- # working_main ="A"
- # print "working_main............",working_main
- # ++++ START TIME & END TIME +++++++++++++++++++
- st= ed= False
- if in_punch:
- st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- if out_punch1:
- ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- #print "ed.................",ed
- #if category == 'staff':
- if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- lunch_mid =True
- # if category != 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- #print "lunch_mid...........",lunch_mid
- # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- new_hrs=0.0
- ot_hr = 0
- ot_min = 0
- if st and ed:
- # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- punch_min = float(working_hour.total_seconds() / 60)
- if category == 'worker' and category=='contractor':
- if lunch_mid:
- punch_min = punch_min - 30.0
- punch_hr = float(punch_min / 60)
- punch_hr = divmod(punch_hr,1)[0]
- if punch_hr:
- nw_min = punch_min - punch_hr * 60
- else:
- nw_min = punch_min
- if nw_min > 24 and nw_min < 55:
- nm_min = 0.5
- elif nw_min >= 55:
- punch_hr = punch_hr + 1
- nm_min = 0.0
- else:
- nm_min = 0.0
- new_hrs = punch_hr + nm_min
- #print "new_hrs..........",new_hrs,type(new_hrs)
- # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- #print "over_time.............",over_time
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- #print "actual ot new_hrs1.........",new_hrs1
- ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot = 0.0
- if ot > 2.0:
- extra_ot= float(float(ot -2.0))
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot= 2.0
- # if ot > 2.0 and ot_sum_gaurav<16:
- # extra_ot= float(float(ot -2.0))
- # #print "ot setting to 2.0...extra_ot...........",extra_ot
- # ot= 2.0
- # if ot_sum_gaurav>15.5:
- # extra_ot= float(float(ot))
- # ot = 0.0
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot_sum_gaurav = ot_sum_gaurav+ot
- # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- val1=self.float_time_convert_main(ot)
- hr=0
- #print "val1...............",val1
- time1 = 0.0
- if val1 and len(str(val1[1])) == 1:
- hr = 0
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- if val1 and len(str(val1[1])) == 2:
- if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- hr = 0
- else:
- hr = 5
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- ot = time1
- #print "new ot...........",ot
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- #print "new extra_ot..............",extra_ot
- # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- if category == 'worker' or category == 'contractor' :
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 7.5:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 7.5 :
- working_main = 'P'
- #print "working setting P....",working_main
- if working_main == 'HD' and working_main == 'A':
- working_main = 'A'
- if category == 'staff':
- if new_hrs <= 3.0:
- working_main = 'A'
- # print "===================================",working_main
- # error
- if short_leave_late >= 2 and short_leave == True and category == 'staff':
- second_short = True
- working_main = 'HD'
- working_main_second_half = 'A'
- working_main_first_half ='P'
- if late_count >= 3 and late==True and category == 'staff' and (working_main=='HD' or working_main=='P'):
- third_late = True
- if unpaid_flag == True:
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- else:
- working_main = 'P'
- working_main_first_half = 'L'
- working_main_second_half = 'P'
- print "hard_absent ,hard_hd ..short_leave.. ",hard_absent ,hard_hd,short_leave_late
- if working_main == 'P' and hard_hd:
- working_main = 'HD'
- # if working_main == 'HD' and hard_absent:
- # working_main = 'A'
- #print "working main....",working_main
- if new_hrs1 < 0:
- new_hrs1 = 0
- in_punch_sun = False
- out_punch_sun = False
- if working_main == 'A':
- short_leave = False
- late = False
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_qty = 0.0
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- if leave_search and leave_qty == 0.5:
- working_main_first_half = 'A'
- working_main_second_half= 'L'
- working_main = 'HD'
- in_punch_sun = True
- out_punch_sun = True
- elif leave_search and leave_qty > 0.5:
- working_main_first_half = 'L'
- working_main_second_half= 'L'
- working_main = 'L'
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main_first_half = 'A'
- working_main_second_half= 'A'
- working_main = 'A'
- if working_main == 'P' and third_late==False:
- working_main_first_half = 'P'
- working_main_second_half= 'P'
- if working_main == 'HD' and third_late==False:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date = leave_date + timedelta(hours=03,minutes=00)
- leave_date1 = leave_date + timedelta(hours=23,minutes=00)
- leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- print "time", leave_date
- leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','>=',str(leave_date)),('date_to','<=',str(leave_date1)),('holiday_status_id','!=',9),('employee_id','=',employee_id.id)])
- print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_list:
- leave_qty = self.pool.get('hr.holidays').browse(cr,uid,leave_list[0]).number_of_days_temp
- in_punch_time_in = datetime.strptime(in_punch, DATETIME_FORMAT)
- out_punch_time_out = datetime.strptime(out_punch1, DATETIME_FORMAT)
- time_from = datetime.strptime(str(in_punch_time_in),'%Y-%m-%d %H:%M:%S').timetuple()
- time_to = datetime.strptime(str(out_punch_time_out),'%Y-%m-%d %H:%M:%S').timetuple()
- if (time_from.tm_hour >= 8 and time_from.tm_hour<=17) and (time_to.tm_hour<=17):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_first_half = 'P'
- working_main_second_half= 'L'
- else:
- working_main_first_half= 'P'
- working_main_second_half= 'A'
- elif (time_from.tm_hour >= 10 and time_from.tm_hour<=18) and (time_to.tm_hour<=23):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_second_half = 'P'
- working_main_first_half = 'L'
- else:
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- print "working main..working hour...ot.",working_main,new_hrs,new_hrs1,ot,ot_sum_gaurav
- # print "end_time.............",end_time,type(end_time)
- # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- out_punch2 = out_punch1
- else:
- random_second = random.randrange(1, 59, 1)
- random_min = random.randrange(1, 10, 1)
- if ot_min >= 5 :
- random_min += 30
- else:
- random_min += 0
- #print "random_min..........",random_min
- out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- #print "out_punch2.............",str(out_punch2)
- #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print "out_punch2..........",str(out_punch2)
- in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- #print "ot hr ,ot min......",ot_hr, ot_min
- if (category == 'worker' or category == 'contractor') and (working_main == 'A' or working_main=='L'):
- extra_ot = 0.0
- ot = 0.0
- new_hrs1 = 0.0
- if category == 'staff':
- extra_ot = 0.0
- ot = 0.0
- if category != 'staff':
- short_leave = False
- late = False
- # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- holiday_flag = False
- try:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- #print "deleted ...punch card .............",cr.fetchall()
- #print "going................."
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag = True
- if holiday_flag == True and category == 'staff':
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first =False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- print "========================AAAAAAAAAA==============",int(full_day[0][0]),int((half_day[0][0])/2),total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- if holiday_flag == True and (category =='worker' or category=='contractor'):
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first =False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- # print "======================================",start_date,end_date,total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half ='WO'
- working_main_second_half = 'WO'
- punch_min1 = float(working_hour.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- extra_ot = new_hrs1
- new_hrs = 0
- ot = 0
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- punch_min1 = float(working_hour.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- extra_ot = new_hrs1
- new_hrs = 0
- ot = 0
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- in_punch_sun = True
- out_punch_sun = True
- print "Punch hr",punch_hr1,new_hrs1
- if in_punch_sun == True and out_punch_sun== True:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch)})
- else:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- 'out_punch2':str(out_punch2),'in_punch_custom':str(in_punch),'late':late,})
- print "=========================NEW PUNCH CREATED===========================",created_id
- except Exception,e:
- print "Exception Punch Card Creation...........", e.args
- pass
- else:
- in_punch = data[0]
- #print "in_punch....................",in_punch
- out_punch1 = data[1]
- #print "out_punch1..................",out_punch1
- #category =employee_id.category
- in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "in_time.........",in_time
- out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- #print "out_time.........",out_time
- dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- #print "timing.................",timing
- lunch_mid = late = hard_absent = short_leave = hard_hd = False
- start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- working_main= False
- working_main_first_half = False
- working_main_second_half = False
- unpaid_flag=False
- third_late = False
- second_short = False
- lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- elunch = lunch + timedelta(hours=4,minutes=30)
- # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- if contract_data.weekly_shedule_id:
- for each in contract_data.weekly_shedule_id.attendance_ids:
- flag = 0
- # print "Gaurav==========123",salary_date,each.dt_from,each.date_to
- date_from_week = datetime.strptime(each.dt_from,DEFAULT_SERVER_DATE_FORMAT).date()
- date_to_week = datetime.strptime(each.date_to,DEFAULT_SERVER_DATE_FORMAT).date()
- salary_date_week = datetime.strptime(str(salary_date),DEFAULT_SERVER_DATE_FORMAT).date()
- time_diff = date_to_week - date_from_week
- diff_day = time_diff.days + (float(time_diff.seconds) / 86400)
- diff_day = round(math.ceil(diff_day))
- # print "Diffre========================",diff_day
- next_date_week = date_from_week
- for day in range(0, int(diff_day+1)):
- if datetime.strptime((next_date_week.strftime('%Y-%m-%d')),"%Y-%m-%d").date() == salary_date_week:
- # print "Hello",
- flag=1
- break
- next_date_week += timedelta(days=1)
- if flag == 1:
- # print "====Each=========",each,salary_date
- shift = self.working_hours_on_day_weekly(cr, uid, each, salary_date, context)
- else:
- shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- # print "shift............",shift,salary_date
- start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['start']))
- min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # print "start_time..............",start_time,type(start_time)
- end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- hour= int(float(shift['end']))
- min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- if min and len(min) == 1:
- min = str(min) +'0'
- if min and len(min) == 1:
- min = str(min)
- end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- #print "end_time................",end_time
- if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- actual_start = start_time
- else:
- actual_start = in_punch
- #print "actual_start............",actual_start
- if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- actual_end = end_time
- else:
- actual_end = out_punch1
- #print "actual_end.............",actual_end
- # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- #if category == 'staff':
- if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=32)):
- hard_absent =True
- #print "setting absent1...hard_absent =True......."
- working_main='A'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2,minutes=1)):
- #print "setting hd1..........."
- working_main='HD'
- elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- print "setting P1 and late..859.........12",in_punch
- # working_main ='P'
- late=True
- late_count = late_count+1
- holiday_flag_1=False
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag_1 = True
- if late_count>=3 and category=='staff' and holiday_flag_1==False:
- working_main ='HD'
- punch_in_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_in_hd= punch_in_hd.strftime("%Y-%m-%d 04:00:30")
- punch_out_hd = datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S')
- punch_out_hd = punch_out_hd.strftime("%Y-%m-%d 08:10:30")
- leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- if leave_obj1:
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- if cl_status[5]['remaining_leaves']>=0.5:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- print "Hiii",create_id
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif ml_status[2]['remaining_leaves']>=0.5:
- print "Ml"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- elif el_status[6]['remaining_leaves']>=0.5:
- print "El"
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':punch_in_hd,'date_to':punch_out_hd,'number_of_days_temp':0.5,'day_temp':0.5,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- unpaid_flag = True
- print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- else:
- working_main = 'P'
- else:
- #print "setting P1..........."
- working_main ='P'
- if not in_punch and not out_punch1:
- working_main = "A"
- #continue
- #print "working_main..........",working_main
- # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- hard_hd = short_leave = False
- if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- if late_count>=3 and category=='staff':
- working_main = 'HD'
- else:
- #print "hard hd true....."
- working_main = 'HD'
- hard_hd = True
- #print "hard_hd......setting...",hard_hd
- elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str((datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(hours=2))),'%Y-%m-%d %H:%M:%S') )) and \
- (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=5))):
- #print "short leave true....."
- short_leave = True
- short_leave_late = short_leave_late + 1
- # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # missing = new_hrs_miss = 0.0
- # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # missing = value.total_seconds()
- # #print "missing................",missing
- # miss_min = float(missing / 60)
- # print "miss_min............",miss_min
- # miss_hr = float(miss_min / 60)
- # #print "miss_hr.................",miss_hr
- # miss_hr = divmod(miss_hr,1)[0]
- # #print "miss_hr.................",miss_hr
- # if miss_hr:
- # #print "miss_hr...............",miss_hr
- # nw_min = miss_min - miss_hr * 60
- # #print "nw_min...1............",nw_min
- # else:
- # nw_min = miss_min
- # #print "nw_min......2.........",nw_min
- # nw_min = round(nw_min,0)
- # if nw_min > 5 and nw_min <= 35:
- # nm_min = 0.5
- # elif nw_min > 35:
- # miss_hr = miss_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # print "miss_hr............",miss_hr
- # print "nm_min..............",nm_min
- # new_hrs_miss = miss_hr + nm_min
- # print "new_hrs_miss................",new_hrs_miss
- # if new_hrs_miss < 4.0:
- # working_main ="A"
- # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # working_main ="HD"
- # elif new_hrs_miss >= 6.0 :
- # working_main ="A"
- # print "working_main............",working_main
- # ++++ START TIME & END TIME +++++++++++++++++++
- st= ed= False
- if in_punch:
- st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- if out_punch1:
- ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- #print "ed.................",ed
- #if category == 'staff':
- if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- lunch_mid =True
- # if category != 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- #print "lunch_mid...........",lunch_mid
- # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- new_hrs=0.0
- ot_hr = 0
- ot_min = 0
- if st and ed:
- # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- punch_min = float(working_hour.total_seconds() / 60)
- if category == 'worker' and category=='contractor':
- if lunch_mid:
- punch_min = punch_min - 30.0
- punch_hr = float(punch_min / 60)
- punch_hr = divmod(punch_hr,1)[0]
- if punch_hr:
- nw_min = punch_min - punch_hr * 60
- else:
- nw_min = punch_min
- if nw_min > 24 and nw_min < 55:
- nm_min = 0.5
- elif nw_min >= 55:
- punch_hr = punch_hr + 1
- nm_min = 0.0
- else:
- nm_min = 0.0
- new_hrs = punch_hr + nm_min
- #print "new_hrs..........",new_hrs,type(new_hrs)
- # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- #print "over_time.............",over_time
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- #print "actual ot new_hrs1.........",new_hrs1
- ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot = 0.0
- if ot > 2.0:
- extra_ot= float(float(ot -2.0))
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot= 2.0
- # if ot > 2.0 and ot_sum_gaurav<16:
- # extra_ot= float(float(ot -2.0))
- # #print "ot setting to 2.0...extra_ot...........",extra_ot
- # ot= 2.0
- # if ot_sum_gaurav>15.5:
- # extra_ot= float(float(ot))
- # ot = 0.0
- #print "ot setting to 2.0...extra_ot...........",extra_ot
- ot_sum_gaurav = ot_sum_gaurav+ot
- # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- val1=self.float_time_convert_main(ot)
- hr=0
- #print "val1...............",val1
- time1 = 0.0
- if val1 and len(str(val1[1])) == 1:
- hr = 0
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- if val1 and len(str(val1[1])) == 2:
- if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- hr = 0
- else:
- hr = 5
- ot_hr = val1[0]
- ot_min = hr
- time1 = str(val1[0]) +'.'+str(hr) + '0'
- ot = time1
- #print "new ot...........",ot
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- #print "new extra_ot..............",extra_ot
- # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- if category == 'worker' or category == 'contractor' :
- if working_main == 'HD' or working_main == 'P':
- #print "going in.........."
- if new_hrs < 4.0:
- working_main = 'A'
- #print "working hours are less than 4.0.....",working_main
- elif new_hrs >= 4.0 and new_hrs < 7.5:
- working_main = 'HD'
- #late = False
- #print "working setting HD....",working_main
- elif new_hrs >= 7.5 :
- working_main = 'P'
- #print "working setting P....",working_main
- if working_main == 'HD' and working_main == 'A':
- working_main = 'A'
- if category == 'staff':
- if new_hrs <= 3.0:
- working_main = 'A'
- # print "===================================",working_main
- # error
- if short_leave_late >= 2 and short_leave == True and category == 'staff':
- second_short = True
- working_main = 'HD'
- working_main_second_half = 'A'
- working_main_first_half ='P'
- if late_count >= 3 and late==True and category == 'staff' and (working_main=='HD' or working_main=='P'):
- third_late = True
- if unpaid_flag == True:
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- else:
- working_main = 'P'
- working_main_first_half = 'L'
- working_main_second_half = 'P'
- if working_main == 'P' and hard_hd:
- working_main = 'HD'
- # if working_main == 'HD' and hard_absent:
- # working_main = 'A'
- #print "working main....",working_main
- if new_hrs1 < 0:
- new_hrs1 = 0
- in_punch_sun = False
- out_punch_sun = False
- if working_main == 'A':
- short_leave = False
- late = False
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- if leave_search and leave_qty == 0.5:
- working_main_first_half = 'A'
- working_main_second_half= 'L'
- working_main = 'HD'
- in_punch_sun = True
- out_punch_sun = True
- elif leave_search and leave_qty > 0.5:
- working_main_first_half = 'L'
- working_main_second_half= 'L'
- working_main = 'L'
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main_first_half = 'A'
- working_main_second_half= 'A'
- working_main = 'A'
- if working_main == 'P' and third_late==False:
- working_main_first_half = 'P'
- working_main_second_half= 'P'
- if working_main == 'HD' and third_late==False:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date = leave_date + timedelta(hours=03,minutes=00)
- leave_date1 = leave_date + timedelta(hours=23,minutes=00)
- leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- print "time", leave_date
- leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','>=',str(leave_date)),('date_to','<=',str(leave_date1)),('holiday_status_id','!=',9),('employee_id','=',employee_id.id)])
- print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_list:
- leave_qty = self.pool.get('hr.holidays').browse(cr,uid,leave_list[0]).number_of_days_temp
- in_punch_time_in = datetime.strptime(in_punch, DATETIME_FORMAT)
- out_punch_time_out = datetime.strptime(out_punch1, DATETIME_FORMAT)
- time_from = datetime.strptime(str(in_punch_time_in),'%Y-%m-%d %H:%M:%S').timetuple()
- time_to = datetime.strptime(str(out_punch_time_out),'%Y-%m-%d %H:%M:%S').timetuple()
- if (time_from.tm_hour >= 8 and time_from.tm_hour<=17) and (time_to.tm_hour<=17):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_first_half = 'P'
- working_main_second_half= 'L'
- else:
- working_main_first_half= 'P'
- working_main_second_half= 'A'
- elif (time_from.tm_hour >= 10 and time_from.tm_hour<=18) and (time_to.tm_hour<=23):
- if leave_list and leave_qty == 0.5:
- working_main = 'P'
- working_main_second_half = 'P'
- working_main_first_half = 'L'
- else:
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- # print "end_time.............",end_time,type(end_time)
- # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- out_punch2 = out_punch1
- else:
- random_second = random.randrange(1, 59, 1)
- random_min = random.randrange(1, 10, 1)
- if ot_min >= 5 :
- random_min += 30
- else:
- random_min += 0
- #print "random_min..........",random_min
- out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- #print "out_punch2.............",str(out_punch2)
- #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # print "out_punch2..........",str(out_punch2)
- in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- #print "ot hr ,ot min......",ot_hr, ot_min
- if (category == 'worker' or category == 'contractor') and (working_main == 'A' or working_main=='L'):
- extra_ot = 0.0
- ot = 0.0
- new_hrs1 = 0.0
- if category == 'staff':
- extra_ot = 0.0
- ot = 0.0
- if category != 'staff':
- short_leave = False
- late = False
- # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- holiday_flag = False
- try:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- #print "deleted ...punch card .............",cr.fetchall()
- #print "going................."
- #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- if dict['holiday_id']:
- for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- holiday_flag = True
- if holiday_flag == True and category == 'staff':
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- short_leave = False
- late = False
- late_count = late_count-1
- in_punch_sun = True
- out_punch_sun = True
- if holiday_flag == True and (category =='worker' or category=='contractor'):
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- # print "======================================",start_date,end_date,total_day_week,full_day[0][0],half_day[0][0]
- if total_day_week >=3:
- working_main ='WO'
- working_main_first_half ='WO'
- working_main_second_half = 'WO'
- over_time=datetime.strptime(str( datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") + timedelta(hours=5,minutes=30)),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_start),"%Y-%m-%d %H:%M:%S")
- print "over_time.............",over_time,out_punch1,actual_start
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- print "actual ot new_hrs1.........",new_hrs1
- # ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot= float(float(new_hrs1))
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- ot = 0.0
- new_hrs = 0.0
- in_punch_sun = True
- out_punch_sun = True
- else:
- working_main ='S'
- working_main_first_half ='S'
- working_main_second_half = 'S'
- over_time=datetime.strptime(str( datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") + timedelta(hours=5,minutes=30)),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_start),"%Y-%m-%d %H:%M:%S")
- print "over_time.............",over_time,out_punch1,actual_start
- punch_min1 = float(over_time.total_seconds() / 60)
- punch_hr1 = float(punch_min1 / 60)
- punch_hr1 = divmod(punch_hr1,1)[0]
- if punch_hr1:
- nw_min1 = punch_min1 - punch_hr1 * 60
- else:
- nw_min1 = punch_min1
- if nw_min1 > 25 and nw_min1 < 55:
- nm_min1 = 0.5
- elif nw_min1 >= 55:
- punch_hr1 = punch_hr1 + 1
- nm_min1 = 0.0
- else:
- nm_min1 = 0.0
- new_hrs1 = punch_hr1 + nm_min1
- print "actual ot new_hrs1.........",new_hrs1
- # ot=round(new_hrs1/2,2)
- #print "shown ot.............",ot
- extra_ot= float(float(new_hrs1))
- extra_ot = round(extra_ot/2,2)
- val2=self.float_time_convert_main(extra_ot)
- hr1=0
- #print "val2...............",val2
- time2 = 0.0
- if val2 and len(str(val2[1])) == 1:
- hr1 = 0
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- if val2 and len(str(val2[1])) == 2:
- if int(val2[1]) >=0 and int(val2[1]) <= 24:
- hr1 = 0
- # elif val2[1] == 50:
- # hr1 = 5
- else:
- hr1 = 5
- time2 = str(val2[0]) +'.'+str(hr1) + '0'
- extra_ot = time2
- ot = 0.0
- new_hrs = 0.0
- in_punch_sun = True
- out_punch_sun = True
- print "Punch hr",punch_hr1,new_hrs1
- if in_punch_sun == True and out_punch_sun== True:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch)})
- else:
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- 'out_punch2':str(out_punch2),'in_punch_custom':str(in_punch),'late':late,})
- print "=========================NEW PUNCH CREATED===========================",created_id
- except Exception,e:
- print "Exception Punch Card Creation...........", e.args
- pass
- else:
- cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- cr.execute(""" select h_line.leave_date,h_line.national_holiday from holiday_list_lines as h_line left join holiday_list as h_list on (h_line.holiday_id = h_list.id)
- where h_list.month ='"""+str(salary_month.month)+"""' and h_list.year_id ='"""+str(salary_month.year_id.id)+"""' group by h_line.leave_date,h_line.national_holiday
- """)
- temp1 = cr.fetchall()
- sunday_list = {}
- flag = False
- for each in temp1:
- sunday_list.update({each[0]:each[1]})
- for key,val in sunday_list.items():
- if salary_date == key and val == False and joining_date <= salary_date:
- if termination_date:
- if termination_date >=salary_date:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working = 'L') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- if total_day_week >=3:
- working_main = 'WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'S'
- working_main_first_half = 'S'
- working_main_second_half = 'S'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- start_date = salary_date
- start_date = datetime.strptime(start_date,'%Y-%m-%d')
- start_date = datetime.strftime(start_date,'%Y-%m-%d %H:%M:%S')
- end_date = datetime.strptime(start_date, DATETIME_FORMAT)
- end_date = end_date - timedelta(hours=144,minutes=00)
- end_date = datetime.strftime(end_date,'%Y-%m-%d %H:%M:%S')
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='P' or working='L' ) and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- full_day = cr.fetchall()
- cr.execute("select count(*) from hr_punch_card where employee_id = '"+str(employee_id.id)+"' and (working='HD') and in_punch between '"+str(end_date)+"' and '"+str(start_date)+"'")
- half_day = cr.fetchall()
- if week_off_first == True:
- cr.execute("select number_of_days_temp from hr_holidays where date_from >= '"+str(end_date)+"' and date_to <= '"+str(start_date)+"' and employee_id='"+str(employee_id.id)+"';")
- leave_first = cr.fetchall()
- week_off_first = False
- if leave_first:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2) + leave_first[0][0]
- leave_first =False
- else:
- total_day_week = int(full_day[0][0]) + float((half_day[0][0])/2)
- if total_day_week >=3:
- working_main = 'WO'
- working_main_first_half = 'WO'
- working_main_second_half = 'WO'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'S'
- working_main_first_half = 'S'
- working_main_second_half = 'S'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- elif salary_date == key and val == True and joining_date <= salary_date :
- if termination_date :
- if termination_date >= salary_date:
- working_main = 'H'
- working_main_first_half = 'H'
- working_main_second_half = 'H'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'H'
- working_main_first_half = 'H'
- working_main_second_half = 'H'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- if salary_date not in sunday_list.keys() and joining_date <= salary_date :
- if termination_date:
- if termination_date >= salary_date:
- leave_qty = 0.0
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- print "select date_from,number_of_days_temp,date_to from hr_holidays where (date_from <= '"+time_to+"' and date_to >='"+time_from+"') and employee_id = '"+str(employee_id.id)+"'"
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- print "leave_search",leave_search
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- if leave_qty > 0.5:
- week_days +=1
- working_main = 'L'
- working_main_first_half = 'L'
- working_main_second_half = 'L'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- elif leave_qty == 0.5:
- week_days +=1
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'A'
- working_main_first_half = 'A'
- working_main_second_half = 'A'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- leave_qty = 0.0
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
- leave_date = datetime.strptime(salary_date,'%Y-%m-%d')
- leave_date = datetime.strftime(leave_date,'%Y-%m-%d %H:%M:%S')
- leave_date = datetime.strptime(leave_date, DATETIME_FORMAT)
- leave_date11 = leave_date + timedelta(hours=23,minutes=50)
- leave_date1 = leave_date + timedelta(hours=01,minutes=50)
- time_from = datetime.strftime(leave_date11,'%Y-%m-%d %H:%M:%S')
- time_to = datetime.strftime(leave_date1,'%Y-%m-%d %H:%M:%S')
- # leave_date = datetime.strptime(str(leave_date), DATETIME_FORMAT)
- # print "time", time_from
- print "select date_from,number_of_days_temp,date_to from hr_holidays where (date_from <= '"+time_to+"' and date_to >='"+time_from+"') and employee_id = '"+str(employee_id.id)+"'"
- cr.execute("select date_from,number_of_days_temp,date_to from hr_holidays where holiday_status_id in (5,6,2) and state='validate' and (date_from <= '"+time_from+"' and date_to >='"+time_to+"') and employee_id = '"+str(employee_id.id)+"' ")
- leave_search = cr.fetchall()
- print "leave_search",leave_search
- # leave_list = self.pool.get('hr.holidays').search(cr,uid,[('date_from','<=',str(leave_date)),('date_to','>=',str(leave_date)),('employee_id','=',employee_id.id)])
- # print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiii",leave_list
- if leave_search:
- leave_qty = leave_search[0][1]
- if leave_qty > 0.5:
- week_days +=1
- working_main = 'L'
- working_main_first_half = 'L'
- working_main_second_half = 'L'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- elif leave_qty == 0.5:
- week_days +=1
- working_main = 'HD'
- working_main_first_half = 'A'
- working_main_second_half = 'P'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- else:
- working_main = 'A'
- working_main_first_half = 'A'
- working_main_second_half = 'A'
- created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'first_half':working_main_first_half,'second_half':working_main_second_half,
- 'method':'auto','in_punch':str(salary_date),'method':'auto',#'in_time':in_time,'out_time':out_time,
- })
- print "IN and Out Pair attendance not found for emp on date......",employee_id,salary_date
- next_date += timedelta(days=1)
- # eror
- # print "emp_list..............",emp_list
- # month1=salary_month.month
- # print "month......... ",month1
- # year=salary_month.year_id.name
- # print "year............",year
- # if int(month1) in [1,3,5,7,8,10,12]:
- # month = 31
- # if int(month1) in [4,6,9,11]:
- # month = 30
- # if int(month1) in [2]:
- # if int(year) % 4 == 0:
- # month = 29
- # else:
- # month = 28
- # day_from = str(year) + '-' + str(month1) + '-' + '01'
- # # day_from = datetime.strptime(day_from,"%Y-%m-%d")
- # print "day_from..............",day_from
- # day_to = str(year) + '-' + str(month1) + '-' + str(month)
- # day_to = datetime.strptime(day_to,"%Y-%m-%d")
- # #print "day_to.....................",day_to
- # day_from = datetime.strptime(day_from,"%Y-%m-%d")
- # next_date = day_from
- # for day in range(0, month):
- # #print "next_date.............",str(next_date)
- # salary_date = next_date.strftime('%Y-%m-%d')
- # if emp_list:
- # for emp in emp_list:
- # late_count = 0;
- # ot_sum_gaurav = 0
- # employee_id=emp_obj.browse(cr ,uid ,emp )
- # contract_ids = cont_obj.search(cr,uid,[('employee_id','=',employee_id.id)])
- # if contract_ids:
- # contract_data = cont_obj.browse(cr, uid, contract_ids)[0]
- # else:
- # raise osv.except_osv(_('Warning !'),_("Contract is missing for employee %s." % (employee_id.name)))
- # category = employee_id.category
- # timing_main= self.timing_main_func( cr ,uid ,ids ,contract_data.working_hours ,salary_date)
- # #print "timing_main...........",timing_main
- # total_punch = "select min(name + interval'5 hour 30 minutes') ,max(name + interval'5 hour 30 minutes') from hr_attendance where name + interval '5 hours 30 minute' >= to_timestamp('"+str(timing_main['start_time'])+"',\
- # 'YYYY-MM-DD HH24:MI:SS')::timestamp - interval '1 hours 30 minute' and name + interval '5 hours 30 minute' < to_timestamp('"+str(timing_main['final_time'])+"','YYYY-MM-DD HH24:MI:SS')::timestamp and employee_id = \
- # '"+str(employee_id.id)+"' "
- # cr.execute(total_punch)
- # total_punch_result = cr.fetchall()
- # for data in total_punch_result:
- # if len(data)>1 and data[0] != None and data[1] != None and data[0] != data[1]:
- # #if total_punch_result and len(total_punch_result[0]) == 2 and total_punch_result[0][0] != None and total_punch_result[0][1] != None and total_punch_result[0][0] != total_punch_result[0][1]:
- # in_punch = data[0]
- # #print "in_punch....................",in_punch
- # out_punch1 = data[1]
- # #print "out_punch1..................",out_punch1
- # #category =employee_id.category
- # in_time = float(str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- # #print "in_time.........",in_time
- # out_time = float(str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S").strftime('%H.%M')))
- # #print "out_time.........",out_time
- # dict=self.get_month_year(cr ,uid ,ids ,salary_date)
- # timing = self.calculate_time(cr, uid, ids, salary_date, in_time or 0.0, out_time or 0.0)
- # #print "timing.................",timing
- # lunch_mid = late = hard_absent = short_leave = hard_hd = False
- # start = datetime.strptime(str(timing_main['start_time']),"%Y-%m-%d %H:%M:%S")
- # time1600 = start.replace(hour=16, minute=00, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # working_main= False
- # lunch = datetime.strptime(str(timing['start_time']),"%Y-%m-%d %H:%M:%S")
- # time915 = lunch.replace(hour=9, minute=15, second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # elunch = lunch + timedelta(hours=4,minutes=30)
- # # +++++++++++++++ Finds Out the His Shift Timings and His Actual Working Time ++++++++++++++
- # shift = self.working_hours_on_day(cr, uid, contract_data.working_hours, salary_date, context)
- # #print "shift............",shift
- # start_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- # hour= int(float(shift['start']))
- # min = str(str(abs(float(shift['start'])) % 1).split('.')[1])
- # if min and len(min) == 1:
- # min = str(min) +'0'
- # if min and len(min) == 1:
- # min = str(min)
- # start_time = start_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # #print "start_time..............",start_time,type(start_time)
- # end_time = datetime.strptime(datetime.strptime(salary_date,"%Y-%m-%d").strftime('%Y-%m-%d %H:%M:%S'),"%Y-%m-%d %H:%M:%S")
- # hour= int(float(shift['end']))
- # min = str(str(abs(float(shift['end'])) % 1).split('.')[1])
- # if min and len(min) == 1:
- # min = str(min) +'0'
- # if min and len(min) == 1:
- # min = str(min)
- # end_time = end_time.replace(hour=hour, minute=int(min), second= 00).strftime('%Y-%m-%d %H:%M:%S')
- # #print "end_time................",end_time
- # if datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S") < datetime.strptime(start_time,"%Y-%m-%d %H:%M:%S"):
- # actual_start = start_time
- # else:
- # actual_start = in_punch
- # #print "actual_start............",actual_start
- # if datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S") > datetime.strptime(end_time,"%Y-%m-%d %H:%M:%S"):
- # actual_end = end_time
- # else:
- # actual_end = out_punch1
- # #print "actual_end.............",actual_end
- # # +++++++++++++++++++++ TO KNOW P , HD , A OR LATE +++++++++++++++++++++++++++++++++
- # #if category == 'staff':
- # if datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') >( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4, minutes=30)):
- # hard_absent =True
- # #print "setting absent1...hard_absent =True......."
- # working_main='A'
- # elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)):
- # #print "setting hd1..........."
- # working_main='HD'
- # elif datetime.strptime(str(in_punch),'%Y-%m-%d %H:%M:%S') > ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes=11)):
- # print "setting P1 and late....1604......."
- # working_main ='P'
- # late_count = late_count+1
- # print "+++++++++++++++++++++++++++++==================================",late_count
- # late=True
- # print "+++++++++++++++++++++++++++++==================================",late_count,in_punch,employee_id.id
- # if late_count>=3 and category=='staff':
- # working_main ='A'
- # leave_obj1 = self.pool.get('hr.holidays').search(cr,uid,[('employee_id','=',employee_id.id),('date_from','=',in_punch)],context=context)
- # if leave_obj1:
- # self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- # self.pool.get('hr.holidays').holidays_refuse(cr,uid,leave_obj1)
- # self.pool.get('hr.holidays').write(cr,uid,leave_obj1,{'state':'confirm','approve_user_id':employee_id.parent_id.id },context=None)
- # leave_obj2 = self.pool.get('hr.holidays').unlink(cr,uid,leave_obj1)
- # cl_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [5], employee_id.id, False, context=context)
- # ml_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [2], employee_id.id, False, context=context)
- # el_status = self.pool.get('hr.holidays.status').get_days(cr, uid, [6], employee_id.id, False, context=context)
- # if cl_status[5]['remaining_leaves']>=1:
- # create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':5,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':1,'day_temp':1,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- # print "Hiii",create_id
- # a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- # print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- # elif ml_status[2]['remaining_leaves']>=1:
- # print "Ml"
- # create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':2,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':1,'day_temp':1,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- # a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- # print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- # elif el_status[6]['remaining_leaves']>=1:
- # print "El"
- # create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':6,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':1,'day_temp':1,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- # a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- # print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- # else:
- # create_id = self.pool.get('hr.holidays').create(cr,uid,{'name':'Late Leave','employee_id':employee_id.id,'holiday_status_id':9,'date_from':in_punch,'date_to':out_punch1,'number_of_days_temp':1,'day_temp':1,'manager_id':employee_id.parent_id.id,'res_employee_id':1},context=None)
- # a = self.pool.get('hr.holidays').write(cr,uid,create_id,{'state':'validate','approve_user_id':employee_id.parent_id.id },context=None)
- # print "+++++++++++++++++++++++++++++=========================Leave Created=========",late_count,a
- # else:
- # working_main = 'P'
- # else:
- # #print "setting P1..........."
- # working_main ='P'
- # if not in_punch and not out_punch1:
- # working_main = "A"
- # #continue
- # #print "working_main..........",working_main
- # # ++++++++++++++++++++++++++++++++ Check for Employee Short Leave (Goes Before Time) , SETS STRICT HD(hard_hd) +++++++++++++++
- # #print "(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )..",(datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )
- # #print "(datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')......",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # #print "(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15)).....",(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))
- # hard_hd = short_leave = False
- # if datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') < (datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') ):#- timedelta(hours=5,minutes=30)
- # if late_count>=3 and category=='staff':
- # print "Late Count Reseted$$$$$$$$$$$$$$$$$$$$$$$",late_count
- # working_main = 'A'
- # else:
- # working_main = 'HD'
- # hard_hd = True
- # #print "hard_hd......setting...",hard_hd
- # elif (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') >= (datetime.strptime(str(time1600),'%Y-%m-%d %H:%M:%S') )) and \
- # (datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S') <= (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') - timedelta(minutes=15))):
- # #print "short leave true....."
- # short_leave = True
- # # +++++++++++ Calculating Missing of Employee +++++++++++++++++++++++++++++++
- # # missing = new_hrs_miss = 0.0
- # # if datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # # value = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") - datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # # missing = value.total_seconds()
- # # #print "missing................",missing
- # # miss_min = float(missing / 60)
- # # print "miss_min............",miss_min
- # # miss_hr = float(miss_min / 60)
- # # #print "miss_hr.................",miss_hr
- # # miss_hr = divmod(miss_hr,1)[0]
- # # #print "miss_hr.................",miss_hr
- # # if miss_hr:
- # # #print "miss_hr...............",miss_hr
- # # nw_min = miss_min - miss_hr * 60
- # # #print "nw_min...1............",nw_min
- # # else:
- # # nw_min = miss_min
- # # #print "nw_min......2.........",nw_min
- # # nw_min = round(nw_min,0)
- # # if nw_min > 5 and nw_min <= 35:
- # # nm_min = 0.5
- # # elif nw_min > 35:
- # # miss_hr = miss_hr + 1
- # # nm_min = 0.0
- # # else:
- # # nm_min = 0.0
- # # print "miss_hr............",miss_hr
- # # print "nm_min..............",nm_min
- # # new_hrs_miss = miss_hr + nm_min
- # # print "new_hrs_miss................",new_hrs_miss
- # # if new_hrs_miss < 4.0:
- # # working_main ="A"
- # # elif new_hrs_miss >=4.0 and new_hrs_miss < 6.0:
- # # working_main ="HD"
- # # elif new_hrs_miss >= 6.0 :
- # # working_main ="A"
- # # print "working_main............",working_main
- # # ++++ START TIME & END TIME +++++++++++++++++++
- # st= ed= False
- # if in_punch:
- # st=str(datetime.strptime(in_punch,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- # if out_punch1:
- # ed=str(datetime.strptime(out_punch1,"%Y-%m-%d %H:%M:%S"))# - timedelta(hours=5,minutes=30))
- # #+++++++++++++++++ Lunch Lies in between of work ++++++++++++++++++++++
- # #print "st..............",st,type(st) # st.strftime('%Y-%m-%d %H:%M:%S')
- # #print "ed.................",ed
- # #if category == 'staff':
- # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # lunch_mid =True
- # # if category != 'staff':
- # # if st and datetime.strptime(st,'%Y-%m-%d %H:%M:%S') <= ( datetime.strptime(str(start_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=3,minutes=30)) and \
- # # ed and datetime.strptime(ed,'%Y-%m-%d %H:%M:%S') >= ( datetime.strptime(str(timing_main['start_time']),'%Y-%m-%d %H:%M:%S') + timedelta(hours=4)):
- # # lunch_mid =True
- # #print "lunch_mid...........",lunch_mid
- # # ++++++++++++++++++++++ For Working Time Calculation ex 9:00 - 6:00 ++++++ not 8;50 - 6:34 +++
- # new_hrs=0.0
- # ot_hr = 0
- # ot_min = 0
- # if st and ed:
- # # +++++++++++++++++++ Calculate Working Hours +++++++++++++++++++++++++++++
- # working_hour=datetime.strptime(actual_end,"%Y-%m-%d %H:%M:%S") -datetime.strptime(actual_start,"%Y-%m-%d %H:%M:%S")
- # punch_min = float(working_hour.total_seconds() / 60)
- # if lunch_mid:
- # punch_min = punch_min - 30.0
- # punch_hr = float(punch_min / 60)
- # punch_hr = divmod(punch_hr,1)[0]
- # if punch_hr:
- # nw_min = punch_min - punch_hr * 60
- # else:
- # nw_min = punch_min
- # if nw_min > 24 and nw_min < 55:
- # nm_min = 0.5
- # elif nw_min >= 55:
- # punch_hr = punch_hr + 1
- # nm_min = 0.0
- # else:
- # nm_min = 0.0
- # new_hrs = punch_hr + nm_min
- # #print "new_hrs..........",new_hrs,type(new_hrs)
- # # +++++++++++++++++++ Over Time Calculation +++++++++++++++++++++++
- # over_time=datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") -datetime.strptime(str(actual_end),"%Y-%m-%d %H:%M:%S")
- # #print "over_time.............",over_time
- # punch_min1 = float(over_time.total_seconds() / 60)
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- # if punch_hr1:
- # nw_min1 = punch_min1 - punch_hr1 * 60
- # else:
- # nw_min1 = punch_min1
- # if nw_min1 > 25 and nw_min1 < 55:
- # nm_min1 = 0.5
- # elif nw_min1 >= 55:
- # punch_hr1 = punch_hr1 + 1
- # nm_min1 = 0.0
- # else:
- # nm_min1 = 0.0
- # new_hrs1 = punch_hr1 + nm_min1
- # #print "actual ot new_hrs1.........",new_hrs1
- # ot=round(new_hrs1/2,2)
- # #print "shown ot.............",ot
- # extra_ot = 0.0
- # if ot > 2.0:
- # extra_ot= float(float(ot -2.0))
- # #print "ot setting to 2.0...extra_ot...........",extra_ot
- # ot= 2.0
- # # if ot > 2.0 and ot_sum_gaurav<16:
- # # extra_ot= float(float(ot -2.0))
- # # #print "ot setting to 2.0...extra_ot...........",extra_ot
- # # ot= 2.0
- # # if ot_sum_gaurav>16:
- # # extra_ot= float(float(ot))
- # # ot = 0.0
- # # +++++++++++++++++++++++++++++ FORMATTING OT (EX- 1.49 = 1.5) ++++++++++++++++++++++++++++++++++
- # val1=self.float_time_convert_main(ot)
- # hr=0
- # #print "val1...............",val1
- # time1 = 0.0
- # if val1 and len(str(val1[1])) == 1:
- # hr = 0
- # ot_hr = val1[0]
- # ot_min = hr
- # time1 = str(val1[0]) +'.'+str(hr) + '0'
- # if val1 and len(str(val1[1])) == 2:
- # if int(val1[1]) >= 0 and int(val1[1]) <= 24:
- # hr = 0
- # else:
- # hr = 5
- # ot_hr = val1[0]
- # ot_min = hr
- # time1 = str(val1[0]) +'.'+str(hr) + '0'
- # ot = time1
- # #print "new ot...........",ot
- # val2=self.float_time_convert_main(extra_ot)
- # hr1=0
- # #print "val2...............",val2
- # time2 = 0.0
- # if val2 and len(str(val2[1])) == 1:
- # hr1 = 0
- # time2 = str(val2[0]) +'.'+str(hr1) + '0'
- # if val2 and len(str(val2[1])) == 2:
- # if int(val2[1]) >=0 and int(val2[1]) <= 24:
- # hr1 = 0
- # # elif val2[1] == 50:
- # # hr1 = 5
- # else:
- # hr1 = 5
- # time2 = str(val2[0]) +'.'+str(hr1) + '0'
- # extra_ot = time2
- # #print "new extra_ot..............",extra_ot
- # # +++++++++++++++++ Check for If Worked for Less Than 4 Hours ++++++++++++++++++++++=
- # print "working_main............",working_main
- # if working_main == 'HD' or working_main == 'P':
- # #print "going in.........."
- # if new_hrs < 4.0:
- # working_main = 'A'
- # #print "working hours are less than 4.0.....",working_main
- # elif new_hrs >= 4.0 and new_hrs < 6.0:
- # working_main = 'HD'
- # #late = False
- # #print "working setting HD....",working_main
- # elif new_hrs >= 6.0 :
- # working_main = 'P'
- # #print "working setting P....",working_main
- # print "hard_absent ,hard_hd ..short_leave.. ",hard_absent ,hard_hd,short_leave
- # if working_main == 'P' and hard_hd:
- # working_main = 'HD'
- # # if working_main == 'HD' and hard_absent:
- # # working_main = 'A'
- # #print "working main....",working_main
- # if new_hrs1 < 0:
- # new_hrs1 = 0
- # if working_main == 'A':
- # short_leave = False
- # late = False
- # print "working main..working hour...ot.",working_main,new_hrs,new_hrs1
- # # print "end_time.............",end_time,type(end_time)
- # # print "datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S').........",datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S')
- # if (datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(minutes = 10)) > datetime.strptime(str(out_punch1),'%Y-%m-%d %H:%M:%S'):
- # out_punch2 = out_punch1
- # else:
- # random_second = random.randrange(1, 59, 1)
- # random_min = random.randrange(1, 10, 1)
- # if ot_min >= 5 :
- # random_min += 30
- # else:
- # random_min += 0
- # #print "random_min..........",random_min
- # out_punch2 = datetime.strptime(str(end_time),"%Y-%m-%d %H:%M:%S") + timedelta(hours=ot_hr,minutes = random_min,seconds=random_second) #- timedelta(hours=5,minutes=30)
- # #print "out_punch2.............",str(out_punch2)
- # #out_punch2 = str(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # # print"(datetime.strptime(str(end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2)).........",str(datetime.strptime((end_time),'%Y-%m-%d %H:%M:%S') + timedelta(hours=2))
- # # print "out_punch2..........",str(out_punch2)
- # in_punch = datetime.strptime(str(in_punch),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- # out_punch1 = datetime.strptime(str(out_punch1),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- # out_punch2 = datetime.strptime(str(out_punch2),"%Y-%m-%d %H:%M:%S") - timedelta(hours=5,minutes=30)
- # #print "ot hr ,ot min......",ot_hr, ot_min
- # if category == 'staff':
- # extra_ot = 0.0
- # ot = 0.0
- # if category != 'staff':
- # short_leave = False
- # late = False
- # # +++++++++ Creating New Punch Deleting Previous One +++++++++++++++++++++++++
- # holiday_flag = False
- # if late_count >=3:
- # late_count =0
- # try:
- # cr.execute("delete from hr_punch_card where day='"+str(salary_date)+"' and employee_id = '"+str(employee_id.id)+"' and method='auto'")
- # #print "deleted ...punch card .............",cr.fetchall()
- # #print "going................."
- # #ot_ids= ot_obj.search( cr ,uid ,[('month_id','=',dict['holiday_id'] and dict['holiday_id'][0]),('employee_id','=',employee_id.id)])
- # #punch_ids=punch_obj.search(cr ,uid ,[('month','=',dict['month']),('year_id','=',dict['year_id'] and dict['year_id'][0]),('employee_id','=',employee_id.id)])
- # if dict['holiday_id']:
- # for sun in holiday_obj.browse(cr ,uid ,dict['holiday_id'][0]).holiday_lines:
- # if datetime.strptime(salary_date,"%Y-%m-%d").date() == datetime.strptime(str(sun.leave_date),"%Y-%m-%d").date():
- # holiday_flag = True
- # if holiday_flag :
- # working_main ='L'
- # short_leave = False
- # late = False
- # if holiday_flag and (category =='worker' or category=='contractor'):
- # print "ooooooooooooooooooooooootttttttttMy Block",
- # working_main ='L'
- # punch_min1 = float(working_hour.total_seconds() / 60)
- # # punch_hr1 = float(punch_min1 / 60)
- # # punch_hr1 = divmod(punch_hr1,1)[0]
- # punch_hr1 = float(punch_min1 / 60)
- # punch_hr1 = divmod(punch_hr1,1)[0]
- # if punch_hr1:
- # nw_min1 = punch_min1 - punch_hr1 * 60
- # else:
- # nw_min1 = punch_min1
- # if nw_min1 > 25 and nw_min1 < 55:
- # nm_min1 = 0.5
- # elif nw_min1 >= 55:
- # punch_hr1 = punch_hr1 + 1
- # nm_min1 = 0.0
- # else:
- # nm_min1 = 0.0
- # new_hrs1 = punch_hr1 + nm_min1
- # extra_ot = new_hrs1
- # new_hrs = 0
- # ot = 0
- # print "Punch hr",punch_hr1,new_hrs1
- # created_id = punch_obj.create(cr, uid, {'employee_id':employee_id.id,'working':working_main,'working_hour':float(new_hrs),'extra_ot':extra_ot,'new_ot':ot,'ot':new_hrs1,
- # 'short_leave':short_leave,'method':'auto','method':'auto','in_punch':str(in_punch),'out_punch1':str(out_punch1),#'in_time':in_time,'out_time':out_time,
- # 'out_punch2':str(out_punch2),'late':late,})
- # print "=========================NEW PUNCH CREATED===========================",created_id
- # except Exception,e:
- # print "Exception Punch Card Creation...........", e.args
- # pass
- # else:
- # print "IN and Out Pair attendance not found for emp on date......",employee_id.name,salary_date
- # next_date += timedelta(days=1)
- return False
- hr_calculate_salary()
- # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Add Comment
Please, Sign In to add comment