Improve how cases/units, uom are handled for mobile receiving

last-used uom should be more or less sticky, etc.
This commit is contained in:
Lance Edgar 2018-07-10 14:24:12 -05:00
parent 147c65afe6
commit 477a34cfa7
3 changed files with 44 additions and 10 deletions

View file

@ -68,9 +68,11 @@ $(document).on('click', 'form.receiving-update .receiving-actions button', funct
}); });
// quick-receive (1 CS)
$(document).on('click', 'form.receiving-update .receive-one-case', function() { $(document).on('click', 'form.receiving-update .receive-one-case', function() {
var form = $(this).parents('form:first'); var form = $(this).parents('form:first');
form.find('[name="mode"]').val('received'); form.find('[name="mode"]').val('received');
form.find('[name="cases"]').val('1'); form.find('[name="cases"]').val('1');
form.find('input[name="quick_receive"]').val('true');
form.submit(); form.submit();
}); });

View file

@ -6,14 +6,6 @@
<%def name="page_title()">${h.link_to("Receiving", url('mobile.receiving'))} &raquo; ${h.link_to(batch.id_str, url('mobile.receiving.view', uuid=batch.uuid))} &raquo; ${row.upc.pretty()}</%def> <%def name="page_title()">${h.link_to("Receiving", url('mobile.receiving'))} &raquo; ${h.link_to(batch.id_str, url('mobile.receiving.view', uuid=batch.uuid))} &raquo; ${row.upc.pretty()}</%def>
<%
unit_uom = 'LB' if row.product and row.product.weighed else 'EA'
uom = 'CS'
if row.units_ordered and not row.cases_ordered:
uom = 'EA'
%>
<div class="ui-grid-a"> <div class="ui-grid-a">
<div class="ui-block-a"> <div class="ui-block-a">
@ -102,6 +94,8 @@
</tbody> </tbody>
</table> </table>
${h.hidden('quick_receive', value='false')}
${h.hidden('delete_row', value='false')} ${h.hidden('delete_row', value='false')}
% if request.has_perm('{}.delete_row'.format(permission_prefix)): % if request.has_perm('{}.delete_row'.format(permission_prefix)):
<button type="button" id="delete-receiving-row">Delete this Row</button> <button type="button" id="delete-receiving-row">Delete this Row</button>

View file

@ -109,6 +109,8 @@ class ReceivingBatchView(PurchasingBatchView):
allow_from_scratch = True allow_from_scratch = True
allow_truck_dump = False allow_truck_dump = False
default_uom_is_case = True
labels = { labels = {
'truck_dump_batch': "Truck Dump Parent", 'truck_dump_batch': "Truck Dump Parent",
'invoice_parser_key': "Invoice Parser", 'invoice_parser_key': "Invoice Parser",
@ -704,10 +706,18 @@ class ReceivingBatchView(PurchasingBatchView):
existing = getattr(self.handler, 'get_units_{}'.format(mode))(row) existing = getattr(self.handler, 'get_units_{}'.format(mode))(row)
proposed = existing + self.handler.get_units(cases, units, row.case_quantity) proposed = existing + self.handler.get_units(cases, units, row.case_quantity)
new_cases, new_units = self.handler.calc_best_fit(proposed, row.case_quantity) new_cases, new_units = self.handler.calc_best_fit(proposed, row.case_quantity)
if getattr(row, 'cases_{}'.format(mode)) != new_cases:
old_cases = getattr(row, 'cases_{}'.format(mode))
if new_cases and old_cases != new_cases:
setattr(row, 'cases_{}'.format(mode), new_cases) setattr(row, 'cases_{}'.format(mode), new_cases)
if getattr(row, 'units_{}'.format(mode)) != new_units: elif old_cases and not new_cases:
setattr(row, 'cases_{}'.format(mode), None)
old_units = getattr(row, 'units_{}'.format(mode))
if new_units and old_units != new_units:
setattr(row, 'units_{}'.format(mode), new_units) setattr(row, 'units_{}'.format(mode), new_units)
elif old_units and not new_units:
setattr(row, 'units_{}'.format(mode), None)
# if mode in ('damaged', 'expired', 'mispick'): # if mode in ('damaged', 'expired', 'mispick'):
if mode in ('damaged', 'expired'): if mode in ('damaged', 'expired'):
@ -722,8 +732,34 @@ class ReceivingBatchView(PurchasingBatchView):
batch.invoice_total -= row.invoice_total batch.invoice_total -= row.invoice_total
self.handler.refresh_row(row) self.handler.refresh_row(row)
# keep track of last-used uom, although we just track
# whether or not it was 'CS' since the unit_uom can vary
sticky_case = None
if not update_form.validated['quick_receive']:
if cases and not units:
sticky_case = True
elif units and not cases:
sticky_case = False
if sticky_case is not None:
self.request.session['tailbone.mobile.receiving.sticky_uom_is_case'] = sticky_case
return self.redirect(self.get_action_url('view', batch, mobile=True)) return self.redirect(self.get_action_url('view', batch, mobile=True))
# unit_uom can vary by product
context['unit_uom'] = 'LB' if row.product and row.product.weighed else 'EA'
# effective uom can vary in a few ways...the basic default is 'CS' if
# self.default_uom_is_case is true, otherwise whatever unit_uom is.
sticky_case = self.request.session.get('tailbone.mobile.receiving.sticky_uom_is_case')
if sticky_case is None:
context['uom'] = 'CS' if self.default_uom_is_case else context['unit_uom']
elif sticky_case:
context['uom'] = 'CS'
else:
context['uom'] = context['unit_uom']
if context['uom'] == 'CS' and row.units_ordered and not row.cases_ordered:
context['uom'] = context['unit_uom']
if not row.cases_ordered and not row.units_ordered and not batch.truck_dump: if not row.cases_ordered and not row.units_ordered and not batch.truck_dump:
self.request.session.flash("This item was NOT on the original purchase order.", 'receiving-warning') self.request.session.flash("This item was NOT on the original purchase order.", 'receiving-warning')
return self.render_to_response('view_row', context, mobile=True) return self.render_to_response('view_row', context, mobile=True)
@ -849,6 +885,8 @@ class MobileReceivingForm(colander.MappingSchema):
widget=dfwidget.TextInputWidget(), widget=dfwidget.TextInputWidget(),
missing=colander.null) missing=colander.null)
quick_receive = colander.SchemaNode(colander.Boolean())
delete_row = colander.SchemaNode(colander.Boolean()) delete_row = colander.SchemaNode(colander.Boolean())