Add way to prevent "case" entries for inventory adjustment batch

This commit is contained in:
Lance Edgar 2018-05-23 14:48:17 -05:00
parent 57c2a7981f
commit 54bfafdbfe
4 changed files with 80 additions and 30 deletions

View file

@ -9,14 +9,20 @@
<script type="text/javascript">
function assert_quantity() {
% if allow_cases:
if ($('#cases').val() && parseFloat($('#cases').val())) {
return true;
}
% endif
if ($('#units').val() && parseFloat($('#units').val())) {
return true;
}
alert("Please provide case and/or unit quantity");
% if allow_cases:
$('#cases').select().focus();
% else:
$('#units').select().focus();
% endif
return false;
}
@ -24,7 +30,9 @@
$('#product-info p').text(msg);
$('#product-info img').hide();
$('#upc').focus().select();
% if allow_cases:
$('.field-wrapper.cases input').prop('disabled', true);
% endif
$('.field-wrapper.units input').prop('disabled', true);
$('.buttons button').button('disable');
}
@ -65,7 +73,9 @@
$('#product-info .warning').hide();
$('.product-fields').hide();
// $('.receiving-fields').hide();
% if allow_cases:
$('.field-wrapper.cases input').prop('disabled', true);
% endif
$('.field-wrapper.units input').prop('disabled', true);
$('.buttons button').button('disable');
return true;
@ -102,13 +112,19 @@
$('.product-fields').show();
}
$('#product-info .warning.notordered').show();
% if allow_cases:
$('.field-wrapper.cases input').prop('disabled', false);
% endif
$('.field-wrapper.units input').prop('disabled', false);
$('.buttons button').button('enable');
if (data.product.type2) {
$('#units').focus().select();
} else {
% if allow_cases:
$('#cases').focus().select();
% else:
$('#units').focus().select();
% endif
}
// TODO: this is maybe useful if "new products" may be added via inventory batch
@ -147,7 +163,9 @@
});
$('#upc').focus();
% if allow_cases:
$('.field-wrapper.cases input').prop('disabled', true);
% endif
$('.field-wrapper.units input').prop('disabled', true);
$('.buttons button').button('disable');
@ -232,10 +250,12 @@
</div>
<div class="field-wrapper cases">
<label for="cases">Cases</label>
<div class="field">${h.text('cases', autocomplete='off')}</div>
</div>
% if allow_cases:
<div class="field-wrapper cases">
<label for="cases">Cases</label>
<div class="field">${h.text('cases', autocomplete='off')}</div>
</div>
% endif
<div class="field-wrapper units">
<label for="units">Units</label>

View file

@ -3,22 +3,19 @@
<%namespace file="/mobile/keypad.mako" import="keypad" />
## TODO: this is broken for actual page (header) title
<%def name="title()">${h.link_to("Inventory", url('mobile.batch.inventory'))} &raquo; ${h.link_to(instance.batch.id_str, url('mobile.batch.inventory.view', uuid=instance.batch_uuid))} &raquo; ${row.upc.pretty()}</%def>
<%def name="title()">${h.link_to("Inventory", url('mobile.batch.inventory'))} &raquo; ${h.link_to(batch.id_str, url('mobile.batch.inventory.view', uuid=batch.uuid))} &raquo; ${row.upc.pretty()}</%def>
<%
unit_uom = 'LB' if row.product and row.product.weighed else 'EA'
if row.cases:
if row.cases and allow_cases:
uom = 'CS'
elif row.units:
if row.product and row.product.weighed:
uom = 'LB'
else:
uom = 'EA'
elif row.case_quantity:
uom = unit_uom
elif row.case_quantity and allow_cases:
uom = 'CS'
else:
uom = 'EA'
uom = unit_uom
%>
<div class="ui-grid-a">
@ -46,20 +43,22 @@
${uom}
</p>
% if not row.batch.executed and not row.batch.complete:
% if not batch.executed and not batch.complete:
${h.form(request.current_route_url())}
${h.csrf_token(request)}
${h.hidden('row', value=row.uuid)}
% if allow_cases:
${h.hidden('cases')}
% endif
${h.hidden('units')}
${keypad(unit_uom, uom, quantity=row.cases or row.units or 1)}
${keypad(unit_uom, uom, quantity=(row.cases or row.units or 1) if allow_cases else (row.units or 1), allow_cases=allow_cases)}
<fieldset data-role="controlgroup" data-type="horizontal" class="inventory-actions">
<button type="button" class="ui-btn-inline ui-corner-all save">Save</button>
<button type="button" class="ui-btn-inline ui-corner-all delete" disabled="disabled">Delete</button>
${h.link_to("Cancel", url('mobile.batch.inventory.view', uuid=row.batch.uuid), class_='ui-btn ui-btn-inline ui-corner-all')}
${h.link_to("Cancel", url('mobile.batch.inventory.view', uuid=batch.uuid), class_='ui-btn ui-btn-inline ui-corner-all')}
</fieldset>
${h.end_form()}

View file

@ -1,6 +1,6 @@
## -*- coding: utf-8; -*-
<%def name="keypad(unit_uom, selected_uom, quantity=1)">
<%def name="keypad(unit_uom, selected_uom, quantity=1, allow_cases=True)">
<div class="quantity-keypad-thingy" data-changed="false">
<table>
@ -31,7 +31,9 @@
<fieldset data-role="controlgroup" data-type="horizontal">
<button type="button" class="ui-btn-active keypad-quantity">${h.pretty_quantity(quantity or 1)}</button>
<button type="button" disabled="disabled">&nbsp;</button>
% if allow_cases:
${h.radio('keypad-uom', value='CS', checked=selected_uom == 'CS', label="CS")}
% endif
${h.radio('keypad-uom', value=unit_uom, checked=selected_uom == unit_uom, label=unit_uom)}
</fieldset>

View file

@ -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)