Ejemplo n.º 1
0
def add_item(request, chip_id, rf_id):
    order = Order.objects.all().filter(chip__tag=chip_id).order_by('-created')
    if len(order) > 0:
        order = order[0]
        order.created = datetime.datetime.now()
        order.save()
        sku = SKU.objects.all().filter(rfid=rf_id)
        if len(sku) == 0:
            return HttpResponse('{-1}')
        sku = sku[0]
        item = Item.objects.all().filter(order=order, sku=sku)
        if len(item) > 0:
            item = item[0]
            item.quantity += 1
            item.save()
        else:
            item = Item(
                sku=sku,
                quantity=1,
                order=order,
            )
            item.save()
        return HttpResponse('{' + str(sku.title) + ' Rs.' + str(sku.price) +
                            '/-}')
    else:
        return HttpResponse('{-1}')
Ejemplo n.º 2
0
def add_item(request, chip_id, rf_id):
    order = Order.objects.all().filter(chip__tag=chip_id).order_by('-created')
    if len(order) > 0:
        order = order[0]
        order.created = datetime.datetime.now()
        order.save()
        sku = SKU.objects.all().filter(rfid=rf_id)
        if len(sku) == 0:
            return HttpResponse('{-1}')
        sku = sku[0]
        item = Item.objects.all().filter(order=order, sku=sku)
        if len(item) > 0:
            item = item[0]
            item.quantity += 1
            item.save()
        else:
            item = Item(
                    sku=sku,
                    quantity=1,
                    order=order,
            )
            item.save()
        return HttpResponse('{' + str(sku.title) + ' Rs.' + str(sku.price) + '/-}')
    else:
        return HttpResponse('{-1}')
Ejemplo n.º 3
0
def follow(request: WSGIRequest):
    """
        request_body:
        {
            "order_id": 1,
            "creator": "Sam",
            "product": "雞排",
            "count": 1,
            "remarks": "胡椒、不要辣"
        }

        response_body:
        {
            "status": "success"
        }
    """
    if request.method == 'POST':
        data_in = json.loads(request.body)

        # check expired
        order = Order.objects.filter(id=data_in['order_id']).first()
        if order is None:
            return _json(status='Failed to follow order', exception='order id not found')
        if order.is_expired():
            return _json(status='Failed to follow order', exception='order expired')

        try:
            item = Item()
            item.order = order
            user = User.objects.filter(name=data_in['creator']).first()
            if user is None:
                user = User()
                user.name = data_in['creator']
            item.creator = user
            item.product = data_in['product']
            item.remarks = data_in['remarks']
            item.count = data_in['count']
            item.save()
        except Exception as e:
            return _json(status='Failed to follow order', exception=str(e), data_in=data_in)
        return _json(status='Create follow item', item_id=item.id, data_in=data_in)
    return _json(status='No such method')