class RfqFullPrice(models.Model):
sender = models.name = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="quote_sender")`
receiver = models.name = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="quote_reciever")
requestedquotation = models.ForeignKey(RequestForQuotation, related_name="replyprice_rfq", on_delete=models.CASCADE)
subtotal = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
delivery_charges = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
overall_total = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
validity_start_date = models.DateField()
validity_end_date = models.DateField()
class ReplyItemPrice(models.Model):
full_price = models.ForeignKey(RfqFullPrice, on_delete=models.CASCADE, related_name='full_price')
the_rfq = models.ForeignKey(RequestForQuotation, on_delete=models.CASCADE)
item = models.ForeignKey(RequestForQuotationItem, on_delete=models.CASCADE, related_name="rfq_item")
quantity = models.CharField(max_length = 200, help_text='Enter the qauntity')
unit_price = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
item_total_price = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
def quote(request, pk):
template_name = 'request_quote/send_quote.html'
requestedquotation = get_object_or_404(RequestForQuotation, pk=pk)
items = RequestForQuotationItem.objects.filter(item=requestedquotation)
if request.method == 'GET':
full_priceform =QuoteFullPriceForm()
item_priceform = QuoteItemPriceForm()
elif request.method == 'POST':
full_priceform =QuoteFullPriceForm(request.POST, request.FILES)
item_priceform = QuoteItemPriceForm(request.POST, request.FILES)
if full_priceform.is_valid() and item_priceform.is_valid():
full_priceform = full_priceform.save(commit=False)
full_priceform.receiver = requestedquotation.sender
full_priceform.sender = request.user
full_priceform.requestedquotation = requestedquotation
full_priceform.save()
for form in item_priceform:
form = item_priceform.save(commit=False)
form.full_price = full_priceform
form.the_rfq = requestedquotation
form.item = items
form.save()
messages.success(request, 'Uploaded'\
'successfully')
return redirect('/')
else:
messages.error(request, 'Error While Uploading')
context = {
'full_priceform':full_priceform,
'item_priceform':item_priceform,
'requestedquotation':requestedquotation,
'items':items,
}
return render(request, template_name, context)