From c526cad18367e5c1692324075c0db19bc81e1f8c Mon Sep 17 00:00:00 2001 From: Jamsheer Date: Wed, 20 Jun 2018 10:52:20 +0530 Subject: [PATCH] [Fix] Additional Salary Component and tax calculation (#14581) * Additional salary not include in tax calculation * Additional salary get doubled in salary slip via Payroll Entry - Fix * Salary Component - if is_additional_component hide flexi --- .../additional_salary/additional_salary.py | 2 ++ .../salary_component/salary_component.json | 4 ++-- erpnext/hr/doctype/salary_slip/salary_slip.py | 23 ++++++++----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/erpnext/hr/doctype/additional_salary/additional_salary.py b/erpnext/hr/doctype/additional_salary/additional_salary.py index 99c6838dad..ac872ae778 100644 --- a/erpnext/hr/doctype/additional_salary/additional_salary.py +++ b/erpnext/hr/doctype/additional_salary/additional_salary.py @@ -64,6 +64,8 @@ def get_additional_salary_component(employee, start_date, end_date): struct_row['salary_component'] = salary_component.name struct_row['abbr'] = salary_component.salary_component_abbr struct_row['do_not_include_in_total'] = salary_component.do_not_include_in_total + struct_row['is_tax_applicable'] = salary_component.is_tax_applicable + struct_row['variable_based_on_taxable_salary'] = salary_component.variable_based_on_taxable_salary additional_components_dict['amount'] = amount additional_components_dict['struct_row'] = struct_row additional_components_dict['type'] = salary_component.type diff --git a/erpnext/hr/doctype/salary_component/salary_component.json b/erpnext/hr/doctype/salary_component/salary_component.json index 6355bf49fb..fd6fb17d2d 100644 --- a/erpnext/hr/doctype/salary_component/salary_component.json +++ b/erpnext/hr/doctype/salary_component/salary_component.json @@ -410,7 +410,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:doc.type==\"Earning\"", + "depends_on": "eval:doc.type==\"Earning\" && doc.is_additional_component != 1", "fieldname": "flexible_benefits", "fieldtype": "Section Break", "hidden": 0, @@ -1002,7 +1002,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-06-12 12:09:14.420657", + "modified": "2018-06-19 11:37:27.521796", "modified_by": "Administrator", "module": "HR", "name": "Salary Component", diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py index 03f1cd8629..47f1cc4b07 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -63,27 +63,29 @@ class SalarySlip(TransactionBase): for key in ('earnings', 'deductions'): for struct_row in self._salary_structure_doc.get(key): amount = self.eval_condition_and_formula(struct_row, data) - if amount and struct_row.statistical_component == 0: + if amount and struct_row.statistical_component == 0 and struct_row.variable_based_on_taxable_salary != 1: self.update_component_row(struct_row, amount, key) if key=="earnings" and struct_row.is_flexible_benefit == 1: self.add_employee_flexi_benefits(struct_row) - if key=="deductions" and struct_row.variable_based_on_taxable_salary: - tax_row, amount = self.calculate_variable_based_on_taxable_salary(struct_row.salary_component) - if tax_row and amount: - self.update_component_row(frappe._dict(tax_row), amount, key) - additional_components = get_additional_salary_component(self.employee, self.start_date, self.end_date) if additional_components: for additional_component in additional_components: additional_component = frappe._dict(additional_component) - amount = additional_component.amount + self.get_amount_from_exisiting_component(frappe._dict(additional_component.struct_row).salary_component) + amount = additional_component.amount key = "earnings" if additional_component.type == "Deduction": key = "deductions" self.update_component_row(frappe._dict(additional_component.struct_row), amount, key) + # Calculate variable_based_on_taxable_salary after all components updated in salary slip + for struct_row in self._salary_structure_doc.get("deductions"): + if struct_row.variable_based_on_taxable_salary == 1: + tax_row, amount = self.calculate_variable_based_on_taxable_salary(struct_row.salary_component) + if tax_row and amount: + self.update_component_row(frappe._dict(tax_row), amount, "deductions") + def add_employee_flexi_benefits(self, struct_row): if frappe.db.get_value("Salary Component", struct_row.salary_component, "is_pro_rata_applicable") == 1: benefit_component_amount = get_benefit_component_amount(self.employee, self.start_date, self.end_date, struct_row, self._salary_structure_doc, self.payment_days, self.total_working_days) @@ -94,13 +96,6 @@ class SalarySlip(TransactionBase): if benefit_claim_amount: self.update_component_row(struct_row, benefit_claim_amount, "earnings") - def get_amount_from_exisiting_component(self, salary_component): - amount = 0 - for d in self.get("earnings"): - if d.salary_component == salary_component: - amount = d.amount - return amount - def update_component_row(self, struct_row, amount, key): component_row = None for d in self.get(key):