Skip to content

Commit

Permalink
feat: provision to display zero value salary components on salary slip
Browse files Browse the repository at this point in the history
(cherry picked from commit b851735)
  • Loading branch information
saurabh6790 authored and mergify[bot] committed May 2, 2023
1 parent e25e7cf commit 109ba11
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
14 changes: 13 additions & 1 deletion hrms/payroll/doctype/payroll_settings/payroll_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"disable_rounded_total",
"include_holidays_in_total_working_days",
"show_leave_balances_in_salary_slip",
"column_break_rnoq",
"define_opening_balance_for_earning_and_deductions",
"process_payroll_accounting_entry_based_on_employee",
"include_zero_value_salary_component_in_salary_slip",
"column_break_6",
"max_working_hours_against_timesheet",
"daily_wages_fraction_for_half_day",
Expand Down Expand Up @@ -107,13 +109,23 @@
"fieldname": "define_opening_balance_for_earning_and_deductions",
"fieldtype": "Check",
"label": "Define Opening Balance for Earning and Deductions"
},
{
"default": "0",
"fieldname": "include_zero_value_salary_component_in_salary_slip",
"fieldtype": "Check",
"label": "Include Zero Value Salary Component in Salary Slip"
},
{
"fieldname": "column_break_rnoq",
"fieldtype": "Column Break"
}
],
"icon": "fa fa-cog",
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-01-05 10:22:22.425409",
"modified": "2023-02-22 12:21:31.266958",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Settings",
Expand Down
35 changes: 26 additions & 9 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ def calculate_component_amounts(self, component_type):

def add_structure_components(self, component_type):
self.data, self.default_data = self.get_data_for_eval()
allow_zero_value_component = frappe.db.get_single_value(
"Payroll Settings", "include_zero_value_salary_component_in_salary_slip"
)

timesheet_component = frappe.db.get_value(
"Salary Structure", self.salary_structure, "salary_component"
Expand All @@ -966,11 +969,22 @@ def add_structure_components(self, component_type):
self.default_data[struct_row.abbr] = amount
self.data[struct_row.abbr] = flt(payment_days_amount, struct_row.precision("amount"))

elif amount or struct_row.amount_based_on_formula and amount is not None:
default_amount = self.eval_condition_and_formula(struct_row, self.default_data)
self.update_component_row(
struct_row, amount, component_type, data=self.data, default_amount=default_amount
)
else:
if amount or (struct_row.amount_based_on_formula and amount is not None):
default_amount = self.eval_condition_and_formula(struct_row, self.default_data)
self.update_component_row(
struct_row,
amount,
component_type,
data=self.data,
default_amount=default_amount,
allow_zero_value_component=allow_zero_value_component,
)

if allow_zero_value_component:
self.update_component_row(
struct_row, amount, component_type, allow_zero_value_component=allow_zero_value_component
)

def get_data_for_eval(self):
"""Returns data for evaluating formula"""
Expand Down Expand Up @@ -1151,6 +1165,7 @@ def update_component_row(
is_recurring=0,
data=None,
default_amount=None,
allow_zero_value_component=None,
):
component_row = None
for d in self.get(component_type):
Expand All @@ -1177,7 +1192,7 @@ def update_component_row(
)

if not component_row:
if not amount:
if not amount and not allow_zero_value_component:
return

component_row = self.append(component_type)
Expand Down Expand Up @@ -1217,19 +1232,21 @@ def update_component_row(

component_row.amount = amount

self.update_component_amount_based_on_payment_days(component_row)
self.update_component_amount_based_on_payment_days(component_row, allow_zero_value_component)

if data:
data[component_row.abbr] = component_row.amount

def update_component_amount_based_on_payment_days(self, component_row):
def update_component_amount_based_on_payment_days(
self, component_row, allow_zero_value_component=None
):
joining_date, relieving_date = self.get_joining_and_relieving_dates()
component_row.amount = self.get_amount_based_on_payment_days(
component_row, joining_date, relieving_date
)[0]

# remove 0 valued components that have been updated later
if component_row.amount == 0:
if component_row.amount == 0 and not allow_zero_value_component:
self.remove(component_row)

def set_precision_for_component_amounts(self):
Expand Down

0 comments on commit 109ba11

Please sign in to comment.