This question has been flagged
My post message(success) is showing perfectly and now i want to add error message to show if the attendance is not marked.


@http.route('/new_attendance_record', type='json', auth='user')
def new_attend_record(self, **rec):
new_format = "%Y-%m-%d %H:%M:%S"
local_tz = request.env.user.tz
local_dt = pytz.timezone(local_tz)
if request.jsonrequest:
user = request.env.user
mob_checkin = rec['check_in']
# mob_checkout= rec['check_out']
locate = rec['location']
long = rec['longitude']
lat = rec['latitude']
print(long,lat,locate,'Hi')
if mob_checkin:
upd_checkin_time = datetime.strptime(mob_checkin, "%Y-%m-%dT%H:%M")
local_dt1 = local_dt.localize(upd_checkin_time, is_dst=None)
cin = local_dt1.astimezone(pytz.utc)
mob_checkin = cin.strftime(new_format)
# if mob_checkout:
# upd_checkout_time = datetime.strptime(mob_checkout, "%Y-%m-%dT%H:%M")
# local_dt2 = local_dt.localize(upd_checkout_time, is_dst=None)
# cout = local_dt2.astimezone(pytz.utc)
# mob_checkout = cout.strftime(new_format)
print(mob_checkin)
# print(mob_checkout)
print(rec['location'])
if user.id:
vals = {
# 'employee_id': user.id,
'check_in': mob_checkin,
# 'check_out': mob_checkout,
'location': locate,
'longitude': long,
'latitude': lat,


}
new_record = request.env['hr.attendance'].sudo().create(vals)
if not new_record:
return {'error': _('Unable to create attendance.')}
else:
args = {
'success': True, 'message': 'Mark Attendance successfully', 'id': new_record.id
}
return args
Avatar
Discard