def profile_ceation(self): webnotes.errprint("creating profile_ceation") ch=webnotes.conn.sql("select name from tabProfile where name like '%"+cstr(self.doc.contact_email)+"%'") if ch: pass else : pp=Document('Profile') pp.email=self.doc.contact_email pp.first_name=self.doc.contact_name webnotes.errprint(self.doc.password) pp.new_password=self.doc.password pp.account_id=self.doc.name pp.franchise_admin='1' pp.enabled='1' pp.save(new=1) ur=Document('UserRole') ur.parent=self.doc.contact_email ur.parentfield='user_roles' ur.parenttype='Profile' ur.role='Franchise' ur.save(new=1) dv=Document('DefaultValue') dv.parent=self.doc.contact_email dv.parentfield='system_defaults' dv.parenttype='Control Panel' dv.defkey='region' dv.defvalue=self.doc.region dv.save(new=1) aa="insert into __Auth(user,password) values('"+self.doc.contact_email+"',password('"+self.doc.password+"'))" webnotes.errprint(aa) webnotes.conn.sql(aa)
def set_cp_defaults(self, cname, industry, timezone, country, acc_name): cp = Document('Control Panel','Control Panel') cp.account_id = acc_name cp.company_name = cname cp.industry = industry cp.time_zone = timezone cp.country = country cp.client_name = '<div style="padding:4px; font-size:20px;">'+cname+'</div>' cp.save()
def set_cp_defaults(self, cname, industry, timezone, country, acc_name): cp = Document('Control Panel', 'Control Panel') cp.account_id = acc_name cp.company_name = cname cp.industry = industry cp.time_zone = timezone cp.country = country cp.client_name = '<div style="padding:4px; font-size:20px;">' + cname + '</div>' cp.save()
def schedule(_type='POST'): regn = webnotes.conn.sql( "select name from `tabFranchise Visiting Schedule` where name in (select distinct region from `tabFranchise`) and name in (select distinct region from `tabSub Franchise`)", as_list=1) webnotes.errprint(regn) for r in regn: details = webnotes.conn.sql( "select visiting_frequency,frequency,start_date from `tabFranchise Visiting Schedule` where name='" + r[0] + "'", as_list=1) k = webnotes.conn.sql( "select account_id from `tabFranchise` where region='" + r[0] + "'", as_list=1) s = webnotes.conn.sql( "select sf_name from `tabSub Franchise` where region='" + r[0] + "'", as_list=1) bb = get_last_day(details[0][2]) j = 0 from webnotes.utils import nowdate dd = nowdate() if details[0][0] == 'Weekly': m = 4 j = m * cint(details[0][1]) elif details[0][0] == 'Fortnightly': m = 2 j = m * cint(details[0][1]) elif details[0][0] == 'Monthly': m = 1 j = m * cint(details[0][1]) list1 = [] list1.append(details[0][2]) dt = details[0][2] for j in range(0, j): for ls in s: for i in range(len(list1)): d = Document('Sub Franchise Visiting Schedule') d.account_id = k[0][0] d.region = r[0] d.sf_name = ls[0] if details[0][0] == 'Weekly': d.weekly = details[0][1] elif details[0][0] == 'Fortnightly': d.forth_nightly = details[0][1] elif details[0][0] == 'Monthly': d.monthly = details[0][1] d.save() webnotes.conn.commit() webnotes.errprint("Done")
def generate_visiting_schedule(self,bb,s,a,k): j=0 d = datetime.date.today() #n="delete from `tabSub Franchise Visiting Schedule` where region='"+cstr(self.doc.regions)+"' and visiting_date between '"+cstr(d)+"' and '"+cstr(bb)+"'" #webnotes.conn.sql(n) #webnotes.errprint(n) if self.doc.visiting_frequency=='Weekely': m = 7 j = 4 * cint(self.doc.frequency) #j= 5 elif self.doc.visiting_frequency=='Forth Night': #webnotes.errprint("hellooo") m = 15 j = 2 * cint(self.doc.frequency) #j= 2 elif self.doc.visiting_frequency=='One Month': m = 30 j = 1 * cint(self.doc.frequency) #j=1 #webnotes.errprint(j) list1 = [] list1.append(self.doc.start_date) dt=self.doc.start_date #for j in range (0,j): # date=add_days(getdate(dt),m) # webnotes.errprint(date) # if date <= bb: # list1.append(date) # dt=date #webnotes.errprint(self.doc.start_date) #webnotes.errprint(bb) #webnotes.errprint(list1) webnotes.errprint(j) for j in range(0,j): #webnotes.errprint("hii") for ls in s: #webnotes.errprint("hello") for i in range(len(list1)): #webnotes.errprint(k) #webnotes.errprint(list1[i]) d=Document('Sub Franchise Visiting Schedule') d.account_id=k #webnotes.errprint(d.account_id) d.region=self.doc.regions d.device_id=a d.sf_name=ls[0] #visiting_date=list1[i] d.save(new=1) return ("Welcome..")
def on_update(self): #res="select account_id from `tabFranchise` where region='"+self.doc.region+"'" #rs=webnotes.conn.sql(res) #webnotes.errprint(rs) #self.doc.account_id=rs[0][0] #webnotes.errprint(self.doc.account_id) #self.doc.save() s=webnotes.conn.sql("select customer_name from `tabCustomer` where territory='"+cstr(self.doc.region)+"' and name='"+self.doc.name+"'") #webnotes.errprint(s) if not s: d = Document('Customer') d.customer_name=self.doc.sf_name d.territory=self.doc.region d.account_id=self.doc.account_id d.sf_name=self.doc.sf_name d.customer_type='Company' d.customer_group='Commercial'
def on_update(self): #res="select account_id from `tabFranchise` where region='"+self.doc.region+"'" #rs=webnotes.conn.sql(res) #webnotes.errprint(rs) #self.doc.account_id=rs[0][0] #webnotes.errprint(self.doc.account_id) #self.doc.save() s = webnotes.conn.sql( "select customer_name from `tabCustomer` where territory='" + cstr(self.doc.region) + "' and name='" + self.doc.name + "'") #webnotes.errprint(s) if not s: d = Document('Customer') d.customer_name = self.doc.sf_name d.territory = self.doc.region d.account_id = self.doc.account_id d.sf_name = self.doc.sf_name d.customer_type = 'Company' d.customer_group = 'Commercial'
def schedule(_type='POST'): regn=webnotes.conn.sql("select name from `tabFranchise Visiting Schedule` where name in (select distinct region from `tabFranchise`) and name in (select distinct region from `tabSub Franchise`)",as_list=1) webnotes.errprint(regn) for r in regn: details=webnotes.conn.sql("select visiting_frequency,frequency,start_date from `tabFranchise Visiting Schedule` where name='"+r[0]+"'",as_list=1) k=webnotes.conn.sql("select account_id from `tabFranchise` where region='"+r[0]+"'",as_list=1) s=webnotes.conn.sql("select sf_name from `tabSub Franchise` where region='"+r[0]+"'",as_list=1) bb=get_last_day(details[0][2]) j=0 from webnotes.utils import nowdate dd = nowdate() if details[0][0]=='Weekly': m = 4 j = m * cint(details[0][1]) elif details[0][0]=='Fortnightly': m = 2 j = m * cint(details[0][1]) elif details[0][0]=='Monthly': m = 1 j = m * cint(details[0][1]) list1 = [] list1.append(details[0][2]) dt=details[0][2] for j in range(0,j): for ls in s: for i in range(len(list1)): d=Document('Sub Franchise Visiting Schedule') d.account_id=k[0][0] d.region=r[0] d.sf_name=ls[0] if details[0][0]=='Weekly': d.weekly=details[0][1] elif details[0][0]=='Fortnightly': d.forth_nightly=details[0][1] elif details[0][0]=='Monthly': d.monthly=details[0][1] d.save() webnotes.conn.commit() webnotes.errprint("Done")
def generate_visiting_schedule(self,bb,s,a,k): j=0 d = datetime.date.today() if self.doc.visiting_frequency=='Weekely': m = 7 j = 4 * cint(self.doc.frequency) elif self.doc.visiting_frequency=='Fortnightly': m = 15 j = 2 * cint(self.doc.frequency) elif self.doc.visiting_frequency=='Monthly': m = 30 j = 1 * cint(self.doc.frequency) list1 = [] list1.append(self.doc.start_date) dt=self.doc.start_date #webnotes.errprint(j) for j in range(0,j): for ls in s: for i in range(len(list1)): #webnotes.errprint("generation") d=Document('Sub Franchise Visiting Schedule') d.account_id=k d.region=self.doc.regions d.device_id=a d.sf_name=ls[0] if self.doc.visiting_frequency=='Weekely': #webnotes.errprint("Weekely") d.weekly=self.doc.frequency elif self.doc.visiting_frequency=='Fortnightly': #webnotes.errprint("Fortnightly") d.forth_nightly=self.doc.frequency elif self.doc.visiting_frequency=='Monthly': #webnotes.errprint("Monthly") d.monthly=self.doc.frequency d.save(new=1) return ("Welcome..")
def generate_visiting_schedule(self, bb, s, a, k): j = 0 d = datetime.date.today() if self.doc.visiting_frequency == 'Weekely': m = 7 j = 4 * cint(self.doc.frequency) elif self.doc.visiting_frequency == 'Fortnightly': m = 15 j = 2 * cint(self.doc.frequency) elif self.doc.visiting_frequency == 'Monthly': m = 30 j = 1 * cint(self.doc.frequency) list1 = [] list1.append(self.doc.start_date) dt = self.doc.start_date #webnotes.errprint(j) for j in range(0, j): for ls in s: for i in range(len(list1)): #webnotes.errprint("generation") d = Document('Sub Franchise Visiting Schedule') d.account_id = k d.region = self.doc.regions d.device_id = a d.sf_name = ls[0] if self.doc.visiting_frequency == 'Weekely': #webnotes.errprint("Weekely") d.weekly = self.doc.frequency elif self.doc.visiting_frequency == 'Fortnightly': #webnotes.errprint("Fortnightly") d.forth_nightly = self.doc.frequency elif self.doc.visiting_frequency == 'Monthly': #webnotes.errprint("Monthly") d.monthly = self.doc.frequency d.save(new=1) return ("Welcome..")
def create_customer1(auth_key,name,mobile_number,email_id,datetime,version,_type='POST'): login =[] loginObj = {} qr="select name from `tabauth keys` where auth_key="+auth_key res=webnotes.conn.sql(qr) if res: qr1="select name from `tabCustomer Details` where customer_name="+name+" and phone_number="+mobile_number rs=webnotes.conn.sql(qr1) if rs : key={} key['customer_id']=rs[0][0] login.append(key) loginObj['status']='200' loginObj['customer']=login return loginObj else : from webnotes.model.doc import Document d = Document('Customer Details') if len(name)>3: d.customer_name=name[1:-1] if len(email_id)>3: d.customer_email=email_id[1:-1] if len(mobile_number)>3: d.phone_number=mobile_number[1:-1] d.save() d1 = Document('Customer') d1.customer_name=name[1:-1]+'-'+mobile_number[1:-1] d1.territory='' d1.account_id='' d1.sf_name='' d1.customer_type='Company' d1.customer_group='Commercial' d1.company='PowerCap' d1.save(new=1) if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")): if not webnotes.conn.get_value("Account", {"master_type": "Customer","master_name": d1.name}) and not webnotes.conn.get_value("Account", {"master_name": d1.name}): if not webnotes.conn.get_value("Stock Ledger Entry", {"Warehouse": d1.name}): ac_bean = webnotes.bean({ "doctype": "Account", 'account_name': d1.name, 'parent_account': "Accounts Receivable - P", 'group_or_ledger':'Ledger', 'debit_or_credit':'Debit', 'company':"PowerCap", "master_type": "Customer", "master_name": d1.name, "freeze_account": "No" }) ac_bean.ignore_permissions = True ac_bean.insert() webnotes.conn.commit() key={} key['customer_id']=d.name login.append(key) loginObj['status']='200' loginObj['customer']=login return loginObj else: loginObj['status']='401' return loginObj
def create_subfranchise1(auth_key,name,address,map_location,mobile_number,email_id,datetime,version,_type='POST'): login =[] loginObj = {} if len(auth_key[1:-1])<=0 or len(name[1:-1])<=0 or len(address[1:-1])<=0: loginObj['status']='401' loginObj['error']='Incomplete data to create sub- franchise, Please provide token no,name and address' return loginObj qr="select name from `tabauth keys` where auth_key="+auth_key res=webnotes.conn.sql(qr) if res: zz=webnotes.conn.sql("select name from `tabSub Franchise` where name='"+name[1:-1]+"'") if zz: key={} key['subfranchise_id']=zz and zz[0][0] or '' login.append(key) loginObj['status']='200' loginObj['subfranchise']=login return loginObj else: str='sent ' from webnotes.utils.email_lib import sendmail import json,requests url="http://maps.googleapis.com/maps/api/geocode/json?address="+address+"&sensor=true" #return url #webnotes.errprint(url) r = requests.get(url) data = json.loads(r.text) #return data e='' sts=data['status'] if sts=='OK': a=data['results'] b=a[0] c=b['geometry'] e=c['location'] rig="select region from `tabFranchise` where contact_email='"+res[0][0]+"' order by creation desc limit 1" rgn=webnotes.conn.sql(rig) from webnotes.model.doc import Document d = Document('Sub Franchise') d.sf_name=name[1:-1] d.creation=datetime[1:-1] d.region=rgn and rgn[0][0] or '' d.address=address[1:-1] if len(e)>1: d.lat=e['lat'] d.lon=e['lng'] if len(email_id)>3: d.email=email_id[1:-1] if len(mobile_number)>3: d.c_number=mobile_number[1:-1] d.save() d1 = Document('Customer') d1.customer_name=name[1:-1]+'-'+mobile_number[1:-1] d1.territory='' d1.account_id='' d1.sf_name='' d1.customer_type='Company' d1.customer_group='Commercial' d1.company='PowerCap' d1.save(new=1) if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")): if not webnotes.conn.get_value("Account", {"master_type": "Customer","master_name": d1.name}) and not webnotes.conn.get_value("Account", {"master_name": d1.name}): if not webnotes.conn.get_value("Stock Ledger Entry", {"Warehouse": d1.name}): ac_bean = webnotes.bean({ "doctype": "Account", 'account_name': d1.name, 'parent_account': "Accounts Receivable - P", 'group_or_ledger':'Ledger', 'debit_or_credit':'Debit', 'company':"PowerCap", "master_type": "Customer", "master_name": d1.name, "freeze_account": "No" }) ac_bean.ignore_permissions = True ac_bean.insert() webnotes.conn.commit() key={} key['subfranchise_id']=d.name login.append(key) loginObj['status']='200' loginObj['subfranchise']=login return loginObj else: loginObj['status']='401' return loginObj
def profile_ceation(self): webnotes.errprint("creating profile_ceation") ch=webnotes.conn.sql("select name from tabProfile where name like '%"+cstr(self.doc.contact_email)+"%'") if ch: pass else : pp=Document('Profile') pp.email=self.doc.contact_email pp.first_name=self.doc.contact_name webnotes.errprint(self.doc.password) pp.new_password=self.doc.password pp.account_id=self.doc.name pp.franchise_admin='1' pp.enabled='1' pp.save(new=1) ur=Document('UserRole') ur.parent=self.doc.contact_email ur.parentfield='user_roles' ur.parenttype='Profile' ur.role='Franchise' ur.save(new=1) dv=Document('DefaultValue') dv.parent=self.doc.contact_email dv.parentfield='system_defaults' dv.parenttype='Control Panel' dv.defkey='region' dv.defvalue=self.doc.region dv.save(new=1) dv1=Document('DefaultValue') dv1.parent=self.doc.contact_email dv1.parentfield='system_defaults' dv1.parenttype='Control Panel' dv1.defkey='regions' dv1.defvalue=self.doc.regions dv1.save(new=1) aa="insert into __Auth(user,password) values('"+self.doc.contact_email+"',password('"+self.doc.password+"'))" webnotes.errprint(aa) webnotes.conn.sql(aa) zz=webnotes.conn.sql("select accountID from Geozone where accountID='"+self.doc.account_id+"' and geozoneID='"+self.doc.region+"'",debug=1) if not zz: bb="INSERT INTO Geozone select '"+self.doc.account_id+"', geozoneID,sortID, minLatitude,maxLatitude,minLongitude,maxLongitude,zonePurposeID,reverseGeocode,arrivalZone,departureZone,autoNotify,zoomRegion,shapeColor,zoneType,radius,latitude1,longitude1,latitude2,longitude2,latitude3,longitude3,latitude4,longitude4,latitude5,longitude5,latitude6,longitude6,latitude7,longitude7,latitude8,longitude8,latitude9,longitude9,latitude10,longitude10,clientUpload,clientID,groupID,streetAddress,city,stateProvince,postalCode,country,subdivision,displayName,description,lastUpdateTime,creationTime from Geozone where accountID='sysadmin' and geozoneID='"+self.doc.region+"'" webnotes.errprint (bb) webnotes.conn.sql(bb) #dvc="select groupID from DeviceList where accountID='"+self.doc.account_id+"'" #webnotes.errprint(dvc) #webnotes.conn.sql(dvc) #if dvc: # pass #else: dg=Document('Device Group') dg.group_id=self.doc.region.lower() dg.account_id=self.doc.account_id.lower() dg.region=self.doc.region.lower() dg.save(new=1) self.doc.authorized_group=dg.name #DEVICE List dlist=webnotes.conn.sql("select groupID from DeviceList where deviceID='"+self.doc.device_id+"'") webnotes.errprint(dlist) if dlist: pass else: dl="insert into DeviceList (accountID,groupID,deviceID) values('"+cstr(self.doc.account_id)+"','"+cstr(self.doc.authorized_group)+"','"+cstr(self.doc.device_id)+"')" webnotes.conn.sql(dl) webnotes.errprint(dl) #GROUP List glist=webnotes.conn.sql("select groupID from GroupList where accountID='"+cstr(self.doc.account_id)+"' and userID='"+cstr(self.doc.user_id)+"'") webnotes.errprint(glist) if glist: pass else: gl="insert into GroupList (accountID,groupID,userID) values('"+cstr(self.doc.account_id)+"','"+cstr(self.doc.authorized_group)+"','"+cstr(self.doc.user_id)+"')" webnotes.conn.sql(gl) webnotes.errprint(gl)