From 16ab8b6ffa5c392f1ecaad84698c425e2645973b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 10 Jul 2018 16:43:21 -0500 Subject: [PATCH] Stop trying to be smart about "best fit" cases/units for receiving i.e. just record amounts as provided by the user. sometimes it is necessary for the user to avoid "cases" altogether if they detect the "case quantity" to be incorrect --- tailbone/views/purchasing/receiving.py | 27 +++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 9316c2a9..711daac1 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -702,22 +702,17 @@ class ReceivingBatchView(PurchasingBatchView): cases = update_form.validated['cases'] units = update_form.validated['units'] - # try to be smart about how we update cases and units for row - 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) - - old_cases = getattr(row, 'cases_{}'.format(mode)) - if new_cases and old_cases != new_cases: - setattr(row, 'cases_{}'.format(mode), new_cases) - 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) + # add values as-is to existing case/unit amounts. note + # that this can sometimes give us negative values! e.g. if + # user scans 1 CS and then subtracts 2 EA, then we would + # have 1 / -2 for our counts. but we consider that to be + # expected, and other logic must allow for the possibility + if cases: + setattr(row, 'cases_{}'.format(mode), + (getattr(row, 'cases_{}'.format(mode)) or 0) + cases) + if units: + setattr(row, 'units_{}'.format(mode), + (getattr(row, 'units_{}'.format(mode)) or 0) + units) # if mode in ('damaged', 'expired', 'mispick'): if mode in ('damaged', 'expired'):