diff --git a/erpnext/hr/doctype/salary_detail/salary_detail.json b/erpnext/hr/doctype/salary_detail/salary_detail.json
index 3bb621bb62..99c705af56 100644
--- a/erpnext/hr/doctype/salary_detail/salary_detail.json
+++ b/erpnext/hr/doctype/salary_detail/salary_detail.json
@@ -300,7 +300,7 @@
"label": "Condition and Formula Help",
"length": 0,
"no_copy": 0,
- "options": "
Condition and Formula Help
\n\nNotes:
\n\n\n- Use field
base
for using base salary of the Employee \n- Use Salary Component abbreviations in conditions and formulas.
BS = Basic Salary
\n- Use field name for employee details in conditions and formulas.
Employment Type = employment_type
Branch = branch
\n- Direct Amount can also be entered based on Condtion. See example 3
\n\nExamples
\n\n- Calculating Basic Salary based on
base
\nCondition: base < 10000
\nFormula: base * .2
\n- Calculating HRA based on Basic Salary
BS
\nCondition: BS > 2000
\nFormula: BS * .1
\n- Calculating TDS based on Employment Type
employment_type
\nCondition: employment_type==\"Intern\"
\nAmount: 1000
\n
",
+ "options": "Condition and Formula Help
\n\nNotes:
\n\n\n- Use field
base
for using base salary of the Employee \n- Use Salary Component abbreviations in conditions and formulas.
BS = Basic Salary
\n- Use field name for employee details in conditions and formulas.
Employment Type = employment_type
Branch = branch
\n- Use field name from Salary Slip in conditions and formulas.
Payment Days = payment_days
Leave without pay = leave_without_pay
\n- Direct Amount can also be entered based on Condtion. See example 3
\n\nExamples
\n\n- Calculating Basic Salary based on
base
\nCondition: base < 10000
\nFormula: base * .2
\n- Calculating HRA based on Basic Salary
BS
\nCondition: BS > 2000
\nFormula: BS * .1
\n- Calculating TDS based on Employment Type
employment_type
\nCondition: employment_type==\"Intern\"
\nAmount: 1000
\n
",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -323,7 +323,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2016-08-23 15:26:07.754570",
+ "modified": "2016-09-20 05:29:26.373992",
"modified_by": "Administrator",
"module": "HR",
"name": "Salary Detail",
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index 1918f921c7..7727652c44 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -31,7 +31,7 @@ class SalarySlip(TransactionBase):
self.get_leave_details(lwp = self.leave_without_pay)
# if self.salary_slip_based_on_timesheet or not self.net_pay:
- # self.calculate_net_pay()
+ self.calculate_net_pay()
company_currency = get_company_currency(self.company)
self.total_in_words = money_in_words(self.rounded_total, company_currency)
@@ -52,15 +52,27 @@ class SalarySlip(TransactionBase):
data = self.get_data_for_eval()
for key in ('earnings', 'deductions'):
- for d in self._salary_structure_doc.get(key):
- amount = self.eval_condition_and_formula(d, data)
- if amount:
- self.append(key, {
- 'amount': amount,
- 'default_amount': amount,
- 'depends_on_lwp' : d.depends_on_lwp,
- 'salary_component' : d.salary_component
- })
+ for struct_row in self._salary_structure_doc.get(key):
+ amount = self.eval_condition_and_formula(struct_row, data)
+ if amount:
+ self.update_component_row(struct_row, amount, key)
+
+
+ def update_component_row(self, struct_row, amount, key):
+ component_row = None
+ for d in self.get(key):
+ if d.salary_component == struct_row.salary_component:
+ component_row = d
+
+ if not component_row:
+ self.append(key, {
+ 'amount': amount,
+ 'default_amount': amount,
+ 'depends_on_lwp' : struct_row.depends_on_lwp,
+ 'salary_component' : struct_row.salary_component
+ })
+ else:
+ component_row.amount = amount
def eval_condition_and_formula(self, d, data):
try:
@@ -74,6 +86,7 @@ class SalarySlip(TransactionBase):
amount = eval(d.formula, None, data)
data[d.abbr] = amount
+
return amount
except NameError as err:
frappe.throw(_("Name error: {0}".format(err)))
@@ -92,6 +105,7 @@ class SalarySlip(TransactionBase):
data.base, data.variable = d.base, d.variable
data.update(frappe.get_doc("Employee", self.employee).as_dict())
+ data.update(self.as_dict())
# set values for components
salary_components = frappe.get_all("Salary Component", fields=["salary_component_abbr"])