diff --git a/accounts/doctype/account/account.txt b/accounts/doctype/account/account.txt index b29c61782f..bf48a24d0c 100644 --- a/accounts/doctype/account/account.txt +++ b/accounts/doctype/account/account.txt @@ -455,7 +455,8 @@ 'description': "Don't delete this field at any cost", 'doctype': 'DocField', 'fieldname': 'old_parent', - 'fieldtype': 'Data', + 'fieldtype': 'Link', + 'options': 'Account', 'hidden': 1, 'idx': 24, 'label': 'Old Parent', @@ -517,4 +518,4 @@ 'oldfieldtype': 'Small Text', 'permlevel': 1 } -] \ No newline at end of file +] diff --git a/accounts/search_criteria/budget_variance_report/budget_variance_report.py b/accounts/search_criteria/budget_variance_report/budget_variance_report.py index 2efca2833e..182f9e5356 100644 --- a/accounts/search_criteria/budget_variance_report/budget_variance_report.py +++ b/accounts/search_criteria/budget_variance_report/budget_variance_report.py @@ -51,7 +51,6 @@ for r in res: q1 = "select sum(t1.budget_allocated) from `tabBudget Detail` t1, `tab%s` t2, `tabAccount` t3 where " cond2 = " t3.is_pl_account = 'Yes' and t3.debit_or_credit = 'Debit' and t3.name = t1.account and t1.docstatus != 2 and " if ch: - qur = q1+cond2+cond1+" and t2.name = '%s'" ret_amt = sql(qur%(based_on,fiscal_year,based_on,r[0].strip())) @@ -170,4 +169,4 @@ for r in res: r.append(actual) # ================ Variance =================================================== r.append(r[idx] - r[idx + 1]) - count = count +1 \ No newline at end of file + count = count +1 diff --git a/hr/doctype/leave_application/leave_application.js b/hr/doctype/leave_application/leave_application.js index ba00a31a7c..9fc1e428a8 100755 --- a/hr/doctype/leave_application/leave_application.js +++ b/hr/doctype/leave_application/leave_application.js @@ -52,12 +52,12 @@ cur_frm.cscript.from_date = function(doc, dt, dn) { // to date // -------- cur_frm.cscript.to_date = function(doc, dt, dn) { - if(cint(doc.half_day) == 1 && doc.from_date && doc.from_date != doc.to_date){ + if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){ msgprint("To Date should be same as From Date for Half Day leave"); - return; + set_multiple(dt,dn,{to_date:doc.from_date}); } if(cint(doc.half_day) == 1){ - set_multiple(dt,dn,{to_date:doc.from_date}); + } calculate_total_days(doc, dt, dn); } diff --git a/hr/doctype/salary_slip/salary_slip.js b/hr/doctype/salary_slip/salary_slip.js index 8c76b1e7c9..8f953e61ca 100644 --- a/hr/doctype/salary_slip/salary_slip.js +++ b/hr/doctype/salary_slip/salary_slip.js @@ -29,7 +29,7 @@ cur_frm.cscript.month = cur_frm.cscript.employee = cur_frm.cscript.fiscal_year; // Calculate total if lwp exists // ------------------------------------------------------------------------ cur_frm.cscript.leave_without_pay = function(doc,dt,dn){ - doc.payment_days = cint(doc.total_days_in_month) - cint(doc.leave_without_pay); + doc.payment_days = flt(doc.total_days_in_month) - flt(doc.leave_without_pay); refresh_field('payment_days'); calculate_all(doc, dt, dn); } diff --git a/hr/doctype/salary_slip/salary_slip.py b/hr/doctype/salary_slip/salary_slip.py index 9c94885963..af55956149 100644 --- a/hr/doctype/salary_slip/salary_slip.py +++ b/hr/doctype/salary_slip/salary_slip.py @@ -18,210 +18,219 @@ convert_to_lists = webnotes.conn.convert_to_lists from utilities.transaction_base import TransactionBase class DocType(TransactionBase): - def __init__(self,doc,doclist=[]): - self.doc = doc - self.doclist = doclist - - - # autoname - #======================================================= - def autoname(self): - self.doc.name = make_autoname('Sal Slip/' +self.doc.employee + '/.#####') + def __init__(self,doc,doclist=[]): + self.doc = doc + self.doclist = doclist + + + # autoname + #======================================================= + def autoname(self): + self.doc.name = make_autoname('Sal Slip/' +self.doc.employee + '/.#####') - # Get employee details - #======================================================= - def get_emp_and_leave_details(self): - # Get payment days - if self.doc.fiscal_year and self.doc.month: - self.get_leave_details() + # Get employee details + #======================================================= + def get_emp_and_leave_details(self): + # Get payment days + if self.doc.fiscal_year and self.doc.month: + self.get_leave_details() - # check sal structure - if self.doc.employee: - struct = self.check_sal_struct() - if struct: - self.pull_sal_struct(struct) + # check sal structure + if self.doc.employee: + struct = self.check_sal_struct() + if struct: + self.pull_sal_struct(struct) - # Check sal structure - #======================================================= - def check_sal_struct(self): - struct = sql("select name from `tabSalary Structure` where employee ='%s' and is_active = 'Yes' "%self.doc.employee) - if not struct: - msgprint("Please create Salary Structure for employee '%s'"%self.doc.employee) - self.doc.employee = '' - return struct and struct[0][0] or '' + # Check sal structure + #======================================================= + def check_sal_struct(self): + struct = sql("select name from `tabSalary Structure` where employee ='%s' and is_active = 'Yes' "%self.doc.employee) + if not struct: + msgprint("Please create Salary Structure for employee '%s'"%self.doc.employee) + self.doc.employee = '' + return struct and struct[0][0] or '' - # Pull struct details - #======================================================= - def pull_sal_struct(self, struct): - self.doc.clear_table(self.doclist, 'earning_details') - self.doc.clear_table(self.doclist, 'deduction_details') + # Pull struct details + #======================================================= + def pull_sal_struct(self, struct): + self.doc.clear_table(self.doclist, 'earning_details') + self.doc.clear_table(self.doclist, 'deduction_details') - get_obj('DocType Mapper', 'Salary Structure-Salary Slip').dt_map('Salary Structure', 'Salary Slip', struct, self.doc, self.doclist, "[['Salary Structure', 'Salary Slip'],['Earning Detail', 'SS Earning Detail'],['Deduction Detail','SS Deduction Detail']]") + get_obj('DocType Mapper', 'Salary Structure-Salary Slip').dt_map('Salary Structure', 'Salary Slip', struct, self.doc, self.doclist, "[['Salary Structure', 'Salary Slip'],['Earning Detail', 'SS Earning Detail'],['Deduction Detail','SS Deduction Detail']]") - basic_info = sql("select bank_name, bank_ac_no, esic_card_no, pf_number from `tabEmployee` where name ='%s'" % self.doc.employee) - self.doc.bank_name = basic_info[0][0] - self.doc.bank_account_no = basic_info[0][1] - self.doc.esic_no = basic_info[0][2] - self.doc.pf_no = basic_info[0][3] + basic_info = sql("select bank_name, bank_ac_no, esic_card_no, pf_number from `tabEmployee` where name ='%s'" % self.doc.employee) + self.doc.bank_name = basic_info[0][0] + self.doc.bank_account_no = basic_info[0][1] + self.doc.esic_no = basic_info[0][2] + self.doc.pf_no = basic_info[0][3] - # Get leave details - #======================================================= - def get_leave_details(self): - m = self.get_month_details() - lwp = self.calculate_lwp(m) - self.doc.total_days_in_month = m[3] - self.doc.leave_without_pay = lwp - self.doc.payment_days = flt(m[3]) - flt(lwp) + # Get leave details + #======================================================= + def get_leave_details(self): + m = self.get_month_details() + lwp = self.calculate_lwp(m) + self.doc.total_days_in_month = m[3] + self.doc.leave_without_pay = lwp + self.doc.payment_days = flt(m[3]) - flt(lwp) - # Get month details - #======================================================= - def get_month_details(self): - ysd = sql("select year_start_date from `tabFiscal Year` where name ='%s'"%self.doc.fiscal_year)[0][0] - if ysd: - from dateutil.relativedelta import relativedelta - import calendar, datetime - mnt = int(self.doc.month) - diff_mnt = int(mnt)-int(ysd.month) - if diff_mnt<0: - diff_mnt = 12-int(ysd.month)+int(mnt) - msd = ysd + relativedelta(months=diff_mnt) # month start date - month_days = cint(calendar.monthrange(cint(msd.year) ,cint(self.doc.month))[1]) # days in month - med = datetime.date(msd.year, cint(self.doc.month), month_days) # month end date - return msd.year, msd, med, month_days + # Get month details + #======================================================= + def get_month_details(self): + ysd = sql("select year_start_date from `tabFiscal Year` where name ='%s'"%self.doc.fiscal_year)[0][0] + if ysd: + from dateutil.relativedelta import relativedelta + import calendar, datetime + mnt = int(self.doc.month) + diff_mnt = int(mnt)-int(ysd.month) + if diff_mnt<0: + diff_mnt = 12-int(ysd.month)+int(mnt) + msd = ysd + relativedelta(months=diff_mnt) # month start date + month_days = cint(calendar.monthrange(cint(msd.year) ,cint(self.doc.month))[1]) # days in month + med = datetime.date(msd.year, cint(self.doc.month), month_days) # month end date + return msd.year, msd, med, month_days - # Calculate LWP - #======================================================= - def calculate_lwp(self, m): - holidays = sql("select t1.holiday_date from `tabHoliday List Detail` t1, tabEmployee t2 where t1.parent = t2.holiday_list and t2.name = '%s' and t1.holiday_date between '%s' and '%s'" % (self.doc.employee, m[1], m[2])) - if not holidays: - holidays = sql("select t1.holiday_date from `tabHoliday List Detail` t1, `tabHoliday List` t2 where t1.parent = t2.name and ifnull(t2.is_default, 0) = 1 and t2.fiscal_year = '%s'" % self.doc.fiscal_year) - holidays = [cstr(i[0]) for i in holidays] - lwp = 0 - for d in range(m[3]): - dt = add_days(cstr(m[1]), d) - if dt not in holidays: - if sql("select t1.name from `tabLeave Application` t1, `tabLeave Type` t2 where t2.name = t1.leave_type and ifnull(t2.is_lwp, 0) = 1 and t1.docstatus = 1 and t1.employee = '%s' and '%s' between from_date and to_date"%(self.doc.employee, dt)): - lwp += 1 - return lwp - - # Check existing - #======================================================= - def check_existing(self): - ret_exist = sql("select name from `tabSalary Slip` where month = '%s' and fiscal_year = '%s' and docstatus != 2 and employee = '%s' and name !='%s'" % (self.doc.month,self.doc.fiscal_year,self.doc.employee,self.doc.name)) - if ret_exist: - msgprint("Salary Slip of employee '%s' already created for this month" % self.doc.employee) - self.doc.employee = '' - raise Exception + # Calculate LWP + #======================================================= + def calculate_lwp(self, m): + holidays = sql("select t1.holiday_date from `tabHoliday List Detail` t1, tabEmployee t2 where t1.parent = t2.holiday_list and t2.name = '%s' and t1.holiday_date between '%s' and '%s'" % (self.doc.employee, m[1], m[2])) + if not holidays: + holidays = sql("select t1.holiday_date from `tabHoliday List Detail` t1, `tabHoliday List` t2 where t1.parent = t2.name and ifnull(t2.is_default, 0) = 1 and t2.fiscal_year = '%s'" % self.doc.fiscal_year) + holidays = [cstr(i[0]) for i in holidays] + lwp = 0 + for d in range(m[3]): + dt = add_days(cstr(m[1]), d) + if dt not in holidays: + leave = sql(""" + select t1.name, t1.half_day + from `tabLeave Application` t1, `tabLeave Type` t2 + where t2.name = t1.leave_type + and ifnull(t2.is_lwp, 0) = 1 + and t1.docstatus = 1 + and t1.employee = '%s' + and '%s' between from_date and to_date + """%(self.doc.employee, dt)) + if leave: + lwp = cint(leave[0][1]) and lwp + 0.5 or lwp + 1 + return lwp + + # Check existing + #======================================================= + def check_existing(self): + ret_exist = sql("select name from `tabSalary Slip` where month = '%s' and fiscal_year = '%s' and docstatus != 2 and employee = '%s' and name !='%s'" % (self.doc.month,self.doc.fiscal_year,self.doc.employee,self.doc.name)) + if ret_exist: + msgprint("Salary Slip of employee '%s' already created for this month" % self.doc.employee) + self.doc.employee = '' + raise Exception - # Validate - #======================================================= - def validate(self): - self.check_existing() - dcc = TransactionBase().get_company_currency(self.doc.company) - self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) - - # ON SUBMIT - #======================================================= - def on_submit(self): - if(self.doc.email_check == 1): - self.send_mail_funct() + # Validate + #======================================================= + def validate(self): + self.check_existing() + dcc = TransactionBase().get_company_currency(self.doc.company) + self.doc.total_in_words = get_obj('Sales Common').get_total_in_words(dcc, self.doc.rounded_total) + + # ON SUBMIT + #======================================================= + def on_submit(self): + if(self.doc.email_check == 1): + self.send_mail_funct() - # Send mail - #======================================================= - def send_mail_funct(self): - emailid_ret=sql("select company_email from `tabEmployee` where name = '%s'"%self.doc.employee) - if emailid_ret: - receiver = cstr(emailid_ret[0][0]) - subj = 'Salary Slip ' + cstr(self.doc.month) +' '+cstr(self.doc.year) - earn_ret=sql("select e_type,e_amount from `tabSS Earning Detail` where parent = '%s'"%self.doc.name) - ded_ret=sql("select d_type,d_amount from `tabSS Deduction Detail` where parent = '%s'"%self.doc.name) - - earn_table = '' - ded_table = '' - if earn_ret: - - earn_table += "" - - for e in earn_ret: - if not e[1]: - earn_table +=''%(cstr(e[0])) - else: - earn_table +=''%(cstr(e[0]),cstr(e[1])) - earn_table += '
%s0.00
%s%s
' - - if ded_ret: - - ded_table += "" - - for d in ded_ret: - if not d[1]: - ded_table +=''%(cstr(d[0])) - else: - ded_table +=''%(cstr(d[0]),cstr(d[1])) - ded_table += '
%s0.00
%s%s
' - - letter_head = sql("select value from `tabSingles` where field = 'letter_head' and doctype = 'Control Panel'") - - if not letter_head: - letter_head = '' - - msg = ''' %s
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - -
- - - - - - - - -

Salary Slip

Employee Code : %sEmployee Name : %s
Month : %sYear : %sFiscal Year : %s
Department : %sBranch : %sDesignation : %s
Grade : %sBank Account No. : %sBank Name : %s
PF No. : %sESIC No. : %sArrear Amount : %s
Total days in month : %sLeave Without Pay : %sPayment days : %s
EarningDeduction
%s%s
Gross Pay : %sTotal Deduction : %s
Net Pay : %sNet Pay (in words) : %s
'''%(cstr(letter_head[0][0]),cstr(self.doc.employee),self.doc.employee_name,cstr(self.doc.month),cstr(self.doc.year),cstr(self.doc.fiscal_year),self.doc.department,self.doc.branch,self.doc.designation,self.doc.grade,cstr(self.doc.bank_account_no),self.doc.bank_name,cstr(self.doc.pf_no),cstr(self.doc.esic_no),cstr(self.doc.arrear_amount),cstr(self.doc.total_days_in_month),cstr(self.doc.leave_without_pay),cstr(self.doc.payment_days),earn_table,ded_table,cstr(self.doc.gross_pay),cstr(self.doc.total_deduction),cstr(self.doc.net_pay),cstr(self.doc.net_pay_in_words)) - sendmail([receiver], sender='automail@webnotestech.com', subject=subj, parts=[['text/plain', msg]]) - else: - msgprint("Company Email ID not found.") + # Send mail + #======================================================= + def send_mail_funct(self): + emailid_ret=sql("select company_email from `tabEmployee` where name = '%s'"%self.doc.employee) + if emailid_ret: + receiver = cstr(emailid_ret[0][0]) + subj = 'Salary Slip ' + cstr(self.doc.month) +' '+cstr(self.doc.year) + earn_ret=sql("select e_type,e_amount from `tabSS Earning Detail` where parent = '%s'"%self.doc.name) + ded_ret=sql("select d_type,d_amount from `tabSS Deduction Detail` where parent = '%s'"%self.doc.name) + + earn_table = '' + ded_table = '' + if earn_ret: + + earn_table += "" + + for e in earn_ret: + if not e[1]: + earn_table +=''%(cstr(e[0])) + else: + earn_table +=''%(cstr(e[0]),cstr(e[1])) + earn_table += '
%s0.00
%s%s
' + + if ded_ret: + + ded_table += "" + + for d in ded_ret: + if not d[1]: + ded_table +=''%(cstr(d[0])) + else: + ded_table +=''%(cstr(d[0]),cstr(d[1])) + ded_table += '
%s0.00
%s%s
' + + letter_head = sql("select value from `tabSingles` where field = 'letter_head' and doctype = 'Control Panel'") + + if not letter_head: + letter_head = '' + + msg = ''' %s
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + + + + + + + +
+ + + + + + + + +

Salary Slip

Employee Code : %sEmployee Name : %s
Month : %sYear : %sFiscal Year : %s
Department : %sBranch : %sDesignation : %s
Grade : %sBank Account No. : %sBank Name : %s
PF No. : %sESIC No. : %sArrear Amount : %s
Total days in month : %sLeave Without Pay : %sPayment days : %s
EarningDeduction
%s%s
Gross Pay : %sTotal Deduction : %s
Net Pay : %sNet Pay (in words) : %s
'''%(cstr(letter_head[0][0]),cstr(self.doc.employee),self.doc.employee_name,cstr(self.doc.month),cstr(self.doc.year),cstr(self.doc.fiscal_year),self.doc.department,self.doc.branch,self.doc.designation,self.doc.grade,cstr(self.doc.bank_account_no),self.doc.bank_name,cstr(self.doc.pf_no),cstr(self.doc.esic_no),cstr(self.doc.arrear_amount),cstr(self.doc.total_days_in_month),cstr(self.doc.leave_without_pay),cstr(self.doc.payment_days),earn_table,ded_table,cstr(self.doc.gross_pay),cstr(self.doc.total_deduction),cstr(self.doc.net_pay),cstr(self.doc.net_pay_in_words)) + sendmail([receiver], sender='automail@webnotestech.com', subject=subj, parts=[['text/plain', msg]]) + else: + msgprint("Company Email ID not found.") diff --git a/patches/patch.py b/patches/patch.py index e84200fe35..abd6ed6ffd 100644 --- a/patches/patch.py +++ b/patches/patch.py @@ -1,7 +1,7 @@ # REMEMBER to update this # ======================== -last_patch = 334 +last_patch = 335 #------------------------------------------- @@ -1352,3 +1352,6 @@ def execute(patch_no): p.add_permission('Print Format', 'System Manager', 0, read = 1, write=1, create=1) elif patch_no == 334: reload_doc('knowledge_base', 'doctype', 'answer') + elif patch_no == 335: + for dt in ['Account', 'Cost Center', 'Territory', 'Item Group', 'Customer Group']: + sql("update `tabDocField` set fieldtype = 'Link', options = %s where fieldname = 'old_parent' and parent = %s", (dt, dt))