Exemplo n.º 1
0
def get_all_stock_items(request):
    '''
        NAME: get_all_stock_items

        expected inputs:
        usage_types = [1,2,3]

        Workflow: This function takes an usage_types input which will be a comma separated string,
        each element considered as usage type of stock item. Function will return all the stock items,
        which are active and usage_types is same as any of input usage_types.
    '''
    try:
        params = get_params(request)
        usage_types = params.get('usage_types')
    except Exception as e:
        print(e)
        return JsonResponse({
            "validation": "Inconsistent data",
            "status": True
        })

    kwargs = {}
    kwargs["is_active"] = True
    kwargs["usage_type__in"] = usage_types

    stock_items = StockItem.objects.filter(**kwargs)

    stock_item_list = []
    for stock_item in stock_items:
        stock_item_list.append(stock_item.get_json())

    return JsonResponse({"data": stock_item_list, "status": True})
Exemplo n.º 2
0
def save_sale_order(request):
    params = get_params(request)

    status, data, message = validate_sale_order(params)

    if not status:
        return JsonResponse({"validation": message, "status": status})

    sale_order = create_sale_order_draft(data['item_list'], data['order_code'],
                                         data['order_type'])

    if not isinstance(sale_order, SaleOrder):
        print('sale_order: ', sale_order)
        return JsonResponse({
            "validation": "Failed to save sale order",
            "status": False
        })

    if not sale_order_honoured(sale_order.id):
        return JsonResponse({
            "validation": "Failed to save sale order",
            "status": False
        })

    return JsonResponse({
        "validation": "Sale order placed successfully",
        "status": True
    })
Exemplo n.º 3
0
def get_purchase_order(request):
    params = get_params(request)
    purchase_order_id = params.get('purchase_order_id')

    if not purchase_order_id:
        return JsonResponse({
            "validation": "Purchase order id not found",
            "status": False
        })

    try:
        purchase_order = PurchaseOrder.objects.get(id=purchase_order_id)
        data = purchase_order.get_json()
        data.update({"item_list": []})

        for item in purchase_order.get_purchase_order_items.all():
            stock_item = item.item.get_json()
            stock_item.update({
                "requested_quantity": item.requested_quantity,
                "requested_unit_price": item.requested_unit_price,
                "received_quantity": item.received_quantity,
                "received_unit_price": item.received_unit_price
            })

            data['item_list'].append(stock_item)
        # End of for loop
        return JsonResponse({"data": data, "status": True})
    except Exception as e:
        print('Error in get_purchase_order: ', e)
        return JsonResponse({
            "validation": "Failed to get purchase order",
            "status": False
        })
Exemplo n.º 4
0
def get_stock_transfer_request(request):
    params = get_params(request)
    stock_transfer_request_id = params.get('stock_transfer_request_id')

    if not stock_transfer_request_id:
        return JsonResponse({
            "validation": "Stock transfer request id not found",
            "status": False
        })

    try:
        stock_transfer_request = StockTransferRequest.objects.get(
            id=stock_transfer_request_id)
        data = stock_transfer_request.get_json()
        data.update({"item_list": []})

        for item in stock_transfer_request.get_stock_transfer_request_items.all(
        ):
            stock_item = item.item.get_json()
            stock_item.update({
                "requested_quantity": item.requested_quantity,
                "received_quantity": item.received_quantity,
            })

            data['item_list'].append(stock_item)
        # End of for loop
        return JsonResponse({"data": data, "status": True})
    except Exception as e:
        print('Error in get_stock_transfer_request: ', e)
        return JsonResponse({
            "validation": "Failed to get stock transfer request",
            "status": False
        })
Exemplo n.º 5
0
def save_stock_item(request):
    params = get_params(request)

    data, message, status = validate_stock_item(params)

    if status:
        try:
            stock_item = StockItem.objects.create(**data)
            return JsonResponse({"validation": message, "status": status})
        except Exception as e:
            print(e)
            return JsonResponse({
                "validation": "Inconsistent data: " + e,
                "status": False
            })
    else:
        return JsonResponse({"validation": message, "status": status})
Exemplo n.º 6
0
def save_recipe(request):
    params = get_params(request)

    status, data, message = validate_recipe(params)

    if not status:
        return JsonResponse({"validation": message, "status": status})

    res = create_recipe(data['produced_stock_item_id'],
                        data['produced_item_quantity'],
                        data['ingredients_list'])
    if res:
        return JsonResponse({"validation": "Recipe saved", "status": True})
    else:
        return JsonResponse({
            "validation": "Failed to save recipe",
            "status": False
        })
Exemplo n.º 7
0
def produce_finished_items(request):
    params = get_params(request)

    status, data, message = validate_produce_finished_item(params)

    if not status:
        return JsonResponse({"validation": message, "status": status})

    res = produce_items_with_recipe_and_transfer(data['produced_stock_items'],
                                                 data['department_id'])
    if res:
        return JsonResponse({
            "validation": "Stock item is produced",
            "status": True
        })
    else:
        return JsonResponse({
            "validation": "Failed to produce item",
            "status": False
        })
Exemplo n.º 8
0
def mark_purchase_order_completed(request):
    params = get_params(request)

    status, data, message = validate_mark_purchase_order_completed(params)

    if status:
        res = purchase_order_honoured(data['purchase_order_id'],
                                      data['item_list'])
        if res:
            return JsonResponse({
                "validation": "Purchase order completed",
                "status": True
            })
        else:
            return JsonResponse({
                "validation": "Failed to mark purchase order as complete",
                "status": False
            })
    else:
        return JsonResponse({"validation": message, "status": False})
Exemplo n.º 9
0
def save_stock_transfer_request(request):
    params = get_params(request)

    status, data, message = validate_stock_transfer_request(params)

    if status:
        res = create_stock_transfer_request_draft(data['source_dept_id'],
                                                  data['dest_dept_id'],
                                                  data['stock_item_list'])
        if res:
            return JsonResponse({
                "validation": "Successfully added stock transfer request",
                "status": True
            })
        else:
            return JsonResponse({
                "validation": "Failed to add stock transfer request",
                "status": False
            })
    else:
        return JsonResponse({"validation": message, "status": status})
Exemplo n.º 10
0
def save_purchase_order(request):
    params = get_params(request)

    status, data, message = validate_purchase_order(params)

    if status:
        res = create_purchase_order_draft(data['item_list'],
                                          data['supplier_id'],
                                          data['dest_department_id'])
        if res:
            return JsonResponse({
                "validation": "Successfully saved purchase order",
                "status": True
            })
        else:
            return JsonResponse({
                "validation": "Failed to save purchase order",
                "status": False
            })
    else:
        return JsonResponse({"validation": message, "status": False})
Exemplo n.º 11
0
def manual_stock_verification(request):
    params = get_params(request)

    status, data, message = validate_manual_stock_verification_checkpoint(
        params['manaul_verification_data'])

    if not status:
        return JsonResponse({"validation": message, "status": status})

    res = create_manual_verification_checkpoint(data)

    print(res)
    if not res:
        return JsonResponse({
            "validation":
            "Failed to create manual stock verificaion checkpoint",
            "status": False
        })

    return JsonResponse({
        "validation": "Created manual stock verificaion checkpoint",
        "status": True
    })