diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py index 0d0c23cadc..ba0699599b 100644 --- a/erpnext/hr/doctype/attendance/attendance.py +++ b/erpnext/hr/doctype/attendance/attendance.py @@ -59,48 +59,15 @@ class DocType: msgprint("Employee's attendance already marked.") raise Exception - #validation - leave_type is mandatory for status absent/ half day else not required to entered. - def validate_status(self): - if self.doc.status == 'Present' and self.doc.leave_type: - msgprint("You can not enter leave type for attendance status 'Present'") - raise Exception - - elif (self.doc.status == 'Absent' or self.doc.status == 'Half Day') and not self.doc.leave_type: - msgprint("Please enter leave type for attendance status 'Absent'") - raise Exception #check for already record present in leave transaction for same date def check_leave_record(self): if self.doc.status == 'Present': - chk = sql("select name from `tabLeave Transaction` where employee=%s and (from_date <= %s and to_date >= %s) and status = 'Submitted' and leave_transaction_type = 'Deduction' and docstatus!=2", (self.doc.employee, self.doc.att_date, self.doc.att_date)) + chk = sql("select name from `tabLeave Application` where employee=%s and (from_date <= %s and to_date >= %s) and docstatus!=2", (self.doc.employee, self.doc.att_date, self.doc.att_date)) if chk: msgprint("Leave Application created for employee "+self.doc.employee+" whom you are trying to mark as 'Present' ") raise Exception - #For absent/ half day record - check for leave balances of the employees - def validate_leave_type(self): - if not self.doc.status =='Present' and self.doc.leave_type not in ('Leave Without Pay','Compensatory Off'): - #check for leave allocated to employee from leave transaction - ret = sql("select name from `tabLeave Transaction` where employee = '%s' and leave_type = '%s' and leave_transaction_type = 'Allocation' and fiscal_year = '%s'"%(self.doc.employee,self.doc.leave_type,self.doc.fiscal_year)) - - #if leave allocation is present then calculate leave balance i.e. sum(allocation) - sum(deduction) - if ret: - q1 = 'SUM(CASE WHEN leave_transaction_type = "Allocation" THEN total_leave ELSE 0 END)-SUM(CASE WHEN leave_transaction_type = "Deduction" THEN total_leave ELSE 0 END)' - q2 = "select %s from `tabLeave Transaction` where employee = '%s' and leave_type = '%s' and fiscal_year = '%s' and docstatus = 1" - - res = sql(q2%(q1,self.doc.employee,self.doc.leave_type,self.doc.fiscal_year)) - - if res: - if self.doc.status == 'Absent' and flt(res[0][0]) < 1: - msgprint("%s balances are insufficient to cover a day absence, please select other leave type."%self.doc.leave_type) - raise Exception - if self.doc.status == 'Half Day' and flt(res[0][0]) < 0.5: - msgprint("%s balances are insufficient to cover a half day absence, please select other leave type."%self.doc.leave_type) - raise Exception - - else: - msgprint("Leave Allocation for employee %s not done.\n You can allocate leaves from HR -> Leave Transaction OR HR -> Leave Control Panel."%self.doc.employee) - raise Exception def validate_fiscal_year(self): fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"% self.doc.fiscal_year) @@ -129,7 +96,6 @@ class DocType: def validate(self): self.validate_fiscal_year() self.validate_att_date() - #self.validate_leave_type() self.validate_duplicate_record() #self.validate_status() self.check_leave_record() diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index cd8b115b5b..937ada7ae1 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -8,11 +8,11 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . # Please edit this list and import only required elements import webnotes @@ -34,126 +34,126 @@ convert_to_lists = webnotes.conn.convert_to_lists class DocType: - def __init__(self, doc, doclist=[]): - self.doc = doc - self.doclist = doclist + def __init__(self, doc, doclist=[]): + self.doc = doc + self.doclist = doclist - def get_employee_name(self): - emp_dtl = sql("select employee_name,company_email from `tabEmployee` where name=%s", self.doc.employee) - emp_nm = emp_dtl and emp_dtl[0][0] or '' - self.doc.employee_name = emp_nm - self.doc.email_id = emp_dtl and emp_dtl[0][1] or '' + def get_employee_name(self): + emp_dtl = sql("select employee_name,company_email from `tabEmployee` where name=%s", self.doc.employee) + emp_nm = emp_dtl and emp_dtl[0][0] or '' + self.doc.employee_name = emp_nm + self.doc.email_id = emp_dtl and emp_dtl[0][1] or '' - return cstr(emp_nm) - - def get_approver_lst(self): - approver_lst =[] - approver_lst1 = get_obj('Authorization Control').get_approver_name(self.doc.doctype,0,self) - if approver_lst1: - approver_lst=approver_lst1 - else: - approver_lst = [x[0] for x in sql("select distinct name from `tabProfile` where enabled=1 and name!='Administrator' and name!='Guest' and docstatus!=2")] - return approver_lst + return cstr(emp_nm) + + def get_approver_lst(self): + approver_lst =[] + approver_lst1 = get_obj('Authorization Control').get_approver_name(self.doc.doctype,0,self) + if approver_lst1: + approver_lst=approver_lst1 + else: + approver_lst = [x[0] for x in sql("select distinct name from `tabProfile` where enabled=1 and name!='Administrator' and name!='Guest' and docstatus!=2")] + return approver_lst - def set_approver(self): - ret={} - approver_lst =[] - emp_nm = self.get_employee_name() - approver_lst = self.get_approver_lst() - ret = {'app_lst':"\n" + "\n".join(approver_lst), 'emp_nm':cstr(emp_nm)} - return ret + def set_approver(self): + ret={} + approver_lst =[] + emp_nm = self.get_employee_name() + approver_lst = self.get_approver_lst() + ret = {'app_lst':"\n" + "\n".join(approver_lst), 'emp_nm':cstr(emp_nm)} + return ret - def update_voucher(self): - sql("delete from `tabExpense Claim Detail` where parent = '%s'"%self.doc.name) - for d in getlist(self.doclist, 'expense_voucher_details'): - if not d.expense_type or not d.claim_amount: - msgprint("Please remove the extra blank row added") - raise Exception - d.save(1) - if self.doc.total_sanctioned_amount: - set(self.doc,'total_sanctioned_amount',self.doc.total_sanctioned_amount) - if self.doc.remark: - set(self.doc, 'remark', self.doc.remark) - - def approve_voucher(self): - for d in getlist(self.doclist, 'expense_voucher_details'): - if not d.sanctioned_amount: - msgprint("Please add 'Sanctioned Amount' for all expenses") - return cstr('Incomplete') - - if not self.doc.total_sanctioned_amount: - msgprint("Please calculate total sanctioned amount using button 'Calculate Total Amount'") - return cstr('No Amount') - self.update_voucher() - - set(self.doc, 'approval_status', 'Approved') - # on approval notification - #get_obj('Notification Control').notify_contact('Expense Claim Approved', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name) + def update_voucher(self): + sql("delete from `tabExpense Claim Detail` where parent = '%s'"%self.doc.name) + for d in getlist(self.doclist, 'expense_voucher_details'): + if not d.expense_type or not d.claim_amount: + msgprint("Please remove the extra blank row added") + raise Exception + d.save(1) + if self.doc.total_sanctioned_amount: + set(self.doc,'total_sanctioned_amount',self.doc.total_sanctioned_amount) + if self.doc.remark: + set(self.doc, 'remark', self.doc.remark) + + def approve_voucher(self): + for d in getlist(self.doclist, 'expense_voucher_details'): + if not d.sanctioned_amount: + msgprint("Please add 'Sanctioned Amount' for all expenses") + return cstr('Incomplete') + + if not self.doc.total_sanctioned_amount: + msgprint("Please calculate total sanctioned amount using button 'Calculate Total Amount'") + return cstr('No Amount') + self.update_voucher() + + set(self.doc, 'approval_status', 'Approved') + # on approval notification + #get_obj('Notification Control').notify_contact('Expense Claim Approved', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name) - return cstr('Approved') - - def reject_voucher(self): - - if self.doc.remark: - set(self.doc, 'remark', self.doc.remark) - set(self.doc, 'approval_status', 'Rejected') + return cstr('Approved') + + def reject_voucher(self): + + if self.doc.remark: + set(self.doc, 'remark', self.doc.remark) + set(self.doc, 'approval_status', 'Rejected') - # on approval notification - #get_obj('Notification Control').notify_contact('Expense Claim Rejected', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name) + # on approval notification + #get_obj('Notification Control').notify_contact('Expense Claim Rejected', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name) - return cstr('Rejected') - - def validate_curr_exp(self): - for d in getlist(self.doclist, 'expense_voucher_details'): - if flt(d.sanctioned_amount) > 0: - if self.doc.approval_status == 'Draft': - msgprint("Sanctioned amount can be added by Approver person only for submitted Expense Claim") - raise Exception - elif self.doc.approval_status == 'Submitted' and session['user'] != self.doc.exp_approver: - msgprint("Sanctioned amount can be added only by expense voucher Approver") - raise Exception - - def validate_fiscal_year(self): - fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"%self.doc.fiscal_year) - ysd=fy and fy[0][0] or "" - yed=add_days(str(ysd),365) - if str(self.doc.posting_date) < str(ysd) or str(self.doc.posting_date) > str(yed): - msgprint("Posting Date is not within the Fiscal Year selected") - raise Exception - - def validate(self): - self.validate_curr_exp() - self.validate_fiscal_year() - - def on_update(self): - set(self.doc, 'approval_status', 'Draft') - - def validate_exp_details(self): - if not getlist(self.doclist, 'expense_voucher_details'): - msgprint("Please add expense voucher details") - raise Exception - - if not self.doc.total_claimed_amount: - msgprint("Please calculate Total Claimed Amount") - raise Exception - - if not self.doc.exp_approver: - msgprint("Please select Expense Claim approver") - raise Exception - - def validate_approver(self): - app_lst = self.get_approver_lst() - if self.doc.exp_approver and self.doc.exp_approver not in app_lst: - msgprint("Approver "+self.doc.exp_approver+" is not authorized to approve this expense voucher. Please select another approver") - valid_app = 'No' - else: - valid_app = 'Yes' - ret = {'app_lst':("\n" + "\n".join(app_lst)), 'valid_approver':valid_app} - return ret - - def on_submit(self): - self.validate_exp_details() - set(self.doc, 'approval_status', 'Submitted') - - def on_cancel(self): - set(self.doc, 'approval_status', 'Cancelled') + return cstr('Rejected') + + def validate_curr_exp(self): + for d in getlist(self.doclist, 'expense_voucher_details'): + if flt(d.sanctioned_amount) > 0: + if self.doc.approval_status == 'Draft': + msgprint("Sanctioned amount can be added by Approver person only for submitted Expense Claim") + raise Exception + elif self.doc.approval_status == 'Submitted' and session['user'] != self.doc.exp_approver: + msgprint("Sanctioned amount can be added only by expense voucher Approver") + raise Exception + + def validate_fiscal_year(self): + fy=sql("select year_start_date from `tabFiscal Year` where name='%s'"%self.doc.fiscal_year) + ysd=fy and fy[0][0] or "" + yed=add_days(str(ysd),365) + if str(self.doc.posting_date) < str(ysd) or str(self.doc.posting_date) > str(yed): + msgprint("Posting Date is not within the Fiscal Year selected") + raise Exception + + def validate(self): + self.validate_curr_exp() + self.validate_fiscal_year() + + def on_update(self): + set(self.doc, 'approval_status', 'Draft') + + def validate_exp_details(self): + if not getlist(self.doclist, 'expense_voucher_details'): + msgprint("Please add expense voucher details") + raise Exception + + if not self.doc.total_claimed_amount: + msgprint("Please calculate Total Claimed Amount") + raise Exception + + if not self.doc.exp_approver: + msgprint("Please select Expense Claim approver") + raise Exception + + def validate_approver(self): + app_lst = self.get_approver_lst() + if self.doc.exp_approver and self.doc.exp_approver not in app_lst: + msgprint("Approver "+self.doc.exp_approver+" is not authorized to approve this expense voucher. Please select another approver") + valid_app = 'No' + else: + valid_app = 'Yes' + ret = {'app_lst':("\n" + "\n".join(app_lst)), 'valid_approver':valid_app} + return ret + + def on_submit(self): + self.validate_exp_details() + set(self.doc, 'approval_status', 'Submitted') + + def on_cancel(self): + set(self.doc, 'approval_status', 'Cancelled') diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.js b/erpnext/hr/doctype/salary_structure/salary_structure.js index eaba16b452..2cfab81281 100644 --- a/erpnext/hr/doctype/salary_structure/salary_structure.js +++ b/erpnext/hr/doctype/salary_structure/salary_structure.js @@ -29,7 +29,6 @@ cur_frm.cscript.onload = function(doc, dt, dn){ //======================================================================= cur_frm.cscript.refresh = function(doc, dt, dn){ if((!doc.__islocal) && (doc.is_active == 'Yes')){ - cur_frm.add_custom_button('Make IT Checklist', cur_frm.cscript['Make IT Checklist']); cur_frm.add_custom_button('Make Salary Slip', cur_frm.cscript['Make Salary Slip']); get_field(doc.doctype, 'employee', doc.name).permlevel = 1; @@ -37,16 +36,6 @@ cur_frm.cscript.refresh = function(doc, dt, dn){ } } -// Make IT checklist -//======================================================================= -cur_frm.cscript['Make IT Checklist']=function(){ - var itc = LocalDB.create('IT Checklist'); - itc = locals['IT Checklist'][itc]; - itc.employee = cur_frm.doc.employee; - itc.fiscal_year = sys_defaults.fiscal_year; - itc.is_cheklist_active='Yes'; - loaddoc('IT Checklist', itc.name); -} // Make Salry Slip //======================================================================= diff --git a/erpnext/patches/jan_mar_2012/rename_dt.py b/erpnext/patches/jan_mar_2012/rename_dt.py index e53daf4dd1..295d4e5685 100644 --- a/erpnext/patches/jan_mar_2012/rename_dt.py +++ b/erpnext/patches/jan_mar_2012/rename_dt.py @@ -143,7 +143,7 @@ def delete_search_criteria(): def change_report_module(): reports = {'itemwise_receipt_details': 'Stock'} for k in reports: - sql("update `tabSearch Criteria` set module = %s where name = %s", (reports[k], k)) + webnotes.conn.sql("update `tabSearch Criteria` set module = %s where name = %s", (reports[k], k)) def rename_in_db(ren_data, data_type, is_doctype): for d in ren_data: