From d60679adfd1bb4f75fcff3fbae9398c0093d682c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 27 Mar 2019 20:11:32 -0500 Subject: [PATCH] Don't allow deletion of some receiving data rows on mobile specifically, rows on a truck dump parent, which originated from a child batch (and therefore presumably, an invoice) --- tailbone/views/purchasing/receiving.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index ab76d112..fbe0ddbe 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -279,9 +279,29 @@ class ReceivingBatchView(PurchasingBatchView): def row_deletable(self, row): batch = row.batch - # can always delete rows from truck dump parent + # don't allow if master view has disabled that entirely + if not self.rows_deletable: + return False + + # can never delete rows for complete/executed batches + # TODO: not so sure about the 'complete' part though..? + if batch.executed or batch.complete: + return False + + # can "always" delete rows from truck dump parent... if batch.is_truck_dump_parent(): - return True + + # ...but only on desktop! + if not self.mobile: + return True + + # ...for mobile we only allow deletion of rows which did *not* come + # from a child batch, i.e. can delete ad-hoc rows only + # TODO: should have a better way to detect this; for now we rely on + # the fact that only rows from an invoice or similar would have + # order quantities + if not (row.cases_ordered or row.units_ordered): + return True # can always delete rows from truck dump child elif batch.is_truck_dump_child():