From d0688cc75172306f0e0f036a6b43a04c68482db3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 13 Mar 2023 12:24:57 +0100 Subject: [PATCH] fix with last lot incoming --- ereuse_devicehub/inventory/views.py | 22 ++++++++----------- ereuse_devicehub/resources/device/models.py | 20 +++++++++++------ .../templates/inventory/erasure.html | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 5ebabaa5..b03cd345 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -1071,22 +1071,18 @@ class ExportsView(View): if not erasures or customer_details: return my_data, customer_details - init = erasures[0].device.get_set_lots() - for e in erasures: - init = init.intersection(e.device.get_set_lots()) + lots = {erasures[0].device.get_last_incoming_lot()} + for e in erasures[1:]: + lots.add(e.device.get_last_incoming_lot()) - if not len(init): + if len(lots) != 1: return my_data, customer_details - lots = sorted(list(init), key=lambda x: x.created) - lots.reverse() - for lot in lots: - try: - customer_details = lot.transfer.customer_details - if customer_details: - return my_data, customer_details - except Exception: - continue + lot = lots.pop() + try: + customer_details = lot.transfer.customer_details + except Exception: + pass return my_data, customer_details diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 3bb98ffb..a0ba0f20 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1021,18 +1021,24 @@ class Device(Thing): return - def get_set_lots(self): + def get_last_incoming_lot(self): + lots = list(self.lots) if hasattr(self, "orphan") and self.orphan: + lots = list(self.lots) if self.binding: - return set(self.binding.device.lots) - return set(self.lots) + lots = list(self.binding.device.lots) - if hasattr(self, "parent") and self.parent: + elif hasattr(self, "parent") and self.parent: + lots = list(self.parent.lots) if self.parent.binding: - return set(self.parent.binding.device.lots) - return set(self.parent.lots) + lots = list(self.parent.binding.device.lots) - return set(self.lots) + lots = sorted(lots, key=lambda x: x.created) + lots.reverse() + for lot in lots: + if lot.is_incoming: + return lot + return None def __lt__(self, other): return self.id < other.id diff --git a/ereuse_devicehub/templates/inventory/erasure.html b/ereuse_devicehub/templates/inventory/erasure.html index a5eb0039..06ad6943 100644 --- a/ereuse_devicehub/templates/inventory/erasure.html +++ b/ereuse_devicehub/templates/inventory/erasure.html @@ -161,7 +161,7 @@ {% if erasure_hosts %} - SNs; of sanitization server {{ erasure_hosts|length }}: + SNs of sanitization server: {% for e in erasure_hosts %}