Accept any decimal numbers for API inventory batch counts

i.e. don't assume integer values
This commit is contained in:
Lance Edgar 2021-04-12 11:36:24 -05:00
parent c48371ca2a
commit 2d75409757

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar # Copyright © 2010-2021 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -26,6 +26,8 @@ Tailbone Web API - Inventory Batches
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import decimal
import six import six
from rattail import pod from rattail import pod
@ -157,17 +159,19 @@ class InventoryBatchRowViews(APIBatchRowView):
Converts certain fields within the data, to proper "native" types. Converts certain fields within the data, to proper "native" types.
""" """
data = dict(data)
# convert some data types as needed # convert some data types as needed
if 'cases' in data: if 'cases' in data:
if data['cases'] == '': if data['cases'] == '':
data['cases'] = None data['cases'] = None
elif data['cases']: elif data['cases']:
data['cases'] = int(data['cases']) data['cases'] = decimal.Decimal(data['cases'])
if 'units' in data: if 'units' in data:
if data['units'] == '': if data['units'] == '':
data['units'] = None data['units'] = None
elif data['units']: elif data['units']:
data['units'] = int(data['units']) data['units'] = decimal.Decimal(data['units'])
# update row per usual # update row per usual
row = super(InventoryBatchRowViews, self).update_object(row, data) row = super(InventoryBatchRowViews, self).update_object(row, data)