Fix Dashboard
This commit is contained in:
parent
c0bb40cafc
commit
9138f20aba
|
|
@ -32,139 +32,21 @@ class HrEmployee(models.Model):
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_user_employee_details(self):
|
def get_user_employee_details(self):
|
||||||
"""To fetch the details of employee"""
|
|
||||||
uid = request.session.uid
|
uid = request.session.uid
|
||||||
employee = self.env['hr.employee'].sudo().search_read(
|
"""To fetch the details of employee"""
|
||||||
[('user_id', '=', uid)], limit=1)
|
return self.env["hr.employee"].sudo().search_read(
|
||||||
attendance = self.env['hr.attendance'].sudo().search_read(
|
[("user_id", "=", uid)],
|
||||||
[('employee_id', '=', employee[0]['id'])],
|
[
|
||||||
fields=['id', 'check_in', 'check_out', 'worked_hours'])
|
'name',
|
||||||
attendance_line = []
|
'image_1920',
|
||||||
for line in attendance:
|
'job_id',
|
||||||
if line['check_in'] and line['check_out']:
|
'employee_id',
|
||||||
val = {
|
'current_company_exp',
|
||||||
'id':line['id'],
|
'doj',
|
||||||
'date': line['check_in'].date(),
|
'birthday',
|
||||||
'sign_in': line['check_in'].time().strftime('%H:%M'),
|
'mobile_phone',
|
||||||
'sign_out': line['check_out'].time().strftime('%H:%M'),
|
'work_email',
|
||||||
'worked_hours': format_duration(line['worked_hours'])
|
'private_street',
|
||||||
}
|
'attendance_state',
|
||||||
attendance_line.append(val)
|
'id'
|
||||||
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
|
|
||||||
|
|
@ -108,13 +108,12 @@ export class NetflixProfileContainer extends Component {
|
||||||
|
|
||||||
try {
|
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(
|
const attendanceLines = await this.orm.searchRead(
|
||||||
'hr.attendance',
|
'hr.attendance',
|
||||||
[['employee_id', '=', employeeData[0].id]],
|
[['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]],
|
const Leaves = await this.orm.searchRead('hr.leave',[['employee_id', '=', employeeData[0].id]],
|
||||||
['request_date_from', 'request_date_to', 'state','holiday_status_id']);
|
['request_date_from', 'request_date_to', 'state','holiday_status_id']);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue