Beispiel #1
0
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
Beispiel #2
0
def create_subfranchise(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()
		key={}
		key['subfranchise_id']=d.name
		login.append(key)
		loginObj['status']='200'
		loginObj['subfranchise']=login
		return loginObj
	else:
		loginObj['status']='401'
		return loginObj