diff --git a/ereuse_devicehub/resources/device/metrics.py b/ereuse_devicehub/resources/device/metrics.py index dcb1d3b8..bbc2f470 100644 --- a/ereuse_devicehub/resources/device/metrics.py +++ b/ereuse_devicehub/resources/device/metrics.py @@ -10,7 +10,7 @@ class MetricsMix: self.lifetime = 0 self.last_trade = None self.action_create_by = 'Receiver' - self.status_receiver = 'Use' + self.status_receiver = '' self.status_supplier = '' self.act = None self.end_users = 0 @@ -63,7 +63,7 @@ class Metrics(MetricsMix): """ Mark the status of one device. If exist one trade before this action, then modify the trade action - else, create one row new. + else, create one new row. """ if not self.last_trade: # If not exist one trade, the status is of the Receive @@ -71,20 +71,32 @@ class Metrics(MetricsMix): self.status_receiver = self.act.type self.status_supplier = '' row = self.get_template_row() + row['status_supplier_created'] = '' row['status_receiver_created'] = self.act.created self.rows.append(row) return - if self.last_trade['trade_supplier'] == self.act.rol_user.email: + # if self.last_trade['trade_supplier'] == self.act.rol_user.email: + # self.last_trade['status_supplier'] = self.act.type + # self.last_trade['status_supplier_created'] = self.act.created + # return + + # if self.last_trade['trade_receiver'] == self.act.rol_user.email: + # self.last_trade['status_receiver'] = self.act.type + # self.last_trade['status_receiver_created'] = self.act.created + # return + + if self.last_trade['trade_supplier'] == self.act.author.email: self.last_trade['status_supplier'] = self.act.type self.last_trade['status_supplier_created'] = self.act.created return - if self.last_trade['trade_receiver'] == self.act.rol_user.email: + if self.last_trade['trade_receiver'] == self.act.author.email: self.last_trade['status_receiver'] = self.act.type self.last_trade['status_receiver_created'] = self.act.created return + def get_snapshot(self): """ If there are one snapshot get the last lifetime for to do a calcul of time of use. @@ -153,8 +165,8 @@ class Metrics(MetricsMix): row['action_type'] = 'Trade' row['trade_supplier'] = self.act.user_from.email row['trade_receiver'] = self.act.user_to.email - row['self.status_receiver'] = self.status_receiver - row['self.status_supplier'] = self.status_supplier + row['status_receiver'] = '' + row['status_supplier'] = '' row['trade_confirmed'] = self.get_confirms() self.rows.append(row) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index e8db619d..191c988f 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -181,11 +181,11 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient): query=[('filter', {'type': ['Computer']})]) body1_lenovo = 'O48N2;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Trade;foo@foo.com;' - body1_lenovo += 'foo2@foo.com;Supplier;False;Refurbish;Use;' + body1_lenovo += 'foo2@foo.com;Supplier;False;Use;;' body2_lenovo = ';;0;0;Trade;0;0\n' body1_acer = 'J2MA2;laptop-acer-aohappy-lusea0d010038879a01601-00:26:c7:8e:cb:8c;;Trade;' - body1_acer += 'foo@foo.com;foo2@foo.com;Supplier;False;;Use;;;0;' + body1_acer += 'foo@foo.com;foo2@foo.com;Supplier;False;;;;;0;' body2_acer = ';;0;0;Trade;0;4692.0\n' # import pdb; pdb.set_trace() @@ -195,15 +195,22 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient): assert body2_acer in csv_str # User2 mark this device as Refurbish - action = {'type': ma.Refurbish.t, 'devices': [snap1['device']['id']]} + action = {'type': ma.Use.t, 'devices': [snap1['device']['id']]} action_use2, _ = user2.post(action, res=ma.Action) csv_str, _ = user.get(res=documents.DocumentDef.t, item='actions/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) - body2_lenovo = ';Refurbish;0;0;Trade;0;0\n' - body2_acer = ';Refurbish;0;0;Trade;0;4692.0\n' + body1_lenovo = 'O48N2;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Trade;foo@foo.com;' + body1_lenovo += 'foo2@foo.com;Supplier;False;Use;Use;' + body2_lenovo = ';;0;0;Trade;0;0\n' + body2_acer = ';;0;0;Trade;0;4692.0\n' + + assert body1_lenovo in csv_str + assert body2_lenovo in csv_str + assert body2_acer in csv_str + @pytest.mark.mvp