From dd4866ee53c212128f7ff7858a92ac0f49a76846 Mon Sep 17 00:00:00 2001 From: Elyageen Date: Sat, 20 Jul 2024 22:06:20 +0300 Subject: [PATCH] fix bug --- .../controllers/rest_api_v2/permission.py | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/odex25_mobile/odex_mobile/controllers/rest_api_v2/permission.py b/odex25_mobile/odex_mobile/controllers/rest_api_v2/permission.py index d8157b9d7..7a7c7dda0 100644 --- a/odex25_mobile/odex_mobile/controllers/rest_api_v2/permission.py +++ b/odex25_mobile/odex_mobile/controllers/rest_api_v2/permission.py @@ -105,7 +105,7 @@ class PermissionController(http.Controller): success=False) permission = None try: - # permission_number = self.permission_number_decrement(employee, body['date_from'], body['date_to']) + permission_number = self.permission_number_decrement(employee, body['date_from'], body['date_to']) permission = ( http.request.env["hr.personal.permission"] .sudo() @@ -403,50 +403,50 @@ class PermissionController(http.Controller): # item.permission_number = round(number_of_per - all_perission, 2) # else: # raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month')) - # def permission_number_decrement(self, employee_id, date_from, date_to): - # if employee_id: - # if not employee_id.first_hiring_date: - # raise Warning(_('You can not Request Permission The Employee have Not First Hiring Date')) - # if date_to: - # current_date = datetime.strptime(date_to, DEFAULT_SERVER_DATETIME_FORMAT) + def permission_number_decrement(self, employee_id, date_from, date_to): + if employee_id: + if not employee_id.first_hiring_date: + raise Warning(_('You can not Request Permission The Employee have Not First Hiring Date')) + if date_to: + current_date = datetime.strptime(date_to, DEFAULT_SERVER_DATETIME_FORMAT) - # current_month = datetime.strptime(date_to, DEFAULT_SERVER_DATETIME_FORMAT).month - # # date_from = current_date.strftime('%Y-0{0}-01'.format(current_month)) - # # date_to = current_date.strftime('%Y-0{0}-01'.format(current_month + 1)) - # date_from = current_date.replace(day=1) - # if current_month == 12: - # date_to = current_date.strftime('%Y-{0}-31'.format(current_month)) - # number_of_per = employee_id.contract_id.working_hours.permission_number - # employee_permissions = http.request.env['hr.personal.permission'].search([ - # ('employee_id', '=', employee_id.id), - # ('state', '=', 'approve'), - # ('date_from', '>=', date_from), - # ('date_to', '<=', date_to)]) + current_month = datetime.strptime(date_to, DEFAULT_SERVER_DATETIME_FORMAT).month + # date_from = current_date.strftime('%Y-0{0}-01'.format(current_month)) + # date_to = current_date.strftime('%Y-0{0}-01'.format(current_month + 1)) + date_from = current_date.replace(day=1) + if current_month == 12: + date_to = current_date.strftime('%Y-{0}-31'.format(current_month)) + number_of_per = employee_id.contract_id.working_hours.permission_number + employee_permissions = http.request.env['hr.personal.permission'].search([ + ('employee_id', '=', employee_id.id), + ('state', '=', 'approve'), + ('date_from', '>=', date_from), + ('date_to', '<=', date_to)]) - # all_perission = 0 - # for rec in employee_permissions: - # all_perission += rec.duration + all_perission = 0 + for rec in employee_permissions: + all_perission += rec.duration - # if rec.date_to and date_to: - # permission_date1 = datetime.strptime(str(rec.date_to), - # DEFAULT_SERVER_DATETIME_FORMAT).date() - # date_to_value1 = datetime.strptime(str(date_to), DEFAULT_SERVER_DATETIME_FORMAT).date() - # # if rec.date_to and item.date_to: - # # permission_date1 = datetime.strptime(rec.date_to, - # # DEFAULT_SERVER_DATETIME_FORMAT).date() - # # date_to_value1 = datetime.strptime(item.date_to, DEFAULT_SERVER_DATETIME_FORMAT).date() + if rec.date_to and date_to: + permission_date1 = datetime.strptime(str(rec.date_to), + DEFAULT_SERVER_DATETIME_FORMAT).date() + date_to_value1 = datetime.strptime(str(date_to), DEFAULT_SERVER_DATETIME_FORMAT).date() + if rec.date_to and date_to: + permission_date1 = datetime.strptime(rec.date_to, + DEFAULT_SERVER_DATETIME_FORMAT).date() + date_to_value1 = datetime.strptime(date_to, DEFAULT_SERVER_DATETIME_FORMAT).date() - # if permission_date1 == date_to_value1: - # # return http_helper.errcode(code=403, message=_('Sorry You Have Used All Your Permission In This Day you have one permission per a Day')) - # raise Warning( - # _('Sorry You Have Used All Your Permission In This Day you have one permission per a Day')) + if permission_date1 == date_to_value1: + # return http_helper.errcode(code=403, message=_('Sorry You Have Used All Your Permission In This Day you have one permission per a Day')) + raise Warning( + _('Sorry You Have Used All Your Permission In This Day you have one permission per a Day')) - # if number_of_per > all_perission: + if number_of_per > all_perission: - # return round(number_of_per - all_perission, 2) - # else: - # # return http_helper.errcode(code=403, message=_('Sorry You Have Used All Your Permission Hours In This Month')) - # raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month')) + return round(number_of_per - all_perission, 2) + else: + # return http_helper.errcode(code=403, message=_('Sorry You Have Used All Your Permission Hours In This Month')) + raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month')) def get_attchment(self, res_id): attachment = http.request.env['ir.attachment'].search(