Пример #1
0
def invoicedetails(request):
    context = {}
    inv_id = request.POST['invoice_id']
    purchase_order_id = request.POST['purchase_order_id']
    staff_id = request.POST['staff_id']
    vendor_id = request.POST['vendor_id']
    description = request.POST['description']
    purchaseorder = PurchaseOrder.objects.get(
        purchase_order_id=purchase_order_id)
    staff_info = Person.objects.get(person_id=staff_id)
    vendor_info = Vendor.objects.get(vendor_id=vendor_id)

    responses = request.read()
    print(responses)

    q = QueryDict(responses)

    items_id = q.getlist('item_id')
    print(items_id)
    items_name = q.getlist('item_name')
    print(items_name)
    items_quantity = q.getlist('quantity')
    print(items_quantity)
    items_unit_price = q.getlist('unit_price')
    print(items_unit_price)
    items_total_price = q.getlist('total_price')
    print(items_total_price)

    items = list()

    i = 0
    items_length = len(items_id)
    grand_total = Decimal(0)

    while i < items_length:
        total = Decimal(items_quantity[i]) * Decimal(items_unit_price[i])
        item_table = {
            'item_name': items_name[i],
            'item_id': items_id[i],
            'quantity': items_quantity[i],
            'unit_price': items_unit_price[i],
            'total_price': total
        }
        items.append(item_table)
        i = i + 1
        grand_total = grand_total + total
    print(items)

    # push the data to the database
    current_time = datetime.datetime.now()
    print(current_time)
    inv_info = Invoice(
        invoice_id=inv_id,
        time_created=current_time,
        total_price=grand_total,
        person_id=staff_info,
        description=description,
        vendor_id=vendor_info,
        purchase_order_id=purchaseorder,
    )
    inv_info.save()

    invoice = Invoice.objects.get(invoice_id=inv_id)
    for item in items:
        item_info = Item.objects.get(item_id=item['item_id'])
        inv_item_info = InvoiceItem(invoice_id=invoice,
                                    item_id=item_info,
                                    quantity=item['quantity'],
                                    unit_price=item['unit_price'],
                                    total_price=item['total_price'])
        inv_item_info.save()

    # info pass to html
    context = {
        'title': 'Invoice Details',
        'purchase_order_id': purchase_order_id,
        'invoice_id': inv_id,
        'staff_id': staff_id,
        'vendor_id': vendor_id,
        'rows': items,
        'staff_info': staff_info,
        'vendor_info': vendor_info,
        'grand_total': grand_total,
        'time_created': current_time,
        'description': description
    }

    return render(request, 'Invoice/invoicedetails.html', context)
Пример #2
0
def invoiceupdate(request):

    print(request.body)
    pk = request.GET['inv_id']
    #pk = request.POST.get('inv_id', False)
    invoice = Invoice.objects.get(invoice_id=pk)
    items = InvoiceItem.objects.filter(invoice_id=pk)

    print(invoice.person_id)
    context = {
        'title': 'Invoice Details',
        'purchase_order_id': invoice.purchase_order_id.purchase_order_id,
        'invoice_id': pk,
        'staff_id': invoice.person_id.person_id,
        'vendor_id': invoice.vendor_id.vendor_id,
        'rows': items,
        'staff_info': invoice.person_id,
        'vendor_info': invoice.vendor_id,
        'grand_total': invoice.total_price,
        'time_created': invoice.time_created,
        'description': invoice.description
    }
    # push the data to the database
    current_time = datetime.datetime.now()
    print(current_time)
    inv_info = Invoice(
        invoice_id=inv_id,
        time_created=current_time,
        total_price=grand_total,
        person_id=staff_info,
        description=description,
        vendor_id=vendor_info,
        purchase_order_id=purchaseorder,
    )
    inv_info.save()

    invoice = Invoice.objects.get(invoice_id=inv_id)
    for item in items:
        item_info = Item.objects.get(item_id=item['item_id'])
        inv_item_info = InvoiceItem(invoice_id=invoice,
                                    item_id=item_info,
                                    quantity=item['quantity'],
                                    unit_price=item['unit_price'],
                                    total_price=item['total_price'])
        inv_item_info.save()

    # info pass to html
    context = {
        'title': 'Invoice Details',
        'purchase_order_id': purchase_order_id,
        'invoice_id': inv_id,
        'staff_id': staff_id,
        'vendor_id': vendor_id,
        'rows': items,
        'staff_info': staff_info,
        'vendor_info': vendor_info,
        'grand_total': grand_total,
        'time_created': current_time,
        'description': description
    }

    return render(request, 'Invoice/invoiceupdate.html', context)