Skip to content

Commit

Permalink
Merge pull request #2149 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
ruchamahabal committed Sep 4, 2024
2 parents 27e0c4b + 587a7b4 commit 695ca03
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
19 changes: 11 additions & 8 deletions hrms/payroll/doctype/salary_component/test_salary_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,42 @@ def test_update_salary_structures(self):
salary_structure3 = make_salary_structure("Salary Structure 3", "Monthly")
salary_structure3.cancel() # Details should not update for cancelled Salary Structures

OLD_FORMULA = "BS\n*.5"
OLD_CONDITION = "H < 10000"

ss1_detail = next(
(d for d in salary_structure1.earnings if d.salary_component == "Special Allowance"), None
)
self.assertEqual(ss1_detail.condition, "H < 10000")
self.assertEqual(ss1_detail.formula, "BS*.5")
self.assertEqual(ss1_detail.condition, OLD_CONDITION)
self.assertEqual(ss1_detail.formula, OLD_FORMULA)

ss2_detail = next(
(d for d in salary_structure2.earnings if d.salary_component == "Special Allowance"), None
)
self.assertEqual(ss2_detail.condition, "H < 10000")
self.assertEqual(ss2_detail.formula, "BS*.5")
self.assertEqual(ss2_detail.condition, OLD_CONDITION)
self.assertEqual(ss2_detail.formula, OLD_FORMULA)

ss3_detail = next(
(d for d in salary_structure3.earnings if d.salary_component == "Special Allowance"), None
)
self.assertEqual(ss3_detail.condition, "H < 10000")
self.assertEqual(ss3_detail.formula, "BS*.5")
self.assertEqual(ss3_detail.condition, OLD_CONDITION)
self.assertEqual(ss3_detail.formula, OLD_FORMULA)

salary_component.update_salary_structures("condition", "H < 8000")
ss1_detail.reload()
self.assertEqual(ss1_detail.condition, "H < 8000")
ss2_detail.reload()
self.assertEqual(ss2_detail.condition, "H < 8000")
ss3_detail.reload()
self.assertEqual(ss3_detail.condition, "H < 10000")
self.assertEqual(ss3_detail.condition, OLD_CONDITION)

salary_component.update_salary_structures("formula", "BS*.3")
ss1_detail.reload()
self.assertEqual(ss1_detail.formula, "BS*.3")
ss2_detail.reload()
self.assertEqual(ss2_detail.formula, "BS*.3")
ss3_detail.reload()
self.assertEqual(ss3_detail.formula, "BS*.5")
self.assertEqual(ss3_detail.formula, OLD_FORMULA)


def create_salary_component(component_name, **args):
Expand Down
2 changes: 1 addition & 1 deletion hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def get_emp_and_working_day_details(self):
struct = self.check_sal_struct()

if struct:
self._salary_structure_doc = frappe.get_cached_doc("Salary Structure", struct)
self.set_salary_structure_doc()
self.salary_slip_based_on_timesheet = (
self._salary_structure_doc.salary_slip_based_on_timesheet or 0
)
Expand Down
3 changes: 2 additions & 1 deletion hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,8 @@ def make_earning_salary_component(
"salary_component": "Special Allowance",
"abbr": "SA",
"condition": "H < 10000",
"formula": "BS*.5",
# intentional to test multiline formula
"formula": "BS\n*.5",
"type": "Earning",
"amount_based_on_formula": 1,
"depends_on_payment_days": 0,
Expand Down
20 changes: 10 additions & 10 deletions hrms/payroll/doctype/salary_structure/test_salary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_years, date_diff, get_first_day, nowdate
from frappe.utils import add_years, cstr, date_diff, get_first_day, nowdate
from frappe.utils.make_random import get_random

import erpnext
Expand Down Expand Up @@ -91,23 +91,23 @@ def test_amount_totals(self):
self.assertEqual(salary_slip.get("net_pay"), 78000 - salary_slip.get("total_deduction"))

def test_whitespaces_in_formula_conditions_fields(self):
salary_structure = make_salary_structure("Salary Structure Sample", "Monthly", dont_submit=True)

for row in salary_structure.earnings:
def add_whitespaces(row):
row.formula = "\n%s\n\n" % row.formula
row.condition = "\n%s\n\n" % row.condition

for row in salary_structure.deductions:
row.formula = "\n%s\n\n" % row.formula
row.condition = "\n%s\n\n" % row.condition
salary_structure = make_salary_structure("Salary Structure Sample", "Monthly", dont_submit=True)
for table in ("earnings", "deductions"):
for row in salary_structure.get(table):
add_whitespaces(row)

salary_structure.save()
# sanitized before validate and reset to original state to maintain readability
salary_structure.sanitize_condition_and_formula_fields()

for row in salary_structure.earnings:
self.assertFalse("\n" in row.formula or "\n" in row.condition)
self.assertFalse("\n" in cstr(row.formula) or "\n" in cstr(row.condition))

for row in salary_structure.deductions:
self.assertFalse(("\n" in row.formula) or ("\n" in row.condition))
self.assertFalse("\n" in cstr(row.formula) or "\n" in cstr(row.condition))

def test_salary_structures_assignment(self):
company_currency = erpnext.get_default_currency()
Expand Down

0 comments on commit 695ca03

Please sign in to comment.