From 477a34cfa75a4a373635da9ac83011d7d872f7f6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 10 Jul 2018 14:24:12 -0500 Subject: [PATCH] Improve how cases/units, uom are handled for mobile receiving last-used uom should be more or less sticky, etc. --- .../static/js/tailbone.mobile.receiving.js | 2 + .../templates/mobile/receiving/view_row.mako | 10 +---- tailbone/views/purchasing/receiving.py | 42 ++++++++++++++++++- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/tailbone/static/js/tailbone.mobile.receiving.js b/tailbone/static/js/tailbone.mobile.receiving.js index 3786d29f..2d5f9ab6 100644 --- a/tailbone/static/js/tailbone.mobile.receiving.js +++ b/tailbone/static/js/tailbone.mobile.receiving.js @@ -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() { var form = $(this).parents('form:first'); form.find('[name="mode"]').val('received'); form.find('[name="cases"]').val('1'); + form.find('input[name="quick_receive"]').val('true'); form.submit(); }); diff --git a/tailbone/templates/mobile/receiving/view_row.mako b/tailbone/templates/mobile/receiving/view_row.mako index 74b6faac..966b939b 100644 --- a/tailbone/templates/mobile/receiving/view_row.mako +++ b/tailbone/templates/mobile/receiving/view_row.mako @@ -6,14 +6,6 @@ <%def name="page_title()">${h.link_to("Receiving", url('mobile.receiving'))} » ${h.link_to(batch.id_str, url('mobile.receiving.view', uuid=batch.uuid))} » ${row.upc.pretty()} -<% - 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' -%> -
@@ -102,6 +94,8 @@ + ${h.hidden('quick_receive', value='false')} + ${h.hidden('delete_row', value='false')} % if request.has_perm('{}.delete_row'.format(permission_prefix)): diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 1a9f8184..9316c2a9 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -109,6 +109,8 @@ class ReceivingBatchView(PurchasingBatchView): allow_from_scratch = True allow_truck_dump = False + default_uom_is_case = True + labels = { 'truck_dump_batch': "Truck Dump Parent", 'invoice_parser_key': "Invoice Parser", @@ -704,10 +706,18 @@ class ReceivingBatchView(PurchasingBatchView): existing = getattr(self.handler, 'get_units_{}'.format(mode))(row) proposed = existing + self.handler.get_units(cases, units, 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) - 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) + elif old_units and not new_units: + setattr(row, 'units_{}'.format(mode), None) # if mode in ('damaged', 'expired', 'mispick'): if mode in ('damaged', 'expired'): @@ -722,8 +732,34 @@ class ReceivingBatchView(PurchasingBatchView): batch.invoice_total -= row.invoice_total 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)) + # 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: 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) @@ -849,6 +885,8 @@ class MobileReceivingForm(colander.MappingSchema): widget=dfwidget.TextInputWidget(), missing=colander.null) + quick_receive = colander.SchemaNode(colander.Boolean()) + delete_row = colander.SchemaNode(colander.Boolean())