Let custom inventory batch view override logic for mobile UPC scanning

This commit is contained in:
Lance Edgar 2018-01-23 19:00:33 -06:00
parent eefc3b33d7
commit 04d1e303be
2 changed files with 39 additions and 21 deletions

View file

@ -11,6 +11,9 @@
if row.cases:
uom = 'CS'
elif row.units:
if row.product and row.product.weighed:
uom = 'LB'
else:
uom = 'EA'
elif row.case_quantity:
uom = 'CS'

View file

@ -27,6 +27,7 @@ Views for inventory batches
from __future__ import unicode_literals, absolute_import
import re
import decimal
import six
@ -239,7 +240,22 @@ class InventoryBatchView(BatchMasterView):
if upc:
if len(upc) <= 14:
row = self.add_row_for_upc(batch, upc)
if not row:
self.request.session.flash("Product not found: {}".format(upc), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
else:
self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
self.Session.flush()
return self.redirect(self.mobile_row_route_url('view', uuid=row.batch_uuid, row_uuid=row.uuid))
def add_row_for_upc(self, batch, upc):
"""
Add a row to the batch for the given UPC, if applicable.
"""
# try to locate general product by UPC; add to batch either way
provided = GPC(upc, calc_check_digit=False)
checked = GPC(upc, calc_check_digit='upc')
@ -255,17 +271,7 @@ class InventoryBatchView(BatchMasterView):
row.upc = provided # TODO: why not 'checked' instead? how to choose?
row.description = "(unknown product)"
self.handler.add_row(batch, row)
else:
self.request.session.flash("Product not found: {}".format(upc), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
else:
self.request.session.flash("UPC has too many digits ({}): {}".format(len(upc), upc), 'error')
return self.redirect(self.get_action_url('view', batch, mobile=True))
self.Session.flush()
return self.redirect(self.mobile_row_route_url('view', uuid=row.batch_uuid, row_uuid=row.uuid))
return row
def template_kwargs_view_row(self, **kwargs):
row = kwargs['instance']
@ -425,12 +431,21 @@ class ValidBatchRow(forms.validators.ModelValidator):
return row
class Decimal(fe.validators.Number):
def _to_python(self, value, state):
try:
return decimal.Decimal(value)
except ValueError:
raise Invalid(self.message('number', state), value, state)
class InventoryForm(forms.Schema):
allow_extra_fields = True
filter_extra_fields = True
row = ValidBatchRow()
cases = fe.validators.Number()
units = fe.validators.Number()
cases = Decimal()
units = Decimal()
def includeme(config):