Remove the "add vs. subtract" mode for desktop inventory workflow form

hopefully we can always assume the "mode" based on other things
This commit is contained in:
Lance Edgar 2018-03-06 16:26:53 -06:00
parent 802f4bfd6b
commit 6ec0ddb94e
2 changed files with 9 additions and 39 deletions

View file

@ -130,25 +130,11 @@
return false;
});
$('#add').click(function() {
if (! assert_quantity()) {
return;
}
$(this).button('disable').button('option', 'label', "Working...");
$('#mode').val('add');
$('#inventory-form').submit();
});
$('#subtract').click(function() {
if (! assert_quantity()) {
return;
}
$(this).button('disable').button('option', 'label', "Working...");
$('#mode').val('subtract');
$('#inventory-form').submit();
});
$('#inventory-form').submit(function() {
if (! assert_quantity()) {
return false;
}
disable_submit_button(this);
$(this).mask("Working...");
});
@ -200,7 +186,6 @@
<div class="form-wrapper">
${h.form(form.action_url, id='inventory-form')}
${h.csrf_token(request)}
${h.hidden('mode')}
<div class="field-wrapper">
<label for="upc">Product UPC</label>
@ -250,8 +235,7 @@
</div>
<div class="buttons">
<button type="button" id="add">Add</button>
<button type="button" id="subtract">Subtract</button>
${h.submit('submit', "Submit")}
</div>
${h.end_form()}

View file

@ -282,7 +282,6 @@ class InventoryBatchView(BatchMasterView):
form = forms.Form(schema=DesktopForm(), request=self.request)
if form.validate(newstyle=True):
mode = form.validated['mode']
product = self.Session.merge(form.validated['product'])
row = model.InventoryBatchRow()
row.product = product
@ -291,23 +290,14 @@ class InventoryBatchView(BatchMasterView):
row.description = form.validated['description']
row.size = form.validated['size']
row.case_quantity = form.validated['case_quantity']
cases = form.validated['cases']
units = form.validated['units']
if mode == 'add':
row.cases = cases
row.units = units
else:
assert mode == 'subtract'
row.cases = (0 - cases) if cases else None
row.units = (0 - units) if units else None
row.cases = form.validated['cases']
row.units = form.validated['units']
self.handler.add_row(batch, row)
description = make_full_description(form.validated['brand_name'],
form.validated['description'],
form.validated['size'])
self.request.session.flash("({}) {} cases, {} units: {} {}".format(
form.validated['mode'], form.validated['cases'] or 0, form.validated['units'] or 0,
self.request.session.flash("{} cases, {} units: {} {}".format(
form.validated['cases'] or 0, form.validated['units'] or 0,
form.validated['upc'].pretty(), description))
return self.redirect(self.request.current_route_url())
@ -610,10 +600,6 @@ class InventoryForm(colander.MappingSchema):
class DesktopForm(colander.Schema):
mode = colander.SchemaNode(colander.String(),
validator=colander.OneOf(['add',
'subtract']))
product = colander.SchemaNode(forms.types.ProductType())
upc = colander.SchemaNode(forms.types.GPCType())