[hotfix] remove the white spaces from condition and formula fields (#10331)
* [hotfix] remove the white spaces from condition and formula fields * [tests] added tests cases for whitespaces in formula and condition fields
This commit is contained in:
parent
35438b6fc0
commit
aac8349391
@ -75,13 +75,15 @@ class SalarySlip(TransactionBase):
|
||||
|
||||
def eval_condition_and_formula(self, d, data):
|
||||
try:
|
||||
if d.condition:
|
||||
if not frappe.safe_eval(d.condition, None, data):
|
||||
condition = d.condition.strip() if d.condition else None
|
||||
if condition:
|
||||
if not frappe.safe_eval(condition, None, data):
|
||||
return None
|
||||
amount = d.amount
|
||||
if d.amount_based_on_formula:
|
||||
if d.formula:
|
||||
amount = frappe.safe_eval(d.formula, None, data)
|
||||
formula = d.formula.strip() if d.formula else None
|
||||
if formula:
|
||||
amount = frappe.safe_eval(formula, None, data)
|
||||
if amount:
|
||||
data[d.abbr] = amount
|
||||
|
||||
|
@ -17,6 +17,7 @@ class SalaryStructure(Document):
|
||||
for e in self.get('employees'):
|
||||
set_employee_name(e)
|
||||
self.validate_date()
|
||||
self.strip_condition_and_formula_fields()
|
||||
|
||||
def get_ss_values(self,employee):
|
||||
basic_info = frappe.db.sql("""select bank_name, bank_ac_no
|
||||
@ -62,6 +63,16 @@ class SalaryStructure(Document):
|
||||
frappe.throw(_("Active Salary Structure {0} found for employee {1} for the given dates")
|
||||
.format(st_name[0][0], employee.employee))
|
||||
|
||||
def strip_condition_and_formula_fields(self):
|
||||
# remove whitespaces from condition and formula fields
|
||||
for row in self.earnings:
|
||||
row.condition = row.condition.strip() if row.condition else ""
|
||||
row.formula = row.formula.strip() if row.formula else ""
|
||||
|
||||
for row in self.deductions:
|
||||
row.condition = row.condition.strip() if row.condition else ""
|
||||
row.formula = row.formula.strip() if row.formula else ""
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_salary_slip(source_name, target_doc = None, employee = None, as_print = False, print_format = None):
|
||||
def postprocess(source, target):
|
||||
|
@ -44,6 +44,26 @@ class TestSalaryStructure(unittest.TestCase):
|
||||
self.assertEquals(sal_slip.get("deductions")[1].amount, 2500)
|
||||
self.assertEquals(sal_slip.get("total_deduction"), 7500)
|
||||
self.assertEquals(sal_slip.get("net_pay"), 7500)
|
||||
|
||||
def test_whitespaces_in_formula_conditions_fields(self):
|
||||
make_salary_structure("Salary Structure Sample")
|
||||
salary_structure = frappe.get_doc("Salary Structure", "Salary Structure Sample")
|
||||
|
||||
for row in salary_structure.earnings:
|
||||
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.save()
|
||||
|
||||
for row in salary_structure.earnings:
|
||||
self.assertFalse("\n" in row.formula or "\n" in row.condition)
|
||||
|
||||
for row in salary_structure.deductions:
|
||||
self.assertFalse(("\n" in row.formula) or ("\n" in row.condition))
|
||||
|
||||
def make_employee(user):
|
||||
if not frappe.db.get_value("User", user):
|
||||
|
Loading…
x
Reference in New Issue
Block a user