update missing salary component abbr

This commit is contained in:
Nabin Hait
2016-11-16 12:55:17 +05:30
parent d65d67e0a7
commit 00e841d744
3 changed files with 41 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr
'''
Some components do not have type set, try and guess whether they turn up in
@@ -8,18 +9,38 @@ earnings or deductions in existing salary slips
'''
def execute():
for s in frappe.db.sql('select name from `tabSalary Component` where ifnull(type, "")=""'):
compontent = frappe.get_doc('Salary Component', s[0])
for s in frappe.db.sql('''select name, type, salary_component_abbr from `tabSalary Component`
where ifnull(type, "")="" or ifnull(salary_component_abbr, "") = ""''', as_dict=1):
component = frappe.get_doc('Salary Component', s.name)
# guess
guess = frappe.db.sql('''select
parentfield from `tabSalary Detail`
where salary_component=%s limit 1''', s[0])
if not s.type:
guess = frappe.db.sql('''select
parentfield from `tabSalary Detail`
where salary_component=%s limit 1''', s.name)
if guess:
compontent.type = 'Earning' if guess[0][0]=='earnings' else 'Deduction'
if guess:
component.type = 'Earning' if guess[0][0]=='earnings' else 'Deduction'
else:
compontent.type = 'Deduction'
compontent.save()
else:
component.type = 'Deduction'
if not s.salary_component_abbr:
abbr = ''.join([c[0] for c in component.salary_component.split()]).upper()
abbr_count = frappe.db.sql("""
select
count(name)
from
`tabSalary Component`
where
salary_component_abbr = %s or salary_component_abbr like %s
""", (abbr, abbr + "-%%"))
if abbr_count and abbr_count[0][0] > 0:
abbr = abbr + "-" + cstr(abbr_count[0][0])
component.salary_component_abbr = abbr
component.save()