From d319feee9e3bfc42e7515ca4828aaa18e027d867 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Mon, 2 Mar 2020 18:24:55 +0530 Subject: [PATCH] fix: reverse linking --- .../doctype/additional_salary/additional_salary.json | 2 +- .../hr/doctype/additional_salary/additional_salary.py | 8 ++++++-- erpnext/hr/doctype/employee/test_employee.py | 2 +- erpnext/hr/doctype/salary_detail/salary_detail.json | 10 +++++++++- erpnext/hr/doctype/salary_slip/salary_slip.py | 9 +-------- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/erpnext/hr/doctype/additional_salary/additional_salary.json b/erpnext/hr/doctype/additional_salary/additional_salary.json index 91bcdc394a..bf9d8192d0 100644 --- a/erpnext/hr/doctype/additional_salary/additional_salary.json +++ b/erpnext/hr/doctype/additional_salary/additional_salary.json @@ -163,7 +163,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-03-05 18:54:17.763244", + "modified": "2020-03-02 18:06:29.170878", "modified_by": "Administrator", "module": "HR", "name": "Additional Salary", diff --git a/erpnext/hr/doctype/additional_salary/additional_salary.py b/erpnext/hr/doctype/additional_salary/additional_salary.py index d1b602d243..d8f7444beb 100644 --- a/erpnext/hr/doctype/additional_salary/additional_salary.py +++ b/erpnext/hr/doctype/additional_salary/additional_salary.py @@ -50,7 +50,7 @@ class AdditionalSalary(Document): @frappe.whitelist() def get_additional_salary_component(employee, start_date, end_date, component_type): additional_components = frappe.db.sql(""" - select salary_component, sum(amount) as amount, overwrite_salary_structure_amount, deduct_full_tax_on_selected_payroll_date + select name, salary_component, amount, overwrite_salary_structure_amount, deduct_full_tax_on_selected_payroll_date from `tabAdditional Salary` where employee=%(employee)s and docstatus = 1 @@ -60,7 +60,6 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty from_date <= %(to_date)s and to_date >= %(to_date)s ) and type = %(component_type)s - group by salary_component, overwrite_salary_structure_amount order by salary_component, overwrite_salary_structure_amount """, { 'employee': employee, @@ -70,8 +69,11 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty }, as_dict=1) additional_components_list = [] + existing_salary_components = [] component_fields = ["depends_on_payment_days", "salary_component_abbr", "is_tax_applicable", "variable_based_on_taxable_salary", 'type'] for d in additional_components: + if d.salary_component in existing_salary_components: + frappe.throw(_('Multiple additional Salary is created for Salary Component {0}'.format(d.salary_component))) struct_row = frappe._dict({'salary_component': d.salary_component}) component = frappe.get_all("Salary Component", filters={'name': d.salary_component}, fields=component_fields) if component: @@ -79,6 +81,7 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty struct_row['deduct_full_tax_on_selected_payroll_date'] = d.deduct_full_tax_on_selected_payroll_date struct_row['is_additional_component'] = 1 + struct_row['additional_salary'] = d.name additional_components_list.append(frappe._dict({ 'amount': d.amount, @@ -86,4 +89,5 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty 'struct_row': struct_row, 'overwrite': d.overwrite_salary_structure_amount, })) + existing_salary_components.append(d.salary_component) return additional_components_list \ No newline at end of file diff --git a/erpnext/hr/doctype/employee/test_employee.py b/erpnext/hr/doctype/employee/test_employee.py index 906386db11..d3410de2eb 100644 --- a/erpnext/hr/doctype/employee/test_employee.py +++ b/erpnext/hr/doctype/employee/test_employee.py @@ -51,7 +51,7 @@ def make_employee(user, company=None): "doctype": "User", "email": user, "first_name": user, - "new_password": "qwerty123@12435", + "new_password": "password", "roles": [{"doctype": "Has Role", "role": "Employee"}] }).insert() diff --git a/erpnext/hr/doctype/salary_detail/salary_detail.json b/erpnext/hr/doctype/salary_detail/salary_detail.json index bde735d3bc..5a55593506 100644 --- a/erpnext/hr/doctype/salary_detail/salary_detail.json +++ b/erpnext/hr/doctype/salary_detail/salary_detail.json @@ -25,6 +25,7 @@ "tax_on_flexible_benefit", "tax_on_additional_salary", "section_break_11", + "additional_salary", "condition_and_formula_help" ], "fields": [ @@ -187,11 +188,18 @@ "fieldtype": "HTML", "label": "Condition and Formula Help", "options": "

Condition and Formula Help

\n\n

Notes:

\n\n
    \n
  1. Use field base for using base salary of the Employee
  2. \n
  3. Use Salary Component abbreviations in conditions and formulas. BS = Basic Salary
  4. \n
  5. Use field name for employee details in conditions and formulas. Employment Type = employment_typeBranch = branch
  6. \n
  7. Use field name from Salary Slip in conditions and formulas. Payment Days = payment_daysLeave without pay = leave_without_pay
  8. \n
  9. Direct Amount can also be entered based on Condtion. See example 3
\n\n

Examples

\n
    \n
  1. Calculating Basic Salary based on base\n
    Condition: base < 10000
    \n
    Formula: base * .2
  2. \n
  3. Calculating HRA based on Basic SalaryBS \n
    Condition: BS > 2000
    \n
    Formula: BS * .1
  4. \n
  5. Calculating TDS based on Employment Typeemployment_type \n
    Condition: employment_type==\"Intern\"
    \n
    Amount: 1000
  6. \n
" + }, + { + "fieldname": "additional_salary", + "fieldtype": "Link", + "label": "Additional Salary ", + "options": "Additional Salary", + "read_only": 1 } ], "istable": 1, "links": [], - "modified": "2019-12-31 17:15:25.646689", + "modified": "2020-03-02 18:16:38.571005", "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 d03a3dd9a3..ac55c679a6 100644 --- a/erpnext/hr/doctype/salary_slip/salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/salary_slip.py @@ -442,6 +442,7 @@ class SalarySlip(TransactionBase): if amount: self.append(key, { 'amount': amount, + 'additional_salary': '' if not struct_row.get("additional_salary") else struct_row.get("additional_salary"), 'default_amount': amount if not struct_row.get("is_additional_component") else 0, 'depends_on_payment_days' : struct_row.depends_on_payment_days, 'salary_component' : struct_row.salary_component, @@ -790,14 +791,6 @@ class SalarySlip(TransactionBase): "repay_from_salary": 1, }) - - def update_salary_slip_in_additional_salary(self): - salary_slip = self.name if self.docstatus==1 else None - frappe.db.sql(""" - update `tabAdditional Salary` set salary_slip=%s - where employee=%s and payroll_date between %s and %s and docstatus=1 - """, (salary_slip, self.employee, self.start_date, self.end_date)) - def make_loan_repayment_entry(self): for loan in self.loans: repayment_entry = create_repayment_entry(loan.loan, self.employee,