Fix bug
This commit is contained in:
parent
008e125352
commit
67dd2eac6b
|
|
@ -190,16 +190,25 @@ class AttendanceController(http.Controller):
|
|||
if not employee:
|
||||
return http_helper.response(code=400, message=_("You are not allowed to perform this operation. please check with one of your team admins"), success=False)
|
||||
if body.get('action') and body.get('action') == 'sign_in':
|
||||
timezone = user.tz or 'GMT'
|
||||
timezone = user.tz or 'UTC'
|
||||
local_tz = pytz.timezone(timezone)
|
||||
now_gmt = datetime.now(local_tz)
|
||||
current_time_float = now_gmt.hour + now_gmt.minute / 60.0
|
||||
calendar = employee.resource_calendar_id
|
||||
before_work = getattr(calendar, 'grace_hour_before_work', 8.0)
|
||||
after_work = getattr(calendar, 'grace_hour_after_work', 16.0)
|
||||
if before_work and after_work:
|
||||
if current_time_float < before_work or current_time_float > after_work:
|
||||
return http_helper.response(code=400, message=_("Dear employee, your working hours have not started yet."), success=False)
|
||||
if before_work > 0.0 and current_time_float < before_work:
|
||||
return http_helper.response(
|
||||
code=400,
|
||||
message=_("Dear employee, your working hours have not started yet."),
|
||||
success=False
|
||||
)
|
||||
if after_work > 0.0 and current_time_float > after_work:
|
||||
return http_helper.response(
|
||||
code=400,
|
||||
message=_("Dear employee, your working hours have ended."),
|
||||
success=False
|
||||
)
|
||||
if employee.device_id != body.get('device_id'):
|
||||
return http_helper.errcode(code=403, message=_("Device id not matching with already exist in system please contact system admin"))
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ResourceCalendar(models.Model):
|
||||
|
|
@ -8,3 +9,20 @@ class ResourceCalendar(models.Model):
|
|||
|
||||
grace_hour_before_work = fields.Float(string="Grace Hours Before Work")
|
||||
grace_hour_after_work = fields.Float(string="Grace Hours After Work")
|
||||
|
||||
@api.constrains('grace_hour_before_work', 'grace_hour_after_work')
|
||||
def grace_hour_constrains(self):
|
||||
for rec in self:
|
||||
if hasattr(rec, 'is_full_day') and hasattr(rec, 'noke'):
|
||||
if rec.is_full_day and not rec.noke:
|
||||
if rec.grace_hour_before_work and rec.full_min_sign_in:
|
||||
if rec.grace_hour_before_work > rec.full_min_sign_in:
|
||||
raise ValidationError(_(
|
||||
"Grace hours before work must be less than or equal to minimum sign-in time."
|
||||
))
|
||||
|
||||
if rec.grace_hour_after_work and rec.full_max_sign_out:
|
||||
if rec.grace_hour_after_work < rec.full_max_sign_out:
|
||||
raise ValidationError(_(
|
||||
"Grace hours after work must be **greater** than or equal to maximum sign-out time."
|
||||
))
|
||||
|
|
|
|||
|
|
@ -38,24 +38,25 @@ class Validator:
|
|||
else:
|
||||
return page
|
||||
|
||||
def get_attendance_check(self,employee):
|
||||
def get_attendance_check(self, employee):
|
||||
if not employee:
|
||||
return 'sign_out'
|
||||
user = employee.user_id
|
||||
timezone = user.tz or 'GMT'
|
||||
local_tz = pytz.timezone(timezone)
|
||||
now_gmt = datetime.datetime.now(local_tz)
|
||||
current_time_float = now_gmt.hour + now_gmt.minute / 60.0
|
||||
|
||||
timezone = employee.user_id.tz or 'UTC'
|
||||
now = datetime.datetime.now(pytz.timezone(timezone))
|
||||
current_time = now.hour + now.minute / 60.0
|
||||
calendar = employee.resource_calendar_id
|
||||
before_work = getattr(calendar, 'grace_hour_before_work', 8.0)
|
||||
after_work = getattr(calendar, 'grace_hour_after_work', 16.0)
|
||||
|
||||
if before_work and after_work:
|
||||
if current_time_float < before_work or current_time_float > after_work:
|
||||
if calendar:
|
||||
if calendar.grace_hour_before_work > 0.0:
|
||||
if current_time < calendar.grace_hour_before_work:
|
||||
return 'sign_out'
|
||||
|
||||
last = http.request.env['attendance.attendance'].sudo().search([('employee_id', '=', employee.id), ], order='name desc',
|
||||
if calendar.grace_hour_after_work > 0.0:
|
||||
if current_time > calendar.grace_hour_after_work:
|
||||
return 'sign_out'
|
||||
|
||||
last = http.request.env['attendance.attendance'].sudo().search([('employee_id', '=', employee.id), ],
|
||||
order='name desc',
|
||||
limit=1)
|
||||
if last:
|
||||
return last.action
|
||||
|
|
|
|||
Loading…
Reference in New Issue