Exemplo n.º 1
0
def localPushRequests(request):
    data = json.loads(request.raw_post_data)
    rd = data['request_details']
    for i in rd:
        qty = int(i['qty'])
        request_id = int(i['request_id'])
        product_id = int(i['product_id'])
        request_date = datetime.datetime.strptime(i['request_date'],
                                                  '%Y-%m-%d').date()
        shopid = int(i['shopid'])
        new_request = RequestDetails(request_id=request_id,
                                     request_date=request_date,
                                     qty=qty,
                                     store_id=shopid,
                                     product_id=product_id,
                                     status='received')
        new_request.save()
    return HttpResponse('Yo request')
Exemplo n.º 2
0
def localPushInventory(request):
    data = json.loads(request.raw_post_data)
    inventory = data['inventory']
    for i in inventory:
        batchid = int(i['batchid'])
        productid = int(i['product_id'])
        qty = int(i['qty'])
        minimum_qty = int(i['minimum_qty'])
        selling_price = Decimal(i['selling_price'])
        shopid = int(i['shopid'])
        inv = Inventory.objects.get(product_id_id=productid,
                                    batch_id=batchid,
                                    store_id_id=1)
        inv.qty = qty
        inv.selling_price = selling_price
        inv.minimum_qty = minimum_qty
        inv.save()

        eTran = eTransaction.objects.all()
        for e in eTran:
            inv = Inventory.objects.get(store_id_id=e.store_id,
                                        product_id_id=e.product_id,
                                        batch_id=e.batch_id)
            if (inv.qty < e.quantity_sold):
                r = RequestDetails.objects.all().order_by('-request_id')
                if not r:
                    request_id = 1
                else:
                    request_id = r[0].request_id + 1
                r = RequestDetails(request_id=request_id,
                                   request_date=e.transaction_date,
                                   qty=e.quantity_sold,
                                   store_id=e.store_id,
                                   product_id=e.product_id,
                                   status='reserved')
                r.save()
        return HttpResponse('yo')