feat(Buy): add transaction on buy process.
This commit is contained in:
parent
7eb8f40d7a
commit
1f37e57e00
@ -1,8 +1,7 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.template import loader
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.views.generic import ListView
|
||||
from django.db import transaction
|
||||
|
||||
from .models import Sale, Product, ProductCategory, Payment
|
||||
from .forms import ImportProductsForm, PurchaseForm, SaleLineFormSet, ReconciliationJarForm, PurchaseSummaryForm
|
||||
@ -26,9 +25,10 @@ def buy(request):
|
||||
sale_summary_form.is_valid()
|
||||
])
|
||||
if forms_are_valid:
|
||||
sale = sale_form.save()
|
||||
line_formset.instance = sale
|
||||
line_formset.save()
|
||||
with transaction.atomic():
|
||||
sale = sale_form.save()
|
||||
line_formset.instance = sale
|
||||
line_formset.save()
|
||||
return HttpResponseRedirect("compras")
|
||||
else:
|
||||
sale_form = PurchaseForm()
|
||||
|
Loading…
Reference in New Issue
Block a user