Ejemplo n.º 1
0
    def getDateSpecifiedPurchase(self, request):
        c = []
        d = []
        z = []
        dategiven = 0
        data = {}
        query1 = Customer.query()
        entity1 = query1.get()
        for field in request.all_fields():
            if (field.name == 'itemId'):
                data[field.name] = ndb.Key(Item, getattr(request, field.name))
            else:
                data[field.name] = getattr(request, field.name)
        logging.debug('date')
        logging.debug(data['date'])
        for q in query1:
            if (data['date'] != None):
                logging.debug(data['date'])
                f = datetime.datetime.strptime(data['date'], '%m/%d/%y').date()
            else:
                d = DailyOrder.query(DailyOrder.custId == q.key,
                                     projection=[DailyOrder.orderDate])
                for x in d:
                    z.append(x.orderDate)
                f = heapq.nlargest(1, z)
                if f:
                    f = f[0]
            y = -1
            logging.debug(f)
            if f:
                q1 = DailyOrder.query(ndb.AND(
                    DailyOrder.custId == q.key, DailyOrder.orderDate == f,
                    DailyOrder.itemId == data['itemId']),
                                      projection=[DailyOrder.itemQuantity])
                for q2 in q1:
                    y = q2.itemQuantity
            else:
                y = -1
            logging.debug('query resulet')
            logging.debug(q1)
            for q2 in q1:
                logging.debug(q2)
            setattr(q, 'itemQuantity', float(y))
            setattr(q, 'custId', q.key)
            c.append(self._copyCustomerItemQuantityToForm(q))
            z = []

        return CustomerShortFormList(custItemQuantityList=c)
	def getDateSpecifiedPurchase(self,request):
		c = []
		d = []
		z = []
		dategiven=0
		data = {}
		query1 = Customer.query()
		entity1 = query1.get()
		for field in request.all_fields():
			if (field.name == 'itemId'):
				data[field.name] = ndb.Key(Item,getattr(request,field.name))
			else:
				data[field.name] = getattr(request,field.name) 
		logging.debug('date')
		logging.debug(data['date'])
		for q in query1:
			if(data['date'] != None):
				logging.debug(data['date'])
				f = datetime.datetime.strptime(data['date'], '%m/%d/%y').date()
			else:
				d = DailyOrder.query(DailyOrder.custId == q.key,projection = [DailyOrder.orderDate])
				for x in d:
					z.append(x.orderDate)
				f = heapq.nlargest(1,z)
				if f:
					f = f[0]
			y = -1
			logging.debug(f)
			if f:
				q1 = DailyOrder.query(ndb.AND(DailyOrder.custId == q.key, DailyOrder.orderDate == f, DailyOrder.itemId == data['itemId']),projection = [DailyOrder.itemQuantity])
				for q2 in q1:
					y = q2.itemQuantity
			else:
				y = -1
			logging.debug('query resulet')
			logging.debug(q1)
			for q2 in q1:
					logging.debug(q2)
			setattr(q,'itemQuantity',float(y))
			setattr(q,'custId',q.key)
			c.append(self._copyCustomerItemQuantityToForm(q))
			z = []
			
			
		return CustomerShortFormList(custItemQuantityList=c)
Ejemplo n.º 3
0
    def update_dailyorder(self, data):
        query = DailyOrder.query(
            ndb.AND(DailyOrder.custId == data['custId'],
                    DailyOrder.itemId == data['itemId'],
                    DailyOrder.orderDate == data['orderDate']))
        logging.debug(data['orderDate'])
        logging.debug(query)
        x = 0
        for q in query:
            data['key'] = q.key
            data['itemQuantity'] = q.itemQuantity + data['itemQuantity']
            data['orderPrice'] = q.orderPrice + data['orderPrice']
            data['orderDate'] = q.orderDate
            x = 1
        if x:
            print "i"

        else:
            print "else mai hun"
            do_id = Item.allocate_ids(size=1)[0]
            do_key = ndb.Key(DailyOrder, do_id)
            data['key'] = do_key
        DailyOrder(**data).put()
	def update_dailyorder(self,data):
		query = DailyOrder.query(ndb.AND(DailyOrder.custId == data['custId'] , DailyOrder.itemId == data['itemId'], DailyOrder.orderDate == data['orderDate']))
		logging.debug(data['orderDate'])
		logging.debug(query)
		x=0
		for q in query:
			data['key'] = q.key 
			data['itemQuantity'] = q.itemQuantity + data['itemQuantity']
			data['orderPrice'] = q.orderPrice + data['orderPrice']
			data['orderDate'] = q.orderDate
			x=1
		if x:
			print "i"
			
		else:
			print "else mai hun"
			do_id = Item.allocate_ids(size=1)[0]
			do_key = ndb.Key(DailyOrder, do_id)
			data['key'] = do_key
		DailyOrder(**data).put()