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'):