Browse Source

Jan 11 : [FIX] Bug Fixed 'hr_payroll_dashboard'

pull/238/head
AjmalCybro 2 years ago
parent
commit
66e66dc925
  1. 2
      hr_payroll_dashboard/__manifest__.py
  2. 100
      hr_payroll_dashboard/models/employee.py
  3. 22
      hr_payroll_dashboard/static/src/js/hr_payroll_dashboard.js
  4. 22
      hr_payroll_dashboard/static/src/xml/payroll_dashboard.xml

2
hr_payroll_dashboard/__manifest__.py

@ -21,7 +21,7 @@
############################################################################# #############################################################################
{ {
'name': "HR Payroll Dashboard", 'name': "HR Payroll Dashboard",
'version': '14.0.1.0.0', 'version': '14.0.1.1.1',
'summary': """HR Payroll Dashboard""", 'summary': """HR Payroll Dashboard""",
'description': """HR Payroll Dashboard""", 'description': """HR Payroll Dashboard""",
'category': 'Human Resource', 'category': 'Human Resource',

100
hr_payroll_dashboard/models/employee.py

@ -47,37 +47,38 @@ class Employee(models.Model):
def get_user_employee_info(self): def get_user_employee_info(self):
"""To get the employee information""" """To get the employee information"""
uid = request.session.uid uid = request.session.uid
employee_id = self.env['hr.employee'].sudo().search([ employee_user_id = self.env['hr.employee'].sudo().search([
('user_id', '=', uid)], limit=1) ('user_id', '=', uid)
], limit=1)
employee = self.env['hr.employee'].sudo().search_read([ employee = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)], limit=1) ('user_id', '=', uid)], limit=1)
attendance_count = self.env['hr.attendance'].sudo().search( attendance_count = self.env['hr.attendance'].sudo().search(
[('employee_id', '=', employee_id.id), [('employee_id', '=', employee_user_id.id),
('attendance_date', '=', date.today())]) ('attendance_date', '=', date.today())])
manager_attendance_count = self.env['hr.attendance'].sudo().search( manager_attendance_count = self.env['hr.attendance'].sudo().search(
[('attendance_date', '=', date.today())]) [('attendance_date', '=', date.today())])
leave_request_count = self.env['hr.leave'].sudo().search( leave_request_count = self.env['hr.leave'].sudo().search(
[('employee_id', '=', employee_id.id), [('employee_id', '=', employee_user_id.id),
('request_date_from', '=', date.today())]) ('request_date_from', '=', date.today())])
manager_leave_request = self.env['hr.leave'].sudo().search( manager_leave_request = self.env['hr.leave'].sudo().search(
[('request_date_from', '=', date.today())]) [('request_date_from', '=', date.today())])
employee_contracts = self.env['hr.contract'].sudo().search([ employee_contracts = self.env['hr.contract'].sudo().search([
('employee_id', '=', employee_id.id)]) ('employee_id', '=', employee_user_id.id)])
payslips = self.env['hr.payslip'].sudo().search([ payslips = self.env['hr.payslip'].sudo().search([
('employee_id', '=', employee_id.id)]) ('employee_id', '=', employee_user_id.id)])
salary_rules = self.env['hr.salary.rule'].sudo().search([]) salary_rules = self.env['hr.salary.rule'].sudo().search([])
salary_structures = self.env['hr.payroll.structure'].sudo().search([]) salary_structures = self.env['hr.payroll.structure'].sudo().search([])
salary_rule_count = len(salary_rules) salary_rule_count = len(salary_rules)
salary_structure_count = len(salary_structures) salary_structure_count = len(salary_structures)
emp_leave = len(manager_leave_request) if employee_id.is_manager \ emp_leave = len(manager_leave_request) if employee_user_id.is_manager \
else len(leave_request_count) else len(leave_request_count)
payslip_count = len(payslips) if not employee_id.is_manager \ payslip_count = len(payslips) if not employee_user_id.is_manager \
else len(self.env['hr.payslip'].sudo().search([])) else len(self.env['hr.payslip'].sudo().search([]))
emp_contracts_count = len(employee_contracts) \ emp_contracts_count = len(employee_contracts) \
if not employee_id.is_manager else len( if not employee_user_id.is_manager else len(
self.env['hr.contract'].sudo().search([])) self.env['hr.contract'].sudo().search([]))
attendance_today = len(manager_attendance_count) \ attendance_today = len(manager_attendance_count) \
if employee_id.is_manager else len(attendance_count) if employee_user_id.is_manager else len(attendance_count)
if employee: if employee:
data = { data = {
'emp_timesheets': attendance_today, 'emp_timesheets': attendance_today,
@ -128,20 +129,34 @@ class Employee(models.Model):
@api.model @api.model
def get_department_leave(self): def get_department_leave(self):
"""return department wise leave details""" """return department wise leave details"""
employee = False
month_list = [] month_list = []
graph_result = [] graph_result = []
uid = request.session.uid uid = request.session.uid
employee_user = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)
], limit=1)
employees = self.env['hr.employee'].sudo().search_read([], limit=1)
if employee_user:
employee = self.env['hr.employee'].sudo().search_read([ employee = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)], limit=1) ('user_id', '=', uid)], limit=1)
employee_id = self.env['hr.employee'].browse(
employee[0]['id'])
elif employees:
employee = self.env['hr.employee'].sudo().search_read([], limit=1)
employee_id = self.env['hr.employee'].browse(
employee[0]['id'])
for i in range(5, -1, -1): for i in range(5, -1, -1):
last_month = datetime.now() - relativedelta(months=i) last_month = datetime.now() - relativedelta(months=i)
text = format(last_month, '%B %Y') text = format(last_month, '%B %Y')
month_list.append(text) month_list.append(text)
self.env.cr.execute("""select id, name from hr_department self.env.cr.execute("""select id, name from hr_department
where active=True""") where active=True""")
departments = self.env.cr.dictfetchall() departments = self.env.cr.dictfetchall()
department_list = [x['name'] for x in departments] department_list = [x['name'] for x in departments]
for month in month_list: for month in month_list:
leave = {} leave = {}
for dept in departments: for dept in departments:
@ -151,8 +166,8 @@ class Employee(models.Model):
'leave': leave 'leave': leave
} }
graph_result.append(vals) graph_result.append(vals)
employee_id = self.env['hr.employee'].browse(employee[0]['id'])
if employee:
sql = """ sql = """
SELECT h.id, h.employee_id,h.department_id SELECT h.id, h.employee_id,h.department_id
, extract('month' FROM y)::int AS leave_month , extract('month' FROM y)::int AS leave_month
@ -172,6 +187,7 @@ class Employee(models.Model):
self.env.cr.execute(sql) self.env.cr.execute(sql)
results = self.env.cr.dictfetchall() results = self.env.cr.dictfetchall()
leave_lines = [] leave_lines = []
for line in results: for line in results:
employee = self.browse(line['employee_id']) employee = self.browse(line['employee_id'])
from_dt = fields.Datetime.from_string(line['date_from']) from_dt = fields.Datetime.from_string(line['date_from'])
@ -184,6 +200,7 @@ class Employee(models.Model):
'days': days 'days': days
} }
leave_lines.append(vals) leave_lines.append(vals)
if leave_lines: if leave_lines:
df = pd.DataFrame(leave_lines) df = pd.DataFrame(leave_lines)
rf = df.groupby(['l_month', 'department']).sum() rf = df.groupby(['l_month', 'department']).sum()
@ -191,25 +208,39 @@ class Employee(models.Model):
for month in month_list: for month in month_list:
for line in result_lines: for line in result_lines:
if month.replace(' ', '') == line[0].replace(' ', ''): if month.replace(' ', '') == line[0].replace(' ', ''):
match = list(filter(lambda d: d['l_month'] in [month], match = list(filter(
lambda d: d['l_month'] in [month],
graph_result))[0]['leave'] graph_result))[0]['leave']
dept_name = self.env['hr.department'].browse( dept_name = self.env['hr.department'].browse(
line[1]).name line[1]).name
if match: if match:
match[dept_name] = result_lines[line]['days'] match[dept_name] = result_lines[line]['days']
for result in graph_result: for result in graph_result:
result['l_month'] = result['l_month'].split(' ')[:1][0].strip()[:3] \ result['l_month'] = result[
+ " " + result['l_month'].split(' ')[1:2][0] 'l_month'
].split(' ')[:1][0].strip()[:3] + " " +\
result['l_month'].split(' ')[1:2][0]
return graph_result, department_list return graph_result, department_list
else:
return False
@api.model @api.model
def get_employee_expense(self): def get_employee_expense(self):
"""return employee expense details""" """return employee expense details"""
month_list = [] month_list = []
graph_result = [] graph_result = []
uid = request.session.uid uid = request.session.uid
employee = False
employee_user = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)
], limit=1)
employees = self.env['hr.employee'].sudo().search_read([], limit=1)
if employee_user:
employee = self.env['hr.employee'].sudo().search_read([ employee = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)], limit=1) ('user_id', '=', uid)
], limit=1)
elif employees:
employees = self.env['hr.employee'].sudo().search_read([], limit=1)
for i in range(5, -1, -1): for i in range(5, -1, -1):
last_month = datetime.now() - relativedelta(months=i) last_month = datetime.now() - relativedelta(months=i)
@ -228,6 +259,7 @@ class Employee(models.Model):
'leave': leave 'leave': leave
} }
graph_result.append(vals) graph_result.append(vals)
if employee:
employee_id = self.env['hr.employee'].browse(employee[0]['id']) employee_id = self.env['hr.employee'].browse(employee[0]['id'])
sql = """ sql = """
@ -269,6 +301,8 @@ class Employee(models.Model):
result['l_month'] = result['l_month'].split(' ')[:1][0].strip()[:3] \ result['l_month'] = result['l_month'].split(' ')[:1][0].strip()[:3] \
+ " " + result['l_month'].split(' ')[1:2][0] + " " + result['l_month'].split(' ')[1:2][0]
return graph_result, department_list return graph_result, department_list
else:
return False
@api.model @api.model
def employee_leave_trend(self): def employee_leave_trend(self):
@ -281,8 +315,19 @@ class Employee(models.Model):
text = format(last_month, '%B %Y') text = format(last_month, '%B %Y')
month_list.append(text) month_list.append(text)
uid = request.session.uid uid = request.session.uid
employee = False
employee_user = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)
], limit=1)
employees = self.env['hr.employee'].sudo().search_read([], limit=1)
if employee_user:
employee = self.env['hr.employee'].sudo().search_read([ employee = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)], limit=1) ('user_id', '=', uid)
], limit=1)
elif employees:
employee = self.env['hr.employee'].sudo().search_read([], limit=1)
for month in month_list: for month in month_list:
vals = { vals = {
'l_month': month, 'l_month': month,
@ -305,6 +350,7 @@ class Employee(models.Model):
date_trunc('month', now()) date_trunc('month', now())
and h.employee_id = %s and h.employee_id = %s
""" """
if employee:
self.env.cr.execute(sql, (employee[0]['id'],)) self.env.cr.execute(sql, (employee[0]['id'],))
results = self.env.cr.dictfetchall() results = self.env.cr.dictfetchall()
for line in results: for line in results:
@ -331,6 +377,8 @@ class Employee(models.Model):
result['l_month'] = result['l_month'].split(' ')[:1][0].strip()[:3] \ result['l_month'] = result['l_month'].split(' ')[:1][0].strip()[:3] \
+ " " + result['l_month'].split(' ')[1:2][0] + " " + result['l_month'].split(' ')[1:2][0]
return graph_result return graph_result
else:
return False
class Contract(models.Model): class Contract(models.Model):
@ -383,15 +431,29 @@ class HrExpense(models.Model):
last_month = datetime.now() - relativedelta(months=i) last_month = datetime.now() - relativedelta(months=i)
text = format(last_month, '%B %Y') text = format(last_month, '%B %Y')
month_list.append(text) month_list.append(text)
for month in month_list: for month in month_list:
vals = { vals = {
'l_month': month, 'l_month': month,
'count': 0 'count': 0
} }
approved_trend.append(vals) approved_trend.append(vals)
uid = request.session.uid uid = request.session.uid
employee = False
employee_user = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)
], limit=1)
employees = self.env['hr.employee'].sudo().search_read([], limit=1)
if employee_user:
employee = self.env['hr.employee'].sudo().search_read([ employee = self.env['hr.employee'].sudo().search_read([
('user_id', '=', uid)], limit=1) ('user_id', '=', uid)
], limit=1)
elif employees:
employee = self.env['hr.employee'].sudo().search_read([], limit=1)
if employee:
employee_id = self.env['hr.employee'].browse(employee[0]['id']) employee_id = self.env['hr.employee'].browse(employee[0]['id'])
if not employee_id.is_manager: if not employee_id.is_manager:
sql = ('''select to_char(date, 'Month YYYY') as l_month, sql = ('''select to_char(date, 'Month YYYY') as l_month,
@ -424,6 +486,8 @@ class HrExpense(models.Model):
'values': approved_trend 'values': approved_trend
}] }]
return graph_result return graph_result
else:
return False
class HrAttendance(models.Model): class HrAttendance(models.Model):

22
hr_payroll_dashboard/static/src/js/hr_payroll_dashboard.js

@ -223,6 +223,7 @@ var PayrollDashboard = AbstractAction.extend({
model: "hr.expense", model: "hr.expense",
method: "get_employee_expense", method: "get_employee_expense",
}).then(function (data) { }).then(function (data) {
if(data){
data.forEach(function(d) { data.forEach(function(d) {
d.values.forEach(function(d) { d.values.forEach(function(d) {
d.l_month = d.l_month; d.l_month = d.l_month;
@ -295,8 +296,7 @@ var PayrollDashboard = AbstractAction.extend({
.attr("cx", function(d) { return x(d.l_month)}) .attr("cx", function(d) { return x(d.l_month)})
.attr("cy", function(d) { return y(d.count)}) .attr("cy", function(d) { return y(d.count)})
.attr("r", 3); .attr("r", 3);
}
}); });
}, },
@ -309,6 +309,7 @@ var PayrollDashboard = AbstractAction.extend({
model: "hr.employee", model: "hr.employee",
method: "get_department_leave", method: "get_department_leave",
}).then(function (data) { }).then(function (data) {
if (data){
var fData = data[0]; var fData = data[0];
var dept = data[1]; var dept = data[1];
var id = self.$('.leave_graph')[0]; var id = self.$('.leave_graph')[0];
@ -454,7 +455,7 @@ var PayrollDashboard = AbstractAction.extend({
return pC; return pC;
} }
// function to handle legend. // function to handle legend.
function legend(lD){ function legend(lD){
var leg = {}; var leg = {};
@ -515,6 +516,7 @@ var PayrollDashboard = AbstractAction.extend({
var hG = histoGram(sF), // create the histogram. var hG = histoGram(sF), // create the histogram.
pC = pieChart(tF), // create the pie-chart. pC = pieChart(tF), // create the pie-chart.
leg= legend(tF); // create the legend. leg= legend(tF); // create the legend.
}
}); });
}, },
render_graphs: function(){ render_graphs: function(){
@ -543,6 +545,7 @@ var PayrollDashboard = AbstractAction.extend({
method: "get_employee_time_off", method: "get_employee_time_off",
}).then(function (data) { }).then(function (data) {
if (data){
var segColor = {}; var segColor = {};
var vis = d3.select(elem[0]).append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")"); var vis = d3.select(elem[0]).append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")");
var pie = d3.layout.pie().value(function(d){return d.value;}); var pie = d3.layout.pie().value(function(d){return d.value;});
@ -572,7 +575,7 @@ var PayrollDashboard = AbstractAction.extend({
// create the third column for each segment. // create the third column for each segment.
tr.append("td").attr("class",'legendFreq').attr("style","border: 5px solid transparent; font-weight: bold;") tr.append("td").attr("class",'legendFreq').attr("style","border: 5px solid transparent; font-weight: bold;")
.text(function(d){ return d.value;}); .text(function(d){ return d.value;});
}
}); });
}, },
@ -590,6 +593,7 @@ var PayrollDashboard = AbstractAction.extend({
model: "hr.payslip", model: "hr.payslip",
method: "get_employee_payslips", method: "get_employee_payslips",
}).then(function (data) { }).then(function (data) {
if(data){
var segColor = {}; var segColor = {};
var vis = d3.select(elem[0]).append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")"); var vis = d3.select(elem[0]).append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")");
var pie = d3.layout.pie().value(function(d){return d.value;}); var pie = d3.layout.pie().value(function(d){return d.value;});
@ -619,6 +623,7 @@ var PayrollDashboard = AbstractAction.extend({
// create the third column for each segment. // create the third column for each segment.
tr.append("td").attr("class",'legendFreq').attr("style","border: 5px solid transparent; font-weight: bold;") tr.append("td").attr("class",'legendFreq').attr("style","border: 5px solid transparent; font-weight: bold;")
.text(function(d){ return d.value;}); .text(function(d){ return d.value;});
}
}); });
}, },
@ -636,6 +641,7 @@ var PayrollDashboard = AbstractAction.extend({
model: "hr.contract", model: "hr.contract",
method: "get_employee_contract", method: "get_employee_contract",
}).then(function (data) { }).then(function (data) {
if(data){
var segColor = {}; var segColor = {};
var vis = d3.select(elem[0]).append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")"); var vis = d3.select(elem[0]).append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")");
var pie = d3.layout.pie().value(function(d){return d.value;}); var pie = d3.layout.pie().value(function(d){return d.value;});
@ -665,6 +671,7 @@ var PayrollDashboard = AbstractAction.extend({
// create the third column for each segment. // create the third column for each segment.
tr.append("td").attr("class",'legendFreq').attr("style","border: 5px solid transparent; font-weight: bold;") tr.append("td").attr("class",'legendFreq').attr("style","border: 5px solid transparent; font-weight: bold;")
.text(function(d){ return d.value;}); .text(function(d){ return d.value;});
}
}); });
}, },
@ -674,6 +681,7 @@ var PayrollDashboard = AbstractAction.extend({
model: "hr.employee", model: "hr.employee",
method: "employee_leave_trend", method: "employee_leave_trend",
}).then(function (data) { }).then(function (data) {
if(data){
var elem = self.$('.leave_trend'); var elem = self.$('.leave_trend');
var margin = {top: 30, right: 20, bottom: 30, left: 80}, var margin = {top: 30, right: 20, bottom: 30, left: 80},
width = 500 - margin.left - margin.right, width = 500 - margin.left - margin.right,
@ -729,8 +737,8 @@ var PayrollDashboard = AbstractAction.extend({
.attr("r", 3) .attr("r", 3)
.attr("cx", function(d) { return x(d.l_month); }) .attr("cx", function(d) { return x(d.l_month); })
.attr("cy", function(d) { return y(d.leave); }) .attr("cy", function(d) { return y(d.leave); })
// .on('mouseover', function() { d3.select(this).transition().duration(500).ease("elastic").attr('r', 3 * 2) }) // .on('mouseover', function() { d3.select(this).transition().duration(500).ease("elastic").attr('r', 3 * 2) })
// .on('mouseout', function() { d3.select(this).transition().duration(500).ease("in-out").attr('r', 3) }); // .on('mouseout', function() { d3.select(this).transition().duration(500).ease("in-out").attr('r', 3) });
.on("mouseover", function() { tooltip.style("display", null); .on("mouseover", function() { tooltip.style("display", null);
d3.select(this).transition().duration(500).ease("elastic").attr('r', 3 * 2) d3.select(this).transition().duration(500).ease("elastic").attr('r', 3 * 2)
}) })
@ -760,7 +768,7 @@ var PayrollDashboard = AbstractAction.extend({
.style("text-anchor", "middle") .style("text-anchor", "middle")
.attr("font-size", "12px") .attr("font-size", "12px")
.attr("font-weight", "bold"); .attr("font-weight", "bold");
}
}); });
}, },

22
hr_payroll_dashboard/static/src/xml/payroll_dashboard.xml

@ -6,6 +6,20 @@
</div> </div>
</div> </div>
</t> </t>
<t t-name="EmployeeWarning">
<div class="row" style="margin-top:1%;margin-left:40%;">
<div class="col-md-12 ">
<div>
<div class="rounded mx-auto d-block">
<div>
<p style="color:red;">Error : Could not find employee linked to user</p>
<p style="color:red;">Please contact system admin for the setup</p>
</div>
</div>
</div>
</div>
</div>
</t>
<t t-name="EmployeeDetails"> <t t-name="EmployeeDetails">
<link rel="stylesheet" <link rel="stylesheet"
href="/hr_payroll_dashboard/static/src/css/dashboard.css"/> href="/hr_payroll_dashboard/static/src/css/dashboard.css"/>
@ -83,7 +97,7 @@
<div class="oh-card-body"> <div class="oh-card-body">
<div class="stat-widget-one"> <div class="stat-widget-one">
<div class="stat-icon" style="background:#FCF030"> <div class="stat-icon" style="background:#FCF030">
<i class='fa fa-money'></i> <i class='fa fa-money'/>
</div> </div>
<div class="stat-content"> <div class="stat-content">
<div class="stat-head">Salary Rules</div> <div class="stat-head">Salary Rules</div>
@ -100,7 +114,7 @@
<div class="oh-card-body"> <div class="oh-card-body">
<div class="stat-widget-one"> <div class="stat-widget-one">
<div class="stat-icon" style="background:#FFA742"> <div class="stat-icon" style="background:#FFA742">
<i class='fa fa-money'></i> <i class='fa fa-money'/>
</div> </div>
<div class="stat-content"> <div class="stat-content">
<div class="stat-head">Salary Structures</div> <div class="stat-head">Salary Structures</div>
@ -175,8 +189,8 @@
</t> </t>
<t t-name="PayrollManagerDashboard"> <t t-name="PayrollManagerDashboard">
<br></br> <br/>
<br></br> <br/>
<div class="row" style="margin:0px;"> <div class="row" style="margin:0px;">
<div class="col-md-4" id="col-graph"> <div class="col-md-4" id="col-graph">
<div class="card"> <div class="card">

Loading…
Cancel
Save