Invoice bill creation for the specific customers in billing software django forms
i am trying to create a invoice bill for the specific customer , first on the bill customer selection should be available for the selection of the customer , after that we are giving the option to add the items which are taken from the product app along with quantity input option . how can i implement this things using the django and dajngo forms i tried to do this but i am just able to implement the only customer selection option but not of items selection from the product i am giving the my codes of models.py form.py and views.py
models.py:
from django.db import models
from customer.models import Customer
from product.models import Product
# Create your models here.
class Invoice_customer_list(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
# date = models.DateField(auto_now_add=True)
# total_amount = models.DecimalField(max_digits=10, decimal_places=2,default=0.00)
def __str__(self):
return f"Invoice # {self.id} -{self.customer.name}"
class Invoice_product_list(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveBigIntegerField()
forms.py:
from django import forms
from .models import Invoice_customer_list,Invoice_product_list,Product
# Form for the Invoice model
class Invoice_customer_Form(forms.ModelForm):
class Meta:
model = Invoice_customer_list
fields = ['customer']
labels = {
'customer': 'Select Customer',
}
class Invoice_product_form(forms.ModelForm):
class Meta:
model = Invoice_product_list
fields = ['product', 'quantity']
labels = {
'product':'Select Product',
'quantity':'Enter quantity',
}
views.py :
from django.shortcuts import render,redirect
from .forms import Invoice_customer_Form,Invoice_product_form
# Create your views here.
def create_invoice(request):
if request.method == 'POST':
form = Invoice_customer_Form(request.POST)
form_products = Invoice_product_form(request.POST)
if form.is_valid() and form_products.is_valid():
form.save()
form_products.save()
return redirect('invoice_success')
else:
form = Invoice_customer_Form()
form_products = Invoice_product_form()
return render(request, 'invoice/create_invoice.html',{'form':form,'form_products':form_products})