mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +00:00
[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:
committed by
Nabin Hait
parent
35438b6fc0
commit
aac8349391
@@ -75,13 +75,15 @@ class SalarySlip(TransactionBase):
|
|||||||
|
|
||||||
def eval_condition_and_formula(self, d, data):
|
def eval_condition_and_formula(self, d, data):
|
||||||
try:
|
try:
|
||||||
if d.condition:
|
condition = d.condition.strip() if d.condition else None
|
||||||
if not frappe.safe_eval(d.condition, None, data):
|
if condition:
|
||||||
|
if not frappe.safe_eval(condition, None, data):
|
||||||
return None
|
return None
|
||||||
amount = d.amount
|
amount = d.amount
|
||||||
if d.amount_based_on_formula:
|
if d.amount_based_on_formula:
|
||||||
if d.formula:
|
formula = d.formula.strip() if d.formula else None
|
||||||
amount = frappe.safe_eval(d.formula, None, data)
|
if formula:
|
||||||
|
amount = frappe.safe_eval(formula, None, data)
|
||||||
if amount:
|
if amount:
|
||||||
data[d.abbr] = amount
|
data[d.abbr] = amount
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class SalaryStructure(Document):
|
|||||||
for e in self.get('employees'):
|
for e in self.get('employees'):
|
||||||
set_employee_name(e)
|
set_employee_name(e)
|
||||||
self.validate_date()
|
self.validate_date()
|
||||||
|
self.strip_condition_and_formula_fields()
|
||||||
|
|
||||||
def get_ss_values(self,employee):
|
def get_ss_values(self,employee):
|
||||||
basic_info = frappe.db.sql("""select bank_name, bank_ac_no
|
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")
|
frappe.throw(_("Active Salary Structure {0} found for employee {1} for the given dates")
|
||||||
.format(st_name[0][0], employee.employee))
|
.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()
|
@frappe.whitelist()
|
||||||
def make_salary_slip(source_name, target_doc = None, employee = None, as_print = False, print_format = None):
|
def make_salary_slip(source_name, target_doc = None, employee = None, as_print = False, print_format = None):
|
||||||
def postprocess(source, target):
|
def postprocess(source, target):
|
||||||
|
|||||||
@@ -45,6 +45,26 @@ class TestSalaryStructure(unittest.TestCase):
|
|||||||
self.assertEquals(sal_slip.get("total_deduction"), 7500)
|
self.assertEquals(sal_slip.get("total_deduction"), 7500)
|
||||||
self.assertEquals(sal_slip.get("net_pay"), 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):
|
def make_employee(user):
|
||||||
if not frappe.db.get_value("User", user):
|
if not frappe.db.get_value("User", user):
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
|
|||||||
Reference in New Issue
Block a user