def get_appr_user_role(self, det, doctype_name, total, based_on, condition, item, company): amt_list, appr_users, appr_roles = [], [], [] users, roles = '','' if det: for x in det: amt_list.append(flt(x[0])) max_amount = max(amt_list) app_dtl = sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and company = %s %s" % ('%s', '%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on, company)) if not app_dtl: app_dtl = sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and ifnull(company,'') = '' %s" % ('%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on)) for d in app_dtl: if(d[0]): appr_users.append(d[0]) if(d[1]): appr_roles.append(d[1]) if not has_common(appr_roles, webnotes.user.get_roles()) and not has_common(appr_users, [session['user']]): msg, add_msg = '','' if max_amount: dcc = get_company_currency(self.doc.company) if based_on == 'Grand Total': msg = "since Grand Total exceeds %s. %s" % (dcc, flt(max_amount)) elif based_on == 'Itemwise Discount': msg = "since Discount exceeds %s for Item Code : %s" % (cstr(max_amount)+'%', item) elif based_on == 'Average Discount' or based_on == 'Customerwise Discount': msg = "since Discount exceeds %s" % (cstr(max_amount)+'%') if appr_users: add_msg = "Users : "+cstr(appr_users) if appr_roles: add_msg = "Roles : "+cstr(appr_roles) if appr_users and appr_roles: add_msg = "Users : "+cstr(appr_users)+" or "+"Roles : "+cstr(appr_roles) msgprint("You are not authorize to submit this %s %s. Please send for approval to %s" % (doctype_name, msg, add_msg)) raise Exception
def get_comp(self): ret = {} type = [] comp = [] # ------ get period ----------- ret['period'] = ['Annual','Half Yearly','Quarterly','Monthly'] # ---- get companies --------- from accounts.page.accounts_browser.accounts_browser import get_companies ret['company'] = get_companies() #--- to get fiscal year and start_date of that fiscal year ----- res = sql("select name, year_start_date from `tabFiscal Year`") ret['fiscal_year'] = [r[0] for r in res] ret['start_dates'] = {} for r in res: ret['start_dates'][r[0]] = str(r[1]) #--- from month and to month (for MIS - Comparison Report) ------- month_list = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] fiscal_start_month = sql("select MONTH(year_start_date) from `tabFiscal Year` where name = %s",(get_defaults()['fiscal_year'])) fiscal_start_month = fiscal_start_month and fiscal_start_month[0][0] or 1 mon = [''] for i in range(fiscal_start_month,13): mon.append(month_list[i-1]) for i in range(0,fiscal_start_month-1): mon.append(month_list[i]) ret['month'] = mon # ------------------------ get MIS Type on basis of roles of session user ------------------------------------------ if has_common(self.roles, ['Sales Manager']): type.append('Sales') if has_common(self.roles, ['Purchase Manager']): type.append('Purchase') ret['type'] = type return ret
def get_comp(self): ret = {} type = [] comp = [] # ------ get period ----------- ret['period'] = ['Annual','Half Yearly','Quarterly','Monthly'] # ---- get companies --------- from accounts.page.accounts_browser.accounts_browser import get_companies ret['company'] = get_companies() #--- to get fiscal year and start_date of that fiscal year ----- res = webnotes.conn.sql("select name, year_start_date from `tabFiscal Year`") ret['fiscal_year'] = [r[0] for r in res] ret['start_dates'] = {} for r in res: ret['start_dates'][r[0]] = str(r[1]) #--- from month and to month (for MIS - Comparison Report) ------- month_list = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] fiscal_start_month = webnotes.conn.sql("select MONTH(year_start_date) from `tabFiscal Year` where name = %s",(webnotes.defaults.get_global_default("fiscal_year"))) fiscal_start_month = fiscal_start_month and fiscal_start_month[0][0] or 1 mon = [''] for i in range(fiscal_start_month,13): mon.append(month_list[i-1]) for i in range(0,fiscal_start_month-1): mon.append(month_list[i]) ret['month'] = mon # ------------------------ get MIS Type on basis of roles of session user ------------------------------------------ self.roles = webnotes.user.get_roles() if has_common(self.roles, ['Sales Manager']): type.append('Sales') if has_common(self.roles, ['Purchase Manager']): type.append('Purchase') ret['type'] = type return ret
def validate_rule(self): if self.doc.transaction != 'Appraisal': if not self.doc.approving_role and not self.doc.approving_user: msgprint("Please enter Approving Role or Approving User", raise_exception=1) elif self.doc.system_user and self.doc.system_user == self.doc.approving_user: msgprint("Approving User cannot be same as user the rule is Applicable To (User)", raise_exception=1) elif self.doc.system_role and self.doc.system_role == self.doc.approving_role: msgprint("Approving Role cannot be same as user the rule is \ Applicable To (Role).", raise_exception=1) elif self.doc.system_user and self.doc.approving_role and \ has_common([self.doc.approving_role], [x[0] for x in \ sql("select role from `tabUserRole` where parent = '%s'" % \ (self.doc.system_user))]): msgprint("System User : %s is assigned role : %s. So rule does not make sense" % (self.doc.system_user,self.doc.approving_role), raise_exception=1) elif self.doc.transaction in ['Purchase Order', 'Purchase Receipt', \ 'Purchase Invoice', 'Stock Entry'] and self.doc.based_on \ in ['Average Discount', 'Customerwise Discount', 'Itemwise Discount']: msgprint("You cannot set authorization on basis of Discount for %s" % self.doc.transaction, raise_exception=1) elif self.doc.based_on == 'Average Discount' and flt(self.doc.value) > 100.00: msgprint("Discount cannot given for more than 100%", raise_exception=1) elif self.doc.based_on == 'Customerwise Discount' and not self.doc.master_name: msgprint("Please enter Customer Name for 'Customerwise Discount'", raise_exception=1) else: if self.doc.transaction == 'Appraisal' and self.doc.based_on != 'Not Applicable': msgprint("Based on should be 'Not Applicable' while setting authorization rule\ for 'Appraisal'", raise_exception=1)
def validate_rule(self): if not self.doc.transaction == 'Expense Voucher' and not self.doc.transaction == 'Appraisal': if not self.doc.approving_role and not self.doc.approving_user: msgprint("Please enter Approving Role or Approving User") raise Exception elif self.doc.system_user and self.doc.system_user == self.doc.approving_user: msgprint("Approving User cannot be same as user the rule is Applicable To (User).") raise Exception elif self.doc.system_role and self.doc.system_role == self.doc.approving_role: msgprint("Approving Role cannot be same as user the rule is Applicable To (Role).") raise Exception elif self.doc.system_user and self.doc.approving_role and has_common([self.doc.approving_role],[x[0] for x in sql("select role from `tabUserRole` where parent = '%s'" % (self.doc.system_user))]): msgprint("System User : %s is assigned role : %s. So rule does not make sense." % (self.doc.system_user,self.doc.approving_role)) raise Exception elif (self.doc.transaction == 'Purchase Order' or self.doc.transaction == 'Purchase Receipt' or self.doc.transaction == 'Purchase Invoice' or self.doc.transaction == 'Stock Entry') and (self.doc.based_on == 'Average Discount' or self.doc.based_on == 'Customerwise Discount' or self.doc.based_on == 'Itemwise Discount'): msgprint("You cannot set authorization on basis of Discount for %s." % (self.doc.transaction)) raise Exception elif self.doc.based_on == 'Average Discount' and flt(self.doc.value) > 100.00: msgprint("Discount cannot given for more than 100 %s." % ('%')) raise Exception elif self.doc.based_on == 'Customerwise Discount' and not self.doc.master_name: msgprint("Please enter Customer Name for 'Customerwise Discount'") raise Exception else: if self.doc.transaction == 'Appraisal' and self.doc.based_on != 'Not Applicable': msgprint("Based on is 'Not Applicable' while setting authorization rule for 'Appraisal'") raise Exception if self.doc.transaction == 'Expense Voucher' and self.doc.based_on != 'Total Claimed Amount': msgprint("Authorization rule should be based on 'Total Calimed Amount' while setting authorization rule for 'Expense Voucher'") raise Exception
def account_expiry_reminder(self): import webnotes.utils from datetime import datetime # Payment Reminder in case of not enough balance cr_reqd = cint(self.doc.total_users) days_left = cint(self.calc_days()) # check if account balance is sufficient if cint(self.doc.credit_balance)<(cr_reqd): # Difference between last payment date and current date if self.doc.last_deduction_date: last_payment = date_diff(nowdate(),self.doc.last_deduction_date) else: last_payment = -1 # 7 days extension remaining_days = days_left - 24 if last_payment > 30 or last_payment == -1: if remaining_days < 8 and remaining_days >= 1: return "Your account will be de-activated in " + cstr(remaining_days) + " days. Please contact your System Manager to buy credits." elif remaining_days==0: return "Your account will be disabled from tomorrow. Please contact your System Manager to buy credits." elif not has_common(['Administrator'],webnotes.user.get_roles()): return "Stopped" # check if user account is extended for seven days if cint(self.doc.is_trial_account)==0: if days_left < 10 and days_left >= 0: return "You have only %s Credits in your account. Buy credits before %s." % (cint(self.doc.credit_balance),formatdate(self.next_bill_sdate))
def trial_payment_reminders(self): if cint(self.doc.is_trial_account)==1: # Trial Period Expiry trial_end_date = add_days(self.doc.account_start_date, 30) days = date_diff(trial_end_date, nowdate()) # check if trial period has expired if days < 10 and days >= 0 and has_common(['System Manager'],webnotes.user.get_roles()): return "Your Trial Period expires on '%s'. Please buy credits online using Manage Account." % (formatdate(trial_end_date)) # trial period has already expired elif days < 0 and days >= -6: extended_days = 7 + days return "Your Trial Period has expired on %s. However, your account will be live for %s days. Please contact your System Manager to buy credits." % (formatdate(trial_end_date),cstr(extended_days)) elif not has_common(['Administrator'],webnotes.user.get_roles()) and days < -6: return "Stopped" # Account is not a trial account else: return self.account_expiry_reminder()
def get_comp(self): ret = {} type = [] comp = [] # ------ get period ----------- ret["period"] = ["Annual", "Half Yearly", "Quarterly", "Monthly"] # ---- get companies --------- res = sql("select name from `tabCompany`") for r in res: comp.append(r[0]) # comp.append(r[0] for r in res) ret["company"] = comp # --- to get fiscal year and start_date of that fiscal year ----- res = sql("select name, year_start_date from `tabFiscal Year`") ret["fiscal_year"] = [r[0] for r in res] ret["start_dates"] = {} for r in res: ret["start_dates"][r[0]] = str(r[1]) # --- from month and to month (for MIS - Comparison Report) ------- month_list = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] fiscal_start_month = sql( "select MONTH(year_start_date) from `tabFiscal Year` where name = %s", (get_defaults()["fiscal_year"]) ) fiscal_start_month = fiscal_start_month and fiscal_start_month[0][0] or 1 mon = [""] for i in range(fiscal_start_month, 13): mon.append(month_list[i - 1]) for i in range(0, fiscal_start_month - 1): mon.append(month_list[i]) ret["month"] = mon # ------------------------ get MIS Type on basis of roles of session user ------------------------------------------ if has_common(self.roles, ["Sales Manager"]): type.append("Sales") if has_common(self.roles, ["Purchase Manager"]): type.append("Purchase") ret["type"] = type return ret
def check_approving_authority(self, doctype_name, grand_total): det = sql("select amount from `tabApproval Structure` where doctype_name = '%s' and parent = 'Authorization Rules' and amount <= '%s'" % (doctype_name, grand_total)) amt_list, auth_users = [], [] if det: for x in det: amt_list.append(flt(x[0])) max_amount = max(amt_list) # Get names of all approving authority with max amount for d in sql("select approving_authority from `tabApproval Structure` where doctype_name = '%s' and parent = 'Authorization Rules' and amount = '%s'" % (doctype_name, flt(max_amount))): auth_users.append(d[0]) for x in sql("select approving_authority from `tabApproval Structure` where doctype_name = '%s' and parent = 'Authorization Rules' and amount > '%s'" % (doctype_name, grand_total)): auth_users.append(x[0]) if not has_common(auth_users, session['data']['profile']['roles']): msgprint("You do not have an authority to submit this %s. Only %s can submit since amount exceeds %s. %s" % (doctype_name, auth_users, get_defaults()['currency'], flt(max_amount))) raise Exception
def get_comp(self): ret = {} type = [] ret["period"] = ["Annual", "Half Yearly", "Quarterly", "Monthly"] from accounts.page.accounts_browser.accounts_browser import get_companies ret["company"] = get_companies() # --- to get fiscal year and start_date of that fiscal year ----- res = webnotes.conn.sql("select name, year_start_date from `tabFiscal Year`") ret["fiscal_year"] = [r[0] for r in res] ret["start_dates"] = {} for r in res: ret["start_dates"][r[0]] = str(r[1]) # --- from month and to month (for MIS - Comparison Report) ------- month_list = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] fiscal_start_month = webnotes.conn.sql( "select MONTH(year_start_date) from `tabFiscal Year` where name = %s", (webnotes.defaults.get_global_default("fiscal_year")), ) fiscal_start_month = fiscal_start_month and fiscal_start_month[0][0] or 1 mon = [""] for i in range(fiscal_start_month, 13): mon.append(month_list[i - 1]) for i in range(0, fiscal_start_month - 1): mon.append(month_list[i]) ret["month"] = mon # get MIS Type on basis of roles of session user self.roles = webnotes.user.get_roles() if has_common(self.roles, ["Sales Manager"]): type.append("Sales") if has_common(self.roles, ["Purchase Manager"]): type.append("Purchase") ret["type"] = type return ret
def validate_rule(self): if self.doc.transaction != 'Appraisal': if not self.doc.approving_role and not self.doc.approving_user: msgprint("Please enter Approving Role or Approving User", raise_exception=1) elif self.doc.system_user and self.doc.system_user == self.doc.approving_user: msgprint( "Approving User cannot be same as user the rule is Applicable To (User)", raise_exception=1) elif self.doc.system_role and self.doc.system_role == self.doc.approving_role: msgprint("Approving Role cannot be same as user the rule is \ Applicable To (Role).", raise_exception=1) elif self.doc.system_user and self.doc.approving_role and \ has_common([self.doc.approving_role], [x[0] for x in \ sql("select role from `tabUserRole` where parent = '%s'" % \ (self.doc.system_user))]): msgprint( "System User : %s is assigned role : %s. So rule does not make sense" % (self.doc.system_user, self.doc.approving_role), raise_exception=1) elif self.doc.transaction in ['Purchase Order', 'Purchase Receipt', \ 'Purchase Invoice', 'Stock Entry'] and self.doc.based_on \ in ['Average Discount', 'Customerwise Discount', 'Itemwise Discount']: msgprint( "You cannot set authorization on basis of Discount for %s" % self.doc.transaction, raise_exception=1) elif self.doc.based_on == 'Average Discount' and flt( self.doc.value) > 100.00: msgprint("Discount cannot given for more than 100%", raise_exception=1) elif self.doc.based_on == 'Customerwise Discount' and not self.doc.master_name: msgprint( "Please enter Customer Name for 'Customerwise Discount'", raise_exception=1) else: if self.doc.transaction == 'Appraisal' and self.doc.based_on != 'Not Applicable': msgprint( "Based on should be 'Not Applicable' while setting authorization rule\ for 'Appraisal'", raise_exception=1)