feat: Add chart generation
diff --git a/erpnext/projects/report/employee_hours_utilisation_based_on_timesheet/employee_hours_utilisation_based_on_timesheet.py b/erpnext/projects/report/employee_hours_utilisation_based_on_timesheet/employee_hours_utilisation_based_on_timesheet.py
index e3d6b9b..8124c7a 100644
--- a/erpnext/projects/report/employee_hours_utilisation_based_on_timesheet/employee_hours_utilisation_based_on_timesheet.py
+++ b/erpnext/projects/report/employee_hours_utilisation_based_on_timesheet/employee_hours_utilisation_based_on_timesheet.py
@@ -30,8 +30,9 @@
self.generate_columns()
self.generate_data()
self.generate_report_summary()
+ self.generate_chart_data()
- return self.columns, self.data, None, None, self.report_summary
+ return self.columns, self.data, None, self.chart, self.report_summary
def generate_columns(self):
self.columns = [
@@ -87,6 +88,9 @@
row.update(data)
self.data.append(row)
+ # Sort by descending order of percentage utilisation
+ self.data.sort(key=lambda x: x['per_util'], reverse=True)
+
def generate_filtered_time_logs(self):
additional_filters = ''
@@ -149,3 +153,45 @@
'datatype': 'Percentage'
}
]
+
+ def generate_chart_data(self):
+ self.chart = {}
+
+ labels = []
+ billed_hours = []
+ non_billed_hours = []
+ untracked_hours = []
+
+
+ for row in self.data:
+ emp_name = frappe.db.get_value(
+ 'Employee', row['employee'], 'employee_name'
+ )
+ labels.append(emp_name)
+ billed_hours.append(row.get('billed_hours'))
+ non_billed_hours.append(row.get('non_billed_hours'))
+ untracked_hours.append(row.get('untracked_hours'))
+
+ self.chart = {
+ 'data': {
+ 'labels': labels[:30],
+ 'datasets': [
+ {
+ 'name': _('Billed Hours'),
+ 'values': billed_hours[:30]
+ },
+ {
+ 'name': _('Non-Billed Hours'),
+ 'values': non_billed_hours[:30]
+ },
+ {
+ 'name': _('Untracked Hours'),
+ 'values': untracked_hours[:30]
+ }
+ ]
+ },
+ 'type': 'bar',
+ 'barOptions': {
+ 'stacked': True
+ }
+ }