diff --git a/addons_extensions/hr_emp_dashboard/models/emp_dashboard.py b/addons_extensions/hr_emp_dashboard/models/emp_dashboard.py index 09bd26f2b..6d87a9de8 100644 --- a/addons_extensions/hr_emp_dashboard/models/emp_dashboard.py +++ b/addons_extensions/hr_emp_dashboard/models/emp_dashboard.py @@ -32,139 +32,21 @@ class HrEmployee(models.Model): @api.model def get_user_employee_details(self): - """To fetch the details of employee""" uid = request.session.uid - employee = self.env['hr.employee'].sudo().search_read( - [('user_id', '=', uid)], limit=1) - attendance = self.env['hr.attendance'].sudo().search_read( - [('employee_id', '=', employee[0]['id'])], - fields=['id', 'check_in', 'check_out', 'worked_hours']) - attendance_line = [] - for line in attendance: - if line['check_in'] and line['check_out']: - val = { - 'id':line['id'], - 'date': line['check_in'].date(), - 'sign_in': line['check_in'].time().strftime('%H:%M'), - 'sign_out': line['check_out'].time().strftime('%H:%M'), - 'worked_hours': format_duration(line['worked_hours']) - } - attendance_line.append(val) - leaves = self.env['hr.leave'].sudo().search_read( - [('employee_id', '=', employee[0]['id'])], - fields=['request_date_from', 'request_date_to', 'state', - 'holiday_status_id']) - for line in leaves: - line['type'] = line.pop('holiday_status_id')[1] - if line['state'] == 'confirm': - line['state'] = 'To Approve' - line['color'] = 'orange' - elif line['state'] == 'validate1': - line['state'] = 'Second Approval' - line['color'] = '#7CFC00' - elif line['state'] == 'validate': - line['state'] = 'Approved' - line['color'] = 'green' - elif line['state'] == 'cancel': - line['state'] = 'Cancelled' - line['color'] = 'red' - else: - line['state'] = 'Refused' - line['color'] = 'red' - expense =[] - # self.env['hr.expense'].sudo().search_read( - # [('employee_id', '=', employee[0]['id'])], - # fields=['name', 'date', 'state', 'total_amount']) - # for line in expense: - # if line['state'] == 'draft': - # line['state'] = 'To Report' - # line['color'] = '#17A2B8' - # elif line['state'] == 'reported': - # line['state'] = 'To Submit' - # line['color'] = '#17A2B8' - # elif line['state'] == 'submitted': - # line['state'] = 'Submitted' - # line['color'] = '#FFAC00' - # elif line['state'] == 'approved': - # line['state'] = 'Approved' - # line['color'] = '#28A745' - # elif line['state'] == 'done': - # line['state'] = 'Done' - # line['color'] = '#28A745' - # else: - # line['state'] = 'Refused' - # line['color'] = 'red' - leaves_to_approve = self.env['hr.leave'].sudo().search_count( - [('state', 'in', ['confirm', 'validate1'])]) - today = datetime.strftime(datetime.today(), '%Y-%m-%d') - query = """ - select count(id) - from hr_leave - WHERE (hr_leave.date_from::DATE,hr_leave.date_to::DATE) - OVERLAPS ('%s', '%s') and - state='validate'""" % (today, today) - cr = self._cr - cr.execute(query) - leaves_today = cr.fetchall() - first_day = date.today().replace(day=1) - last_day = (date.today() + relativedelta(months=1, day=1)) - timedelta( - 1) - query = """ - select count(id) - from hr_leave - WHERE (hr_leave.date_from::DATE,hr_leave.date_to::DATE) - OVERLAPS ('%s', '%s') - and state='validate'""" % (first_day, last_day) - cr = self._cr - cr.execute(query) - leaves_this_month = cr.fetchall() - leaves_alloc_req = self.env['hr.leave.allocation'].sudo().search_count( - [('state', 'in', ['confirm', 'validate1'])]) - timesheet_count = self.env['account.analytic.line'].sudo().search_count( - [('project_id', '!=', False), ('user_id', '=', uid)]) - timesheet_view_id = self.env.ref( - 'hr_timesheet.hr_timesheet_line_search') - job_applications = self.env['hr.applicant'].sudo().search_count([]) - if employee: - # sql = """select broad_factor from hr_employee_broad_factor - # where id =%s""" - # self.env.cr.execute(sql, (employee[0]['id'],)) - # result = self.env.cr.dictfetchall() - # broad_factor = result[0]['broad_factor'] if result[0][ - # 'broad_factor'] else False - broad_factor = False - if employee[0]['birthday']: - diff = relativedelta(datetime.today(), employee[0]['birthday']) - age = diff.years - else: - age = False - if employee[0]['joining_date']: - diff = relativedelta(datetime.today(), - employee[0]['joining_date']) - years = diff.years - months = diff.months - days = diff.days - experience = '{} years {} months {} days'.format(years, months, - days) - else: - experience = False - if employee: - data = { - 'broad_factor': broad_factor if broad_factor else 0, - 'leaves_to_approve': leaves_to_approve, - 'leaves_today': leaves_today, - 'leaves_this_month': leaves_this_month, - 'leaves_alloc_req': leaves_alloc_req, - 'emp_timesheets': timesheet_count, - 'job_applications': job_applications, - 'timesheet_view_id': timesheet_view_id, - 'experience': experience, - 'age': age, - 'attendance_lines': attendance_line, - 'leave_lines': leaves, - 'expense_lines': expense - } - employee[0].update(data) - return employee - else: - return False \ No newline at end of file + """To fetch the details of employee""" + return self.env["hr.employee"].sudo().search_read( + [("user_id", "=", uid)], + [ + 'name', + 'image_1920', + 'job_id', + 'employee_id', + 'current_company_exp', + 'doj', + 'birthday', + 'mobile_phone', + 'work_email', + 'private_street', + 'attendance_state', + 'id' + ]) \ No newline at end of file diff --git a/addons_extensions/hr_emp_dashboard/static/src/js/profile_component.js b/addons_extensions/hr_emp_dashboard/static/src/js/profile_component.js index c2a4d3280..717cb8845 100644 --- a/addons_extensions/hr_emp_dashboard/static/src/js/profile_component.js +++ b/addons_extensions/hr_emp_dashboard/static/src/js/profile_component.js @@ -108,13 +108,12 @@ export class NetflixProfileContainer extends Component { try { - const employeeData = await this.orm.searchRead("hr.employee", [["user_id", "=", this.props.action.context.user_id]], ['name', 'image_1920','job_id','employee_id','current_company_exp','doj','birthday','mobile_phone','work_email','private_street','attendance_state' ,'id' - ] ); + const employeeData = await this.orm.call( + "hr.employee",'get_user_employee_details'); const attendanceLines = await this.orm.searchRead( 'hr.attendance', [['employee_id', '=', employeeData[0].id]], - ['create_date', 'check_in', 'check_out', 'worked_hours'] - ); + ['create_date', 'check_in', 'check_out', 'worked_hours']); const Leaves = await this.orm.searchRead('hr.leave',[['employee_id', '=', employeeData[0].id]], ['request_date_from', 'request_date_to', 'state','holiday_status_id']);