Merge pull request #290 from expsa/dev_odex25_mobile

fix bug
This commit is contained in:
AbuzarExp 2024-07-20 14:00:19 +03:00 committed by GitHub
commit ec129dcbe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 98 additions and 41 deletions

View File

@ -142,6 +142,7 @@ class OverTimeController(http.Controller):
@http.route(['/rest_api/v2/overtimes'], type='http', auth='none', csrf=False, methods=['POST'])
def create_overtime(self, **kw):
s = None
try:
data = kw.get('lines', {})
if data:
@ -213,6 +214,11 @@ class OverTimeController(http.Controller):
"reason": s.reason,
"overtime_plase":s.overtime_plase,# http_helper.get_lable_selection(s,'overtime_plase',s.overtime_plase),#
# "benefits_discounts_list":s.benefits_discounts.read(['name']),
'account': s.sudo().account_id.id if s.sudo().account_id else False,
'account_id': s.sudo().account_id.name if s.sudo().account_id else False,
'journal': s.sudo().journal_id.name if s.sudo().journal_id else False,
'journal_id': s.sudo().journal_id.id if s.sudo().journal_id else False,
'benefits_discounts': s.sudo().benefits_discounts.name if s.sudo().benefits_discounts else False,
'benefits_discounts_id': s.sudo().benefits_discounts.id if s.sudo().benefits_discounts else False,
}
@ -234,9 +240,13 @@ class OverTimeController(http.Controller):
data={'overtimes': [value],})
except (UserError, AccessError, ValidationError, Exception, Warning) as e:
error = str(e)
if s:
s.unlink()
return http_helper.response(code=400, message=str(error), success=False)
except Exception as e:
_logger.error(str(e))
if s:
s.unlink()
message = validator.get_server_error(e, user)
return http_helper.errcode(code=403, message=message)
@ -297,15 +307,19 @@ class OverTimeController(http.Controller):
# if approvel:
s.write(vals)
s.line_ids_over_time.get_max_remain_hours()
if s.transfer_type == 'accounting' and body.get("account") and body.get("journal"):
vals.update({
'account_id': body['account'],
'journal_id': body['journal'],
})
s.benefits_discounts = False
elif s.transfer_type == 'payroll' and body.get("rule") :
vals.update({
'benefits_discounts':int( body['rule']),
})
s.account_id = False
s.journal_id = False
s.write(vals)
if s.state == 'hr_aaproval':
s.onchange_transfer_type()
@ -326,8 +340,10 @@ class OverTimeController(http.Controller):
}
# if approvel:
value.update({
'account': s.sudo().account_id.id if s.sudo().account_id else False,
'account_id': s.sudo().account_id.name if s.sudo().account_id else False,
'journal_id': s.sudo().journal_id.name if s.sudo().journal_id else False,
'journal': s.sudo().journal_id.name if s.sudo().journal_id else False,
'journal_id': s.sudo().journal_id.id if s.sudo().journal_id else False,
'benefits_discounts': s.sudo().benefits_discounts.name if s.sudo().benefits_discounts else False,
'benefits_discounts_id': s.sudo().benefits_discounts.id if s.sudo().benefits_discounts else False,
@ -474,8 +490,11 @@ class OverTimeController(http.Controller):
}
# if approvel:
value.update({
'account': s.sudo().account_id.id if s.sudo().account_id else False,
'account_id': s.sudo().account_id.name if s.sudo().account_id else False,
'journal_id': s.sudo().journal_id.name if s.sudo().journal_id else False,
'journal': s.sudo().journal_id.name if s.sudo().journal_id else False,
'journal_id': s.sudo().journal_id.id if s.sudo().journal_id else False,
'benefits_discounts': s.sudo().benefits_discounts.name if s.sudo().benefits_discounts else False,
'benefits_discounts_id': s.sudo().benefits_discounts.id if s.sudo().benefits_discounts else False,

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import werkzeug
from odoo import http, tools
from odoo import http, tools , exceptions
from datetime import datetime
from odoo.http import request, Response
import base64
@ -350,23 +350,25 @@ class PermissionController(http.Controller):
_logger.error(str(e))
message = validator.get_server_error(e, user)
return http_helper.errcode(code=403, message=message)
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)
def permission_number_decrement(self):
for item in self:
# item._onchange_time()
if item.employee_id:
if not item.employee_id.first_hiring_date:
raise exceptions.Warning(
_('You can not Request Permission The Employee have Not First Hiring Date'))
if item.date_to:
current_date = datetime.strptime(str(item.date_to), DEFAULT_SERVER_DATETIME_FORMAT)
current_month = current_date.month
date_from = current_date.strftime('%Y-%m-01')
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),
date_to = current_date.strftime('%Y-12-31')
else:
date_to = (current_date.replace(month=current_month + 1, day=1) - timedelta(days=1)).strftime('%Y-%m-%d')
number_of_per = item.employee_id.contract_id.working_hours.permission_number
employee_permissions = self.search([
('employee_id', '=', item.employee_id.id),
('state', '=', 'approve'),
('date_from', '>=', date_from),
('date_to', '<=', date_to)])
@ -375,26 +377,62 @@ class PermissionController(http.Controller):
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 item.date_to:
permission_date1 = rec.date_to.date() if isinstance(rec.date_to, datetime) else datetime.strptime(rec.date_to, DEFAULT_SERVER_DATETIME_FORMAT).date()
date_to_value1 = item.date_to.date() if isinstance(item.date_to, datetime) else datetime.strptime(item.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(
raise exceptions.Warning(
_('Sorry You Have Used All Your Permission In This Day you have one permission per a Day'))
if number_of_per > all_perission:
return round(number_of_per - all_perission, 2)
item.permission_number = 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 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)])
# 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 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:
# 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(