feat(Payments): Generate cash payment with purchase.
This commit is contained in:
@@ -3,7 +3,7 @@ from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.views.generic import ListView
|
||||
from django.db import transaction
|
||||
|
||||
from .models import Sale, Product, ProductCategory, Payment
|
||||
from .models import Sale, Product, ProductCategory, Payment, PaymentMethods
|
||||
from .forms import ImportProductsForm, PurchaseForm, SaleLineFormSet, ReconciliationJarForm, PurchaseSummaryForm
|
||||
|
||||
import csv
|
||||
@@ -13,7 +13,6 @@ import io
|
||||
def index(request):
|
||||
return render(request, 'don_confiao/index.html')
|
||||
|
||||
|
||||
def buy(request):
|
||||
if request.method == "POST":
|
||||
sale_form = PurchaseForm(request.POST)
|
||||
@@ -24,11 +23,18 @@ def buy(request):
|
||||
line_formset.is_valid(),
|
||||
sale_summary_form.is_valid()
|
||||
])
|
||||
payment_method = request.POST.get('payment_method')
|
||||
valid_payment_methods = [PaymentMethods.CASH]
|
||||
valid_payment_method = payment_method in valid_payment_methods
|
||||
if forms_are_valid:
|
||||
with transaction.atomic():
|
||||
sale = sale_form.save()
|
||||
line_formset.instance = sale
|
||||
line_formset.save()
|
||||
Payment.total_payment_from_sale(
|
||||
payment_method,
|
||||
sale
|
||||
)
|
||||
return HttpResponseRedirect("compras")
|
||||
else:
|
||||
sale_form = PurchaseForm()
|
||||
|
||||
Reference in New Issue
Block a user