Skip to content

Commit

Permalink
Merge pull request #1830 from airqo-platform/staging
Browse files Browse the repository at this point in the history
move to production
  • Loading branch information
Baalmart authored Jan 24, 2024
2 parents 581711c + 3cacf56 commit 77d4f68
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions inventory/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,40 +166,58 @@ def metadata(request):


@login_required
def details(request,pk):
def details(request, pk):
item = Stock.objects.get(id=pk)

if request.method == 'POST':
newStockForm = NewStockForm(request.POST, instance=item)
dispenseForm = DispenseForm(request.POST, instance=item)

if newStockForm.is_valid():
history = StockHistory.objects.create(item_name=item.item_name,
stock_in=item.stock_in,
stock_out=item.stock_out,
stock_in_date=item.stock_in_date,
stock_out_date=item.stock_out_date)
# Save the original stock_out value before updating it to zero
original_stock_out = item.stock_out

# Set stock_out to zero
item.stock_out = 0

# Save the new stock entry
new_stock_instance = newStockForm.save()


history = StockHistory.objects.create(
item_name=item.item_name,
stock_in=new_stock_instance.stock_in,
stock_out=original_stock_out, # Use the original stock_out value
stock_in_date=new_stock_instance.stock_in_date,
stock_out_date=new_stock_instance.stock_out_date
)
history.save()
newStockForm.save()

return redirect('products')

if dispenseForm.is_valid():
history = StockHistory.objects.create(item_name=item.item_name,
stock_in=item.stock_in,
stock_out=item.stock_out,
stock_in_date=item.stock_in_date,
stock_out_date=item.stock_out_date)
history = StockHistory.objects.create(
item_name=item.item_name,
stock_in=item.stock_in,
stock_out=item.stock_out,
stock_in_date=item.stock_in_date,
stock_out_date=item.stock_out_date
)
history.save()
dispenseForm.save()
return redirect('products')

else:
newStockForm = NewStockForm(instance=item)
dispenseForm = DispenseForm(instance=item)

context = {
'newStockForm' : newStockForm,
'dispenseForm' : dispenseForm,
'item' : item
'newStockForm': newStockForm,
'dispenseForm': dispenseForm,
'item': item
}
return render(request,'dashboard/details.html',context)

return render(request, 'dashboard/details.html', context)

@login_required
def edit_inventory(request,pk):
Expand Down

0 comments on commit 77d4f68

Please sign in to comment.