From 5c56275228b783dbb6a10ed5c74d1dc6d41640c2 Mon Sep 17 00:00:00 2001 From: nad Date: Tue, 25 Aug 2020 15:31:15 +0200 Subject: [PATCH] Changing devices transfer_states on delivery note PATCH --- .../resources/deliverynote/views.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index b22e999e..61545b5a 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -6,6 +6,7 @@ from teal.resource import View from ereuse_devicehub.db import db from ereuse_devicehub.resources.deliverynote.models import Deliverynote +from ereuse_devicehub.resources.device.models import Computer from ereuse_devicehub.resources.lot.models import Lot @@ -32,17 +33,17 @@ class DeliverynoteView(View): 'ethereum_address'), partial=True) d = request.get_json(schema=patch_schema) dlvnote = Deliverynote.query.filter_by(id=id).one() - # device_fields = ['transfer_state', 'deliverynote_address'] - # computers = [x for x in dlvnote.transferred_devices if isinstance(x, Computer)] + device_fields = ['transfer_state', 'deliverynote_address'] + computers = [x for x in dlvnote.transferred_devices if isinstance(x, Computer)] for key, value in d.items(): setattr(dlvnote, key, value) # Transalate ethereum_address attribute - # devKey = key - # if key == 'ethereum_address': - # devKey = 'deliverynote_address' - # if devKey in device_fields: - # for dev in computers: - # setattr(dev, devKey, value) + devKey = key + if key == 'ethereum_address': + devKey = 'deliverynote_address' + if devKey in device_fields: + for dev in computers: + setattr(dev, devKey, value) db.session.commit() return Response(status=204)