diff --git a/hr/doctype/salary_slip/salary_slip.py b/hr/doctype/salary_slip/salary_slip.py index 2b1d80c193..09bd602da1 100644 --- a/hr/doctype/salary_slip/salary_slip.py +++ b/hr/doctype/salary_slip/salary_slip.py @@ -33,16 +33,12 @@ class DocType(TransactionBase): self.doc = doc self.doclist = doclist - def autoname(self): self.doc.name = make_autoname('Sal Slip/' +self.doc.employee + '/.#####') - def get_emp_and_leave_details(self): if self.doc.employee: self.get_leave_details() - - # check sal structure struct = self.check_sal_struct() if struct: self.pull_sal_struct(struct) @@ -91,16 +87,18 @@ class DocType(TransactionBase): where name = %s", self.doc.employee, as_dict=1)[0] if emp['relieving_date']: - if getdate(emp['relieving_date']) > m['month_start_date'] and getdate(emp['relieving_date']) < m['month_end_date']: - payment_days = getdate(emp['relieving_date']).day + if getdate(emp['relieving_date']) > m['month_start_date'] and \ + getdate(emp['relieving_date']) < m['month_end_date']: + payment_days = getdate(emp['relieving_date']).day elif getdate(emp['relieving_date']) < m['month_start_date']: webnotes.msgprint(_("Relieving Date of employee is ") + cstr(emp['relieving_date'] + _(". Please set status of the employee as 'Left'")), raise_exception=1) if emp['date_of_joining']: - if getdate(emp['date_of_joining']) > m['month_start_date'] and getdate(emp['date_of_joining']) < m['month_end_date']: - payment_days = payment_days - getdate(emp['date_of_joining']).day + 1 + if getdate(emp['date_of_joining']) > m['month_start_date'] and \ + getdate(emp['date_of_joining']) < m['month_end_date']: + payment_days = payment_days - getdate(emp['date_of_joining']).day + 1 elif getdate(emp['date_of_joining']) > m['month_end_date']: payment_days = 0 @@ -110,9 +108,16 @@ class DocType(TransactionBase): def calculate_lwp(self, m): - holidays = sql("select t1.holiday_date from `tabHoliday` 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['month_start_date'], m['month_end_date'])) + holidays = sql("""select t1.holiday_date + from `tabHoliday` 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['month_start_date'], m['month_end_date'])) if not holidays: - holidays = sql("select t1.holiday_date from `tabHoliday` 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 = sql("""select t1.holiday_date + from `tabHoliday` 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['month_days']): @@ -124,20 +129,22 @@ class DocType(TransactionBase): 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)) + 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 - 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)) + 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 + msgprint("Salary Slip of employee '%s' already created for this month" + % self.doc.employee, raise_exception=1) def validate(self): @@ -146,41 +153,32 @@ class DocType(TransactionBase): company_currency = get_company_currency(self.doc.company) self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency) - def calculate_earning_total(self): - """ - Calculates total earnings considering lwp - """ self.doc.gross_pay = flt(self.doc.arrear_amount) + flt(self.doc.leave_encashment_amount) for d in getlist(self.doclist, 'earning_details'): if cint(d.e_depends_on_lwp) == 1: - d.e_modified_amount = round(flt(d.e_amount)*flt(self.doc.payment_days)/cint(self.doc.total_days_in_month), 2) + d.e_modified_amount = round(flt(d.e_amount) * flt(self.doc.payment_days) + / cint(self.doc.total_days_in_month), 2) elif not self.doc.payment_days: d.e_modified_amount = 0 self.doc.gross_pay += flt(d.e_modified_amount) def calculate_ded_total(self): - """ - Calculates total deduction considering lwp - """ self.doc.total_deduction = 0 for d in getlist(self.doclist, 'deduction_details'): if cint(d.d_depends_on_lwp) == 1: - d.d_modified_amount = round(flt(d.d_amount)*flt(self.doc.payment_days)/cint(self.doc.total_days_in_month), 2) + d.d_modified_amount = round(flt(d.d_amount) * flt(self.doc.payment_days) + / cint(self.doc.total_days_in_month), 2) elif not self.doc.payment_days: d.d_modified_amount = 0 self.doc.total_deduction += flt(d.d_modified_amount) def calculate_net_pay(self): - """ - Calculate net payment - """ self.calculate_earning_total() self.calculate_ded_total() self.doc.net_pay = flt(self.doc.gross_pay) - flt(self.doc.total_deduction) - self.doc.rounded_total = round(self.doc.net_pay) - + self.doc.rounded_total = round(self.doc.net_pay) def on_submit(self): if(self.doc.email_check == 1): @@ -189,12 +187,13 @@ class DocType(TransactionBase): def send_mail_funct(self): from webnotes.utils.email_lib import sendmail - emailid_ret=sql("select company_email from `tabEmployee` where name = '%s'"%self.doc.employee) - if emailid_ret: - receiver = cstr(emailid_ret[0][0]) + receiver = webnotes.conn.get_value("Employee", self.doc.employee, "company_email") + if receiver: subj = 'Salary Slip - ' + cstr(self.doc.month) +'/'+cstr(self.doc.fiscal_year) - earn_ret=sql("select e_type,e_modified_amount from `tabSalary Slip Earning` where parent = '%s'"%self.doc.name) - ded_ret=sql("select d_type,d_modified_amount from `tabSalary Slip Deduction` where parent = '%s'"%self.doc.name) + earn_ret=sql("""select e_type, e_modified_amount from `tabSalary Slip Earning` + where parent = %s""", self.doc.name) + ded_ret=sql("""select d_type, d_modified_amount from `tabSalary Slip Deduction` + where parent = %s""", self.doc.name) earn_table = '' ded_table = '' @@ -203,9 +202,10 @@ class DocType(TransactionBase): for e in earn_ret: if not e[1]: - earn_table +='%s0.00'%(cstr(e[0])) + earn_table += '%s0.00' % cstr(e[0]) else: - earn_table +='%s%s'%(cstr(e[0]),cstr(e[1])) + earn_table += '%s%s' \ + % (cstr(e[0]), cstr(e[1])) earn_table += '' if ded_ret: @@ -214,15 +214,14 @@ class DocType(TransactionBase): for d in ded_ret: if not d[1]: - ded_table +='%s0.00'%(cstr(d[0])) + ded_table +='%s0.00' % cstr(d[0]) else: - ded_table +='%s%s'%(cstr(d[0]),cstr(d[1])) + ded_table +='%s%s' \ + % (cstr(d[0]), cstr(d[1])) ded_table += '' - letter_head = sql("select value from `tabSingles` where field = 'letter_head' and doctype = 'Control Panel'") - - if not letter_head: - letter_head = '' + letter_head = webnotes.conn.get_value("Letter Head", {"is_default": 1, "disabled": 0}, + "content") msg = '''
%s
@@ -258,8 +257,10 @@ class DocType(TransactionBase):
- - + + @@ -268,17 +269,28 @@ class DocType(TransactionBase):
EarningsDeductions + Earnings + Deductions
%s
- - + + + + - Net Pay : + Net Pay : + - + + -
Gross Pay : %sTotal Deduction : %sGross Pay : %sTotal Deduction : %s
%s%s
Net Pay(in words) : %sNet Pay(in words) : %s
'''%(cstr(letter_head[0][0]),cstr(self.doc.employee), cstr(self.doc.employee_name), cstr(self.doc.month), cstr(self.doc.fiscal_year), cstr(self.doc.department), cstr(self.doc.branch), cstr(self.doc.designation), cstr(self.doc.grade), cstr(self.doc.bank_account_no), cstr(self.doc.bank_name), cstr(self.doc.arrear_amount), cstr(self.doc.payment_days), earn_table, ded_table, cstr(flt(self.doc.gross_pay)), cstr(flt(self.doc.total_deduction)), cstr(flt(self.doc.net_pay)), cstr(self.doc.total_in_words)) + ''' % (cstr(letter_head), cstr(self.doc.employee), + cstr(self.doc.employee_name), cstr(self.doc.month), cstr(self.doc.fiscal_year), + cstr(self.doc.department), cstr(self.doc.branch), cstr(self.doc.designation), + cstr(self.doc.grade), cstr(self.doc.bank_account_no), cstr(self.doc.bank_name), + cstr(self.doc.arrear_amount), cstr(self.doc.payment_days), earn_table, ded_table, + cstr(flt(self.doc.gross_pay)), cstr(flt(self.doc.total_deduction)), + cstr(flt(self.doc.net_pay)), cstr(self.doc.total_in_words)) + sendmail([receiver], subject=subj, msg = msg) else: msgprint("Company Email ID not found, hence mail not sent")