From e1348e3809c46621d3d06a3c484e226cc6479d8e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 31 May 2021 11:34:46 +0200 Subject: [PATCH] adding isTemporary lot --- ereuse_devicehub/resources/lot/models.py | 4 ++++ ereuse_devicehub/resources/lot/schemas.py | 1 + ereuse_devicehub/resources/lot/views.py | 1 + 3 files changed, 6 insertions(+) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index f8a9066b..9699c969 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -99,6 +99,10 @@ class Lot(Thing): def descendants(self): return self.descendantsq(self.id) + @property + def is_temporary(self): + return False if self.trade else True + @classmethod def descendantsq(cls, id): _id = UUIDLtree.convert(id) diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index 72e49efe..e92de60b 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -26,3 +26,4 @@ class Lot(Thing): transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) receiver_address = SanitizedStr(validate=f.validate.Length(max=42)) deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True) + is_temporary = f.Boolean(missing=True, data_key='isTemporary') diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 295f63e1..744297b9 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -32,6 +32,7 @@ class LotView(View): def post(self): l = request.get_json() + l.pop('is_temporary', '') lot = Lot(**l) db.session.add(lot) db.session().final_flush()