fix: Column value and data indentation
This commit is contained in:
parent
21a4f82f69
commit
c5588a9b93
@ -5,35 +5,59 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import flt
|
||||
from frappe import _
|
||||
from erpnext.hr.doctype.leave_application.leave_application \
|
||||
import get_leave_balance_on, get_leaves_for_period
|
||||
from erpnext.hr.doctype.leave_application.leave_application import get_leaves_for_period
|
||||
|
||||
from erpnext.hr.report.employee_leave_balance.employee_leave_balance \
|
||||
import get_total_allocated_leaves
|
||||
from ..employee_leave_balance.employee_leave_balance import get_total_allocated_leaves
|
||||
|
||||
def execute(filters=None):
|
||||
if filters.to_date <= filters.from_date:
|
||||
frappe.throw(_('From date can not be greater than than To date'))
|
||||
|
||||
columns = get_columns()
|
||||
data = get_data(filters)
|
||||
|
||||
return columns, data
|
||||
|
||||
def get_columns():
|
||||
columns = []
|
||||
columns.append(_('Leave Type') )
|
||||
columns.append(_('Employee'))
|
||||
columns.append(_('Employee Name'))
|
||||
columns.append(_('Opening Balance') + ':Float:160')
|
||||
columns.append(_('Leaves Taken') + ':Float:160')
|
||||
columns.append(_('Closing Balance') + ':Float:160')
|
||||
columns = [{
|
||||
'label': _('Leave Type'),
|
||||
'fieldtype': 'Link',
|
||||
'fieldname': 'leave_type',
|
||||
'width': 300,
|
||||
'options': 'Leave Type'
|
||||
}, {
|
||||
'label': _('Employee'),
|
||||
'fieldtype': 'Link',
|
||||
'fieldname': 'employee',
|
||||
'width': 100,
|
||||
'options': 'Employee'
|
||||
}, {
|
||||
'label': _('Employee Name'),
|
||||
'fieldtype': 'Data',
|
||||
'fieldname': 'employee_name',
|
||||
'width': 100,
|
||||
}, {
|
||||
'label': _('Opening Balance'),
|
||||
'fieldtype': 'float',
|
||||
'fieldname': 'opening_balance',
|
||||
'width': 160,
|
||||
}, {
|
||||
'label': _('Leaves Taken'),
|
||||
'fieldtype': 'float',
|
||||
'fieldname': 'leaves_taken',
|
||||
'width': 160,
|
||||
}, {
|
||||
'label': _('Closing Balance'),
|
||||
'fieldtype': 'float',
|
||||
'fieldname': 'closing_balance',
|
||||
'width': 160,
|
||||
}]
|
||||
|
||||
return columns
|
||||
|
||||
def get_data(filters):
|
||||
leave_types = frappe.db.sql_list("SELECT `name` FROM `tabLeave Type` ORDER BY `name` ASC")
|
||||
|
||||
if filters.to_date <= filters.from_date:
|
||||
frappe.throw(_('From date can not be greater than than To date'))
|
||||
|
||||
conditions = {
|
||||
'status': 'Active',
|
||||
}
|
||||
@ -48,8 +72,14 @@ def get_data(filters):
|
||||
data = []
|
||||
|
||||
for leave_type in leave_types:
|
||||
data.append({
|
||||
'leave_type': leave_type
|
||||
})
|
||||
for employee in active_employees:
|
||||
row = [leave_type, employee.name, employee.employee_name]
|
||||
row = frappe._dict({
|
||||
'employee': employee.name,
|
||||
'employee_name': employee.employee_name
|
||||
})
|
||||
|
||||
leaves_taken = get_leaves_for_period(employee.name, leave_type,
|
||||
filters.from_date, filters.to_date) * -1
|
||||
@ -57,7 +87,10 @@ def get_data(filters):
|
||||
opening = get_total_allocated_leaves(employee.name, leave_type, filters.from_date, filters.to_date)
|
||||
closing = flt(opening) - flt(leaves_taken)
|
||||
|
||||
row += [opening, leaves_taken, closing]
|
||||
row.opening_balance = opening
|
||||
row.leaves_taken = leaves_taken
|
||||
row.closing_balance = closing
|
||||
row.indent = 1
|
||||
data.append(row)
|
||||
|
||||
return data
|
||||
|
Loading…
x
Reference in New Issue
Block a user