today = dt.date.today()
first = today.replace(day=1)
lastMonth = first - dt.timedelta(days=1)
previous_month = int(lastMonth.strftime("%m"))
# Calculating sundays
day = dt.date(today.year, previous_month, 1)
single_day = dt.timedelta(days=1)
sundays = 0
while day.month == previous_month:
if day.weekday() == 6:
sundays += 1
day += single_day
# calculating days from previous month
year = today.year
day = previous_month
total_days = monthrange(year, day)
total_days_1 = int(total_days[1])
current_days = total_days_1 - sundays
total_month_hours = current_days * 8
# calculate worked _hours for previous month:
s = (
"""select sum(worked_hours) from hr_attendance where employee_id=%s and name >= date_trunc('month', current_date - interval '1' month)and name < date_trunc('month', current_date)""" % (
obj.employee_id.id))
cr.execute(s)
l = cr.fetchone()
total_worked_hours = l[0]
print total_worked_hours
# select wages for employee given:
if total_worked_hours != None and total_worked_hours >0.00 :
s1 = (
"""select salary from hr_contract where employee_id=%s""" % (
obj.employee_id.id))
cr.execute(s1)
l1 = cr.fetchone()
per_hour_salary = l1[0]
if total_month_hours > total_worked_hours:
overtime = (total_month_hours) - (total_worked_hours)
incentive = overtime * (per_hour_salary * 1.5)
total_wage = (total_worked_hours )* (per_hour_salary)
total_sal = (total_wage) + (incentive)
print obj.employee_id.id
print total_sal
cr.execute(""" update hr_contract set wage=%s where employee_id=%s""" % (
total_sal, obj.employee_id.id))
else:
if total_worked_hours != None and total_worked_hours > 0.00:
perhourwage = ((total_worked_hours) * (per_hour_salary))
total_sal = perhourwage
res[obj.id] = total_sal
cr.execute(""" update hr_contract set wage=%s where employee_id=%s""" % (
total_sal, obj.employee_id.id))
I don't know where the error is. I have set the condition to not null even though the error comes.
I can't able to find where the error comes. I have also given the non null value it shows the same error.
How can I solve this?
Help me with a solution.
Thanks.
Aucun commentaire:
Enregistrer un commentaire