From f8be48d5241e9ac8eef42ed1a2bfd3052b72c1d6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 5 Nov 2021 13:10:23 +0100 Subject: [PATCH] fixing schema --- ereuse_devicehub/resources/action/schemas.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index f6740c38..1836568d 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -439,7 +439,7 @@ class ActionStatus(Action): @pre_load def put_devices(self, data: dict): - if not 'devices' in data.keys(): + if 'devices' not in data.keys(): data['devices'] = [] @post_load @@ -447,10 +447,16 @@ class ActionStatus(Action): for dev in data['devices']: if dev.trading in [None, 'Revoke', 'ConfirmRevoke']: return data - trade = [ac for ac in dev.actions if ac.t == 'Trade'][-1] + + trades = [ac for ac in dev.actions if ac.t == 'Trade'] + if not trades: + return data + + trade = trades[-1] + if trade.user_to != g.user: data['rol_user'] = trade.user_to - data['trade'] = trade + data['trade'] = trade class Recycling(ActionStatus):