Skip to content

Commit

Permalink
test: add test for circular dependency
Browse files Browse the repository at this point in the history
(cherry picked from commit 3684581)
  • Loading branch information
krantheman authored and mergify[bot] committed Aug 28, 2024
1 parent 666b91d commit 3bd3e75
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
3 changes: 1 addition & 2 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,7 @@ def set_gross_pay_and_base_gross_pay():
self.update_dependent_components_recursively("earnings", deduction_abbrs)

set_gross_pay_and_base_gross_pay()
self.update_dependent_components_recursively("deductions", "gross_pay")
self.update_dependent_components_recursively("deductions", "base_gross_pay")
self.update_dependent_components_recursively("deductions", ["gross_pay", "base_gross_pay"])

set_loan_repayment(self)

Expand Down
63 changes: 63 additions & 0 deletions hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,69 @@ def test_variable_tax_component(self):
self.assertEqual(test_tds.accounts[0].company, salary_slip.company)
self.assertListEqual(tax_component, ["_Test TDS"])

def test_circular_dependency_in_formula(self):
from hrms.payroll.doctype.salary_structure.test_salary_structure import (
create_salary_structure_assignment,
)

earnings = [
{
"salary_component": "Dependent Earning",
"abbr": "DE",
"type": "Earning",
"depends_on_payment_days": 0,
"amount_based_on_formula": 1,
"formula": "ID * 10",
},
]
make_salary_component(earnings, False, company_list=[])

deductions = [
{
"salary_component": "Independent Deduction",
"abbr": "ID",
"type": "Deduction",
"amount": 500,
},
{
"salary_component": "Dependent Deduction",
"abbr": "DD",
"type": "Deduction",
"amount_based_on_formula": 1,
"formula": "DE / 5",
},
]
make_salary_component(deductions, False, company_list=[])

details = {
"doctype": "Salary Structure",
"name": "Test Salary Structure for Circular Dependency",
"company": "_Test Company",
"payroll_frequency": "Monthly",
"payment_account": get_random("Account", filters={"account_currency": "USD"}),
"currency": "INR",
}
salary_structure = frappe.get_doc(details)

for entry in earnings:
salary_structure.append("earnings", entry)
for entry in deductions:
salary_structure.append("deductions", entry)

salary_structure.insert()
salary_structure.submit()

emp = make_employee("[email protected]", company="_Test Company")

create_salary_structure_assignment(emp, salary_structure.name, currency="INR")
salary_slip = make_salary_slip(
salary_structure.name, employee=emp, posting_date=getdate(), for_preview=1
)

self.assertEqual(salary_slip.gross_pay, 5000)
self.assertEqual(salary_slip.earnings[0].amount, 5000)
self.assertEqual(salary_slip.deductions[1].amount, 1000)


class TestSalarySlipSafeEval(FrappeTestCase):
def test_safe_eval_for_salary_slip(self):
Expand Down

0 comments on commit 3bd3e75

Please sign in to comment.