From 1b5f6412f002370ab2abd2c0c25ce1fd04c40509 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 May 2022 12:17:14 +0200 Subject: [PATCH] #3397 add columns of status in the devices list --- ereuse_devicehub/resources/device/models.py | 29 +++++++++++++++++++ ereuse_devicehub/resources/device/states.py | 13 +++++++-- .../templates/inventory/device_list.html | 6 +++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index c08ec3b8..70ce4e3d 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -332,6 +332,35 @@ class Device(Thing): with suppress(LookupError, ValueError): return self.last_action_of(*states.Trading.actions()) + @property + def allocated_status(self): + """Show the actual status of device for this owner. + The status depend of one of this 4 actions: + - Use + - Refurbish + - Recycling + - Management + """ + from ereuse_devicehub.resources.device import states + + with suppress(LookupError, ValueError): + return self.last_action_of(*states.Usage.actions()) + + @property + def physical_status(self): + """Show the actual status of device for this owner. + The status depend of one of this 4 actions: + - Use + - Refurbish + - Recycling + - Management + """ + from ereuse_devicehub.resources.device import states + + with suppress(LookupError, ValueError): + # import pdb; pdb.set_trace() + return self.last_action_of(*states.Physical.actions()) + @property def status(self): """Show the actual status of device for this owner. diff --git a/ereuse_devicehub/resources/device/states.py b/ereuse_devicehub/resources/device/states.py index 3cfefe4b..99603f2a 100644 --- a/ereuse_devicehub/resources/device/states.py +++ b/ereuse_devicehub/resources/device/states.py @@ -33,6 +33,7 @@ class Trading(State): :cvar ProductDisposed: The device has been removed from the facility. It does not mean end-of-life. """ + Reserved = e.Reserve Trade = e.Trade Confirm = e.Confirm @@ -55,12 +56,15 @@ class Physical(State): :cvar Preparing: The device is going to be or being prepared. :cvar Prepared: The device has been prepared. :cvar Ready: The device is in working conditions. + :cvar DataWipe: Do DataWipe over the device. """ + ToBeRepaired = e.ToRepair Repaired = e.Repair Preparing = e.ToPrepare Prepared = e.Prepare Ready = e.Ready + DataWipe = e.DataWipe class Traking(State): @@ -68,22 +72,24 @@ class Traking(State): :cvar Receive: The device changes hands """ + # Receive = e.Receive pass - + class Usage(State): """Usage states. :cvar Allocate: The device is allocate in other Agent (organization, person ...) :cvar Deallocate: The device is deallocate and return to the owner - :cvar InUse: The device is being reported to be in active use. + :cvar InUse: The device is being reported to be in active use. """ + Allocate = e.Allocate Deallocate = e.Deallocate InUse = e.Live - + class Status(State): """Define status of device for one user. :cvar Use: The device is in use for one final user. @@ -91,6 +97,7 @@ class Status(State): :cvar Recycling: The device is sended to recycling. :cvar Management: The device is owned by one Manager. """ + Use = e.Use Refurbish = e.Refurbish Recycling = e.Recycling diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 0f022fd6..5d3946c4 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -334,7 +334,9 @@ Title DHID Unique Identifiers - Status + Lifecycle Status + Allocated Status + Physical Status Update @@ -370,6 +372,8 @@ {% endfor %} {% if dev.status %}{{ dev.status.type }}{% endif %} + {% if dev.allocated_status %}{{ dev.allocated_status.type }}{% endif %} + {% if dev.physical_status %}{{ dev.physical_status.type }}{% endif %} {{ dev.updated.strftime('%H:%M %d-%m-%Y') }} {% endfor %}