Add way to prevent "case" entries for inventory adjustment batch
This commit is contained in:
parent
57c2a7981f
commit
54bfafdbfe
4 changed files with 80 additions and 30 deletions
|
@ -97,6 +97,10 @@ class InventoryBatchView(BatchMasterView):
|
|||
# set to False to disable "zero all" batch count mode
|
||||
allow_zero_all = True
|
||||
|
||||
# set to False to prevent exposing case fields for user input,
|
||||
# when the batch count mode is "adjust only"
|
||||
allow_adjustment_cases = True
|
||||
|
||||
labels = {
|
||||
'mode': "Count Mode",
|
||||
}
|
||||
|
@ -310,8 +314,16 @@ class InventoryBatchView(BatchMasterView):
|
|||
'index_url': self.get_action_url('view', batch),
|
||||
'form': form,
|
||||
'dform': form.make_deform_form(),
|
||||
'allow_cases': self.allow_cases(batch),
|
||||
})
|
||||
|
||||
def allow_cases(self, batch):
|
||||
if batch.mode == self.enum.INVENTORY_MODE_ADJUST:
|
||||
if self.allow_adjustment_cases:
|
||||
return True
|
||||
return False
|
||||
return True
|
||||
|
||||
def desktop_lookup(self):
|
||||
"""
|
||||
Try to locate a product by UPC, and validate it in the context of
|
||||
|
@ -463,23 +475,26 @@ class InventoryBatchView(BatchMasterView):
|
|||
"""
|
||||
self.viewing = True
|
||||
row = self.get_row_instance()
|
||||
parent = self.get_parent(row)
|
||||
batch = self.get_parent(row)
|
||||
form = self.make_mobile_row_form(row)
|
||||
context = {
|
||||
'row': row,
|
||||
'batch': batch,
|
||||
'instance': row,
|
||||
'instance_title': self.get_row_instance_title(row),
|
||||
'parent_model_title': self.get_model_title(),
|
||||
'parent_title': self.get_instance_title(parent),
|
||||
'parent_url': self.get_action_url('view', parent, mobile=True),
|
||||
'parent_title': self.get_instance_title(batch),
|
||||
'parent_url': self.get_action_url('view', batch, mobile=True),
|
||||
'product_image_url': pod.get_image_url(self.rattail_config, row.upc),
|
||||
'form': form,
|
||||
'allow_cases': self.allow_cases(batch),
|
||||
}
|
||||
|
||||
if self.request.has_perm('{}.edit_row'.format(self.get_permission_prefix())):
|
||||
update_form = forms.Form(schema=InventoryForm(), request=self.request)
|
||||
schema = InventoryForm().bind(session=self.Session())
|
||||
update_form = forms.Form(schema=schema, request=self.request)
|
||||
if update_form.validate(newstyle=True):
|
||||
row = update_form.validated['row']
|
||||
row = self.Session.query(model.InventoryBatchRow).get(update_form.validated['row'])
|
||||
cases = update_form.validated['cases']
|
||||
units = update_form.validated['units']
|
||||
if cases:
|
||||
|
@ -489,7 +504,8 @@ class InventoryBatchView(BatchMasterView):
|
|||
row.cases = None
|
||||
row.units = units
|
||||
self.handler.refresh_row(row)
|
||||
return self.redirect(self.request.route_url('mobile.{}.view'.format(self.get_route_prefix()), uuid=row.batch_uuid))
|
||||
route_prefix = self.get_route_prefix()
|
||||
return self.redirect(self.request.route_url('mobile.{}.view'.format(route_prefix), uuid=batch.uuid))
|
||||
|
||||
return self.render_to_response('view_row', context, mobile=True)
|
||||
|
||||
|
@ -533,6 +549,7 @@ class InventoryBatchView(BatchMasterView):
|
|||
|
||||
def configure_row_form(self, f):
|
||||
super(InventoryBatchView, self).configure_row_form(f)
|
||||
row = f.model_instance
|
||||
|
||||
# readonly fields
|
||||
f.set_readonly('upc')
|
||||
|
@ -557,6 +574,11 @@ class InventoryBatchView(BatchMasterView):
|
|||
# upc
|
||||
f.set_renderer('upc', self.render_upc)
|
||||
|
||||
# cases
|
||||
if self.editing:
|
||||
if not self.allow_cases(row.batch):
|
||||
f.set_readonly('cases')
|
||||
|
||||
def render_upc(self, row, field):
|
||||
upc = row.upc
|
||||
if not upc:
|
||||
|
@ -599,19 +621,26 @@ class InventoryBatchView(BatchMasterView):
|
|||
permission='{}.create_row'.format(permission_prefix))
|
||||
|
||||
|
||||
class InventoryBatchRowType(forms.types.ObjectType):
|
||||
model_class = model.InventoryBatchRow
|
||||
|
||||
def deserialize(self, node, cstruct):
|
||||
row = super(InventoryBatchRowType, self).deserialize(node, cstruct)
|
||||
if row and row.batch.executed:
|
||||
# TODO: this is a stopgap measure to fix an obvious bug, which exists when the
|
||||
# session is not provided by the view at runtime (i.e. when it was instead
|
||||
# being provided by the type instance, which was created upon app startup).
|
||||
@colander.deferred
|
||||
def valid_inventory_batch_row(node, kw):
|
||||
session = kw['session']
|
||||
def validate(node, value):
|
||||
row = session.query(model.InventoryBatchRow).get(value)
|
||||
if not row:
|
||||
raise colander.Invalid(node, "Batch row not found")
|
||||
if row.batch.executed:
|
||||
raise colander.Invalid(node, "Batch has already been executed")
|
||||
return row
|
||||
return row.uuid
|
||||
return validate
|
||||
|
||||
|
||||
class InventoryForm(colander.MappingSchema):
|
||||
|
||||
row = colander.SchemaNode(InventoryBatchRowType())
|
||||
row = colander.SchemaNode(colander.String(),
|
||||
validator=valid_inventory_batch_row)
|
||||
|
||||
cases = colander.SchemaNode(colander.Decimal(), missing=colander.null)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue