Skip to content

Commit

Permalink
fix(Payroll): skip dependent component update if no formula is set (b…
Browse files Browse the repository at this point in the history
…ackport #2152) (#2153)

(cherry picked from commit eaa8d3d)

Co-authored-by: Rucha Mahabal <[email protected]>
  • Loading branch information
mergify[bot] and ruchamahabal authored Sep 4, 2024
1 parent 587a7b4 commit 190959f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,11 @@ def is_var_updated(var: str | list[str]) -> bool:
other_component_type = "deductions" if component_type == "earnings" else "earnings"

for d in self._salary_structure_doc.get(component_type):
if not d.amount_based_on_formula:
continue
for var in get_variables_from_formula(d.formula):
if is_var_updated(var):
self.add_structure_component(d, component_type)
self.update_dependent_components_recursively(other_component_type, d.abbr)
if d.amount_based_on_formula and d.formula:
for var in get_variables_from_formula(d.formula):
if is_var_updated(var):
self.add_structure_component(d, component_type)
self.update_dependent_components_recursively(other_component_type, d.abbr)

def set_net_pay(self):
self.total_deduction = self.get_component_totals("deductions")
Expand Down Expand Up @@ -2350,4 +2349,6 @@ def email_salary_slips(names) -> None:


def get_variables_from_formula(formula: str) -> list[str]:
# compile expects a string
formula = cstr(formula)
return [node.id for node in ast.walk(ast.parse(formula, mode="eval")) if isinstance(node, ast.Name)]

0 comments on commit 190959f

Please sign in to comment.