Changes to StockItem model

- Stock adjustments need to accept decimal values
This commit is contained in:
Oliver Walters 2019-11-19 09:18:41 +11:00
parent 20755a6dac
commit 75774771dc
2 changed files with 21 additions and 5 deletions

View File

@ -18,6 +18,7 @@ from django.dispatch import receiver
from mptt.models import TreeForeignKey
from decimal import Decimal, InvalidOperation
from datetime import datetime
from InvenTree import helpers
@ -549,7 +550,10 @@ class StockItem(models.Model):
quantity: If provided, override the quantity (default = total stock quantity)
"""
quantity = int(kwargs.get('quantity', self.quantity))
try:
quantity = Decimal(kwargs.get('quantity', self.quantity))
except InvalidOperation:
return False
if quantity <= 0:
return False
@ -618,7 +622,10 @@ class StockItem(models.Model):
record the date of stocktake
"""
count = int(count)
try:
count = Decimal(count)
except InvalidOperation:
return False
if count < 0 or self.infinite:
return False
@ -646,7 +653,10 @@ class StockItem(models.Model):
if self.serialized:
return False
quantity = int(quantity)
try:
quantity = Decimal(quantity)
except InvalidOperation:
return False
# Ignore amounts that do not make sense
if quantity <= 0 or self.infinite:
@ -670,7 +680,10 @@ class StockItem(models.Model):
if self.serialized:
return False
quantity = int(quantity)
try:
quantity = Decimal(quantity)
except InvalidOperation:
return False
if quantity <= 0 or self.infinite:
return False

View File

@ -20,6 +20,8 @@ from InvenTree.views import QRCodeView
from InvenTree.helpers import str2bool, DownloadFile, GetExportFormats
from InvenTree.helpers import ExtractSerialNumbers
from decimal import Decimal
from datetime import datetime
from company.models import Company
@ -398,8 +400,9 @@ class StockAdjust(AjaxView, FormMixin):
valid = form.is_valid()
for item in self.stock_items:
try:
item.new_quantity = int(item.new_quantity)
item.new_quantity = Decimal(item.new_quantity)
except ValueError:
item.error = _('Must enter integer value')
valid = False