Add basic "receive row" desktop view for receiving batches

not terribly polished yet, but works
This commit is contained in:
Lance Edgar 2019-03-13 18:31:57 -05:00
parent 7fab472fc4
commit c869516449
8 changed files with 343 additions and 9 deletions

View file

@ -98,6 +98,16 @@ class GPCType(colander.SchemaType):
raise colander.Invalid(node, six.text_type(err))
class ProductQuantity(colander.MappingSchema):
"""
Combo schema type for product cases and units; useful for inventory,
ordering, receiving etc. Meant to be used with the ``CasesUnitsWidget``.
"""
cases = colander.SchemaNode(colander.Decimal(), missing=colander.null)
units = colander.SchemaNode(colander.Decimal(), missing=colander.null)
class ModelType(colander.SchemaType):
"""
Custom schema type for scalar ORM relationship fields.

View file

@ -36,6 +36,8 @@ import colander
from deform import widget as dfwidget
from webhelpers2.html import tags, HTML
from tailbone.forms.types import ProductQuantity
class ReadonlyWidget(dfwidget.HiddenWidget):
@ -88,6 +90,46 @@ class PercentInputWidget(dfwidget.TextInputWidget):
return six.text_type(value)
class CasesUnitsWidget(dfwidget.Widget):
"""
Widget for collecting case and/or unit quantities. Most useful when you
need to ensure user provides cases *or* units but not both.
"""
template = 'cases_units'
amount_required = False
one_amount_only = False
def serialize(self, field, cstruct, **kw):
if cstruct in (colander.null, None):
cstruct = ''
readonly = kw.get('readonly', self.readonly)
kw['cases'] = cstruct['cases'] or ''
kw['units'] = cstruct['units'] or ''
template = readonly and self.readonly_template or self.template
values = self.get_template_values(field, cstruct, kw)
return field.renderer(template, **values)
def deserialize(self, field, pstruct):
if pstruct is colander.null:
return colander.null
schema = ProductQuantity()
try:
validated = schema.deserialize(pstruct)
except colander.Invalid as exc:
raise colander.Invalid(field.schema, "Invalid pstruct: %s" % exc)
if self.amount_required and not (validated['cases'] or validated['units']):
raise colander.Invalid(field.schema, "Must provide case or unit amount",
value=validated)
if self.amount_required and self.one_amount_only and validated['cases'] and validated['units']:
raise colander.Invalid(field.schema, "Must provide case *or* unit amount, "
"but *not* both", value=validated)
return validated
class PlainSelectWidget(dfwidget.SelectWidget):
template = 'select_plain'