From d7e19865de0f9b8af63e48219f6e629eec5e5c62 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 8 Jun 2019 13:16:57 -0500 Subject: [PATCH] Update calculated PO totals for purchasing batch, when editing row --- tailbone/views/purchasing/batch.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tailbone/views/purchasing/batch.py b/tailbone/views/purchasing/batch.py index 39106e13..117598b5 100644 --- a/tailbone/views/purchasing/batch.py +++ b/tailbone/views/purchasing/batch.py @@ -896,14 +896,23 @@ class PurchasingBatchView(BatchMasterView): batch = row.batch # first undo any totals previously in effect for the row - if batch.mode == self.enum.PURCHASE_BATCH_MODE_ORDERING and row.po_total: - batch.po_total -= row.po_total + if batch.mode == self.enum.PURCHASE_BATCH_MODE_ORDERING and row.po_total_calculated: + batch.po_total_calculated -= row.po_total_calculated elif batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING and row.invoice_total: + # TODO: pretty sure this should update the `_calculated` value instead? + # TODO: also, should update the value again after the super() call batch.invoice_total -= row.invoice_total row = super(PurchasingBatchView, self).save_edit_row_form(form) + # TODO: is this needed? # self.handler.refresh_row(row) + + # now apply new totals based on current row quantity + if batch.mode == self.enum.PURCHASE_BATCH_MODE_ORDERING and row.po_unit_cost is not None: + row.po_total_calculated = row.po_unit_cost * self.handler.get_units_ordered(row) + batch.po_total_calculated += row.po_total_calculated + return row # def redirect_after_create_row(self, row):