From cce7c5c245218769832dfe9b570a172c4404570b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 30 Jul 2018 10:52:35 +0530 Subject: [PATCH] Fixed salary structure employee patches --- erpnext/patches.txt | 2 -- .../create_salary_structure_assignments.py | 23 ++++++++++++++----- ...yee_parent_to_child_in_salary_structure.py | 17 -------------- ...dates_from_salary_structure_to_employee.py | 9 -------- 4 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 erpnext/patches/v7_0/move_employee_parent_to_child_in_salary_structure.py delete mode 100644 erpnext/patches/v7_2/move_dates_from_salary_structure_to_employee.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 20def27ced..7d069eca42 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -379,7 +379,6 @@ erpnext.patches.v7_2.empty_supplied_items_for_non_subcontracted erpnext.patches.v7_2.arrear_leave_encashment_as_salary_component erpnext.patches.v7_2.rename_att_date_attendance erpnext.patches.v7_2.update_attendance_docstatus -erpnext.patches.v7_2.move_dates_from_salary_structure_to_employee erpnext.patches.v7_2.make_all_assessment_group erpnext.patches.v8_0.repost_reserved_qty_for_multiple_sales_uom erpnext.patches.v8_0.addresses_linked_to_lead @@ -445,7 +444,6 @@ erpnext.patches.v8_8.set_bom_rate_as_per_uom erpnext.patches.v8_8.add_new_fields_in_accounts_settings erpnext.patches.v8_9.set_print_zero_amount_taxes erpnext.patches.v8_9.set_default_customer_group -erpnext.patches.v8_9.remove_employee_from_salary_structure_parent erpnext.patches.v8_9.delete_gst_doctypes_for_outside_india_accounts erpnext.patches.v8_9.set_default_fields_in_variant_settings erpnext.patches.v8_9.update_billing_gstin_for_indian_account diff --git a/erpnext/patches/v11_0/create_salary_structure_assignments.py b/erpnext/patches/v11_0/create_salary_structure_assignments.py index 712269ae6d..596fe8418d 100644 --- a/erpnext/patches/v11_0/create_salary_structure_assignments.py +++ b/erpnext/patches/v11_0/create_salary_structure_assignments.py @@ -7,21 +7,32 @@ from datetime import datetime from erpnext.hr.doctype.salary_structure_assignment.salary_structure_assignment import DuplicateAssignment def execute(): + frappe.reload_doc('hr', 'doctype', 'salary_structure') frappe.reload_doc("hr", "doctype", "salary_structure_assignment") frappe.db.sql(""" delete from `tabSalary Structure Assignment` where salary_structure in (select name from `tabSalary Structure` where is_active='No' or docstatus!=1) """) - for d in frappe.db.sql(""" - select sse.*, ss.company - from `tabSalary Structure Employee` sse, `tabSalary Structure` ss - where ss.name = sse.parent AND ss.is_active='Yes' - AND sse.employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')""", as_dict=1): + if frappe.db.table_exists('Salary Structure Employee'): + ss_details = frappe.db.sql(""" + select sse.employee, sse.employee_name, sse.from_date, sse.to_date, + sse.base, sse.variable, sse.parent as salary_structure, ss.company + from `tabSalary Structure Employee` sse, `tabSalary Structure` ss + where ss.name = sse.parent AND ss.is_active='Yes' + AND sse.employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')""", as_dict=1) + else: + ss_details = frappe.db.sql(""" + select name as salary_structure, employee, employee_name, from_date, to_date, base, variable, company + from `tabSalary Structure` + where is_active='Yes' + AND sse.employee in (select name from `tabEmployee` where ifNull(status, '') != 'Left')""", as_dict=1) + + for d in ss_details: try: s = frappe.new_doc("Salary Structure Assignment") s.employee = d.employee s.employee_name = d.employee_name - s.salary_structure = d.parent + s.salary_structure = d.salary_structure s.from_date = d.from_date s.to_date = d.to_date if isinstance(d.to_date, datetime) else None s.base = d.base diff --git a/erpnext/patches/v7_0/move_employee_parent_to_child_in_salary_structure.py b/erpnext/patches/v7_0/move_employee_parent_to_child_in_salary_structure.py deleted file mode 100644 index b5172db638..0000000000 --- a/erpnext/patches/v7_0/move_employee_parent_to_child_in_salary_structure.py +++ /dev/null @@ -1,17 +0,0 @@ -import frappe - -def execute(): - frappe.reload_doc('hr', 'doctype', 'salary_structure') - frappe.reload_doc('hr', 'doctype', 'salary_structure_employee') - if not frappe.db.has_column('Salary Structure', 'employees'): - return - for ss in frappe.db.sql(""" select employee, name from `tabSalary Structure`""", as_dict=True): - ss_doc = frappe.get_doc('Salary Structure', ss.name) - salary_employee = ss_doc.append('employees',{}) - salary_employee.employee = ss.employee - salary_employee.base = 0 - if not ss_doc.company: - ss_doc.company = frappe.db.get_value('Employee', salary_employee.employee, 'company') - ss_doc.flags.ignore_validate = True - ss_doc.flags.ignore_mandatory = True - ss_doc.save() diff --git a/erpnext/patches/v7_2/move_dates_from_salary_structure_to_employee.py b/erpnext/patches/v7_2/move_dates_from_salary_structure_to_employee.py deleted file mode 100644 index 98e076e060..0000000000 --- a/erpnext/patches/v7_2/move_dates_from_salary_structure_to_employee.py +++ /dev/null @@ -1,9 +0,0 @@ -import frappe - -def execute(): - frappe.reload_doc('hr', 'doctype', 'salary_structure_employee') - salary_structures = frappe.db.sql("""select name, to_date, from_date from `tabSalary Structure`""", as_dict=True) - - for salary_structure in salary_structures: - frappe.db.sql(""" update `tabSalary Structure Employee` set from_date = %s, to_date = %s - where parent = %s """, (salary_structure.from_date, salary_structure.to_date or 'null', salary_structure.name)) \ No newline at end of file