mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Changes to StockItem model
- Stock adjustments need to accept decimal values
This commit is contained in:
parent
20755a6dac
commit
75774771dc
@ -18,6 +18,7 @@ from django.dispatch import receiver
|
|||||||
|
|
||||||
from mptt.models import TreeForeignKey
|
from mptt.models import TreeForeignKey
|
||||||
|
|
||||||
|
from decimal import Decimal, InvalidOperation
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from InvenTree import helpers
|
from InvenTree import helpers
|
||||||
|
|
||||||
@ -549,7 +550,10 @@ class StockItem(models.Model):
|
|||||||
quantity: If provided, override the quantity (default = total stock quantity)
|
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:
|
if quantity <= 0:
|
||||||
return False
|
return False
|
||||||
@ -618,7 +622,10 @@ class StockItem(models.Model):
|
|||||||
record the date of stocktake
|
record the date of stocktake
|
||||||
"""
|
"""
|
||||||
|
|
||||||
count = int(count)
|
try:
|
||||||
|
count = Decimal(count)
|
||||||
|
except InvalidOperation:
|
||||||
|
return False
|
||||||
|
|
||||||
if count < 0 or self.infinite:
|
if count < 0 or self.infinite:
|
||||||
return False
|
return False
|
||||||
@ -646,7 +653,10 @@ class StockItem(models.Model):
|
|||||||
if self.serialized:
|
if self.serialized:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
quantity = int(quantity)
|
try:
|
||||||
|
quantity = Decimal(quantity)
|
||||||
|
except InvalidOperation:
|
||||||
|
return False
|
||||||
|
|
||||||
# Ignore amounts that do not make sense
|
# Ignore amounts that do not make sense
|
||||||
if quantity <= 0 or self.infinite:
|
if quantity <= 0 or self.infinite:
|
||||||
@ -670,7 +680,10 @@ class StockItem(models.Model):
|
|||||||
if self.serialized:
|
if self.serialized:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
quantity = int(quantity)
|
try:
|
||||||
|
quantity = Decimal(quantity)
|
||||||
|
except InvalidOperation:
|
||||||
|
return False
|
||||||
|
|
||||||
if quantity <= 0 or self.infinite:
|
if quantity <= 0 or self.infinite:
|
||||||
return False
|
return False
|
||||||
|
@ -20,6 +20,8 @@ from InvenTree.views import QRCodeView
|
|||||||
|
|
||||||
from InvenTree.helpers import str2bool, DownloadFile, GetExportFormats
|
from InvenTree.helpers import str2bool, DownloadFile, GetExportFormats
|
||||||
from InvenTree.helpers import ExtractSerialNumbers
|
from InvenTree.helpers import ExtractSerialNumbers
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from company.models import Company
|
from company.models import Company
|
||||||
@ -398,8 +400,9 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
valid = form.is_valid()
|
valid = form.is_valid()
|
||||||
|
|
||||||
for item in self.stock_items:
|
for item in self.stock_items:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
item.new_quantity = int(item.new_quantity)
|
item.new_quantity = Decimal(item.new_quantity)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
item.error = _('Must enter integer value')
|
item.error = _('Must enter integer value')
|
||||||
valid = False
|
valid = False
|
||||||
|
Loading…
Reference in New Issue
Block a user