mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Bug fix - receiving lines against a PO caused issues due to integer/Decimal conversion
This commit is contained in:
parent
3098f6045f
commit
067d2be1f0
@ -12,6 +12,7 @@ from django.views.generic import DetailView, ListView
|
|||||||
from django.forms import HiddenInput
|
from django.forms import HiddenInput
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from decimal import Decimal, InvalidOperation
|
||||||
|
|
||||||
from .models import PurchaseOrder, PurchaseOrderLineItem
|
from .models import PurchaseOrder, PurchaseOrderLineItem
|
||||||
from .admin import POLineItemResource
|
from .admin import POLineItemResource
|
||||||
@ -324,6 +325,8 @@ class PurchaseOrderReceive(AjaxUpdateView):
|
|||||||
self.lines = []
|
self.lines = []
|
||||||
self.destination = None
|
self.destination = None
|
||||||
|
|
||||||
|
msg = _("Items received")
|
||||||
|
|
||||||
# Extract the destination for received parts
|
# Extract the destination for received parts
|
||||||
if 'location' in request.POST:
|
if 'location' in request.POST:
|
||||||
pk = request.POST['location']
|
pk = request.POST['location']
|
||||||
@ -332,7 +335,11 @@ class PurchaseOrderReceive(AjaxUpdateView):
|
|||||||
except (StockLocation.DoesNotExist, ValueError):
|
except (StockLocation.DoesNotExist, ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
errors = self.destination is None
|
errors = False
|
||||||
|
|
||||||
|
if self.destination is None:
|
||||||
|
errors = True
|
||||||
|
msg = _("No destination set")
|
||||||
|
|
||||||
# Extract information on all submitted line items
|
# Extract information on all submitted line items
|
||||||
for item in request.POST:
|
for item in request.POST:
|
||||||
@ -359,15 +366,17 @@ class PurchaseOrderReceive(AjaxUpdateView):
|
|||||||
receive = self.request.POST[item]
|
receive = self.request.POST[item]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
receive = int(receive)
|
receive = Decimal(receive)
|
||||||
except ValueError:
|
except InvalidOperation:
|
||||||
# In the case on an invalid input, reset to default
|
# In the case on an invalid input, reset to default
|
||||||
receive = line.remaining()
|
receive = line.remaining()
|
||||||
|
msg = _("Error converting quantity to number")
|
||||||
errors = True
|
errors = True
|
||||||
|
|
||||||
if receive < 0:
|
if receive < 0:
|
||||||
receive = 0
|
receive = 0
|
||||||
errors = True
|
errors = True
|
||||||
|
msg = _("Receive quantity less than zero")
|
||||||
|
|
||||||
line.receive_quantity = receive
|
line.receive_quantity = receive
|
||||||
self.lines.append(line)
|
self.lines.append(line)
|
||||||
@ -378,7 +387,7 @@ class PurchaseOrderReceive(AjaxUpdateView):
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
'form_valid': errors is False,
|
'form_valid': errors is False,
|
||||||
'success': 'Items marked as received',
|
'success': msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.renderJsonResponse(request, data=data, form=self.get_form())
|
return self.renderJsonResponse(request, data=data, form=self.get_form())
|
||||||
|
Loading…
Reference in New Issue
Block a user