Пример #1
0
def create_customer(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)
		rgn=webnotes.conn.sql("select region from `tabFranchise` where contact_email='"+res[0][0]+"'")
		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.region=rgn[0][0]
        	        d.save()

			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
Пример #2
0
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
Пример #3
0
def get_message(number,message,_type='POST'):
	if (cint(len(message[1:-1]))<=0  or cint(len(number[1:-1]))<=0):
		invObj={}
                invObj['status']='401'
                invObj['error']='Incomplete data to send message, Please provide messages and mobile number'
                return invObj
        from webnotes.model.doc import Document
	from webnotes.utils import nowdate,flt,cstr,add_months
        m=message[1:-1].split(',')

	#return m[2]
	bsrn=m[2]
	csrn=m[3]
	vm=m[4]
	un=m[5]
	va=m[6]
        a="select name from `tabCustomer Details` where name='"+m[0]+"-"+number[1:-1]+"'"
	b=webnotes.conn.sql(a)
	itm="select item_code from `tabSerial No` where name='"+cstr(m[2])+"'"
	itemm=webnotes.conn.sql(itm)
        #webnotes.errprint(itemm[0][0])
	#webnotes.errprint(itemm)
        qrs="select warranty_period from tabItem where name='"+cstr(itemm[0][0])+"'"
	#webnotes.errprint("item----------------")
        #webnotes.errprint(itemm[0][0])
        ress=webnotes.conn.sql(qrs)
	#webnotes.errprint("warrenty-----------")
        #webnotes.errprint(ress[0][0])
        if b:
		l = Document('Customer Details',b[0][0])
                l.customer_name=m[0]
		l.customer_email=m[1]
		l.phone_number=number[1:-1]
                l.save()
                webnotes.conn.commit()
		m = Document('Customer Data')
		m.serial_no=bsrn
                m.warranty_start_on=nowdate()
		m.vehical_make=vm
		m.vehical_age=un
		m.unit_no=va
		m.item=itemm[0][0]
		m.capacitor_serial_no=csrn
		m.warranty_end_on=add_months(cstr(nowdate()),cint(ress[0][0]))
		m.parent=l.name
                m.parenttype='Customer Details'
                m.parentfield='customer_data'
		#webnotes.errprint(m.item)
		#webnotes.errprint(add_months(cstr(nowdate()),cint(ress[0][0])))
	        m.save(new=1)
                webnotes.conn.commit()
	else:
                l = Document('Customer Details')
                l.customer_name=m[0]
                l.customer_email=m[1]
                l.phone_number=number[1:-1]
                l.save(new=1)
                webnotes.conn.commit()
                m = Document('Customer Data')
                m.serial_no=bsrn
                m.warranty_start_on=nowdate()
	        m.warranty_end_on=add_months(cstr(nowdate()),cint(ress[0][0]))
		m.item=itemm[0][0]
                m.vehical_make=vm
                m.vehical_age=un
                m.unit_no=va
		m.capacitor_serial_no=csrn
                m.parent=l.name
                m.parenttype='Customer Details'
                m.parentfield='customer_data'
                m.save(new=1)
                webnotes.conn.commit()
        import requests
	from webnotes.model.code import get_obj
	msg="Dear Customer, welcome to PowerCap You have purchased the battery with serail no. '"+bsrn+"' today, your warrenty will expire on 29/09/2015, \n Regards,\n PowerCap"	
	#msg1=msg.split(",")
	#return msg
	#number='9890865260'
	number1=number[1:-1]
	webnotes.errprint(number1)
	nos=[]
	nos.append(number1)
	webnotes.errprint(nos)
	get_obj('SMS Control', 'SMS Control').send_sms(nos, cstr(msg))
        login =[]
        invObj={}
	invObj['status']='200'
	invObj['message']='Updated the record'
        return invObj