Try to be smart about how we update cases/units for receiving batch row

e.g. if you receive 1 CS (@ 12/CS) and then subtract 4 EA then you should wind
up with 8 EA for the row
This commit is contained in:
Lance Edgar 2018-07-10 13:36:28 -05:00
parent 2983ff7ba0
commit 147c65afe6

View file

@ -699,12 +699,15 @@ class ReceivingBatchView(PurchasingBatchView):
mode = update_form.validated['mode'] mode = update_form.validated['mode']
cases = update_form.validated['cases'] cases = update_form.validated['cases']
units = update_form.validated['units'] units = update_form.validated['units']
if cases:
setattr(row, 'cases_{}'.format(mode), # try to be smart about how we update cases and units for row
(getattr(row, 'cases_{}'.format(mode)) or 0) + cases) existing = getattr(self.handler, 'get_units_{}'.format(mode))(row)
if units: proposed = existing + self.handler.get_units(cases, units, row.case_quantity)
setattr(row, 'units_{}'.format(mode), new_cases, new_units = self.handler.calc_best_fit(proposed, row.case_quantity)
(getattr(row, 'units_{}'.format(mode)) or 0) + units) if getattr(row, 'cases_{}'.format(mode)) != new_cases:
setattr(row, 'cases_{}'.format(mode), new_cases)
if getattr(row, 'units_{}'.format(mode)) != new_units:
setattr(row, 'units_{}'.format(mode), new_units)
# if mode in ('damaged', 'expired', 'mispick'): # if mode in ('damaged', 'expired', 'mispick'):
if mode in ('damaged', 'expired'): if mode in ('damaged', 'expired'):