Fixed salary structure employee patches

This commit is contained in:
Nabin Hait 2018-07-30 10:52:35 +05:30
parent 749094dd52
commit cce7c5c245
4 changed files with 17 additions and 34 deletions

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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))