diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index 0b0cb35a..75834c09 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -16,6 +16,7 @@ from ereuse_devicehub.db import db from ereuse_devicehub.query import things_response from ereuse_devicehub.resources.deliverynote.models import Deliverynote from ereuse_devicehub.resources.lot.models import Lot +from ereuse_devicehub.resources.device.models import Computer class DeliverynoteView(View): @@ -41,8 +42,18 @@ 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)] for key, value in d.items(): + # Transalate ethereum_address attribute + devKey = key + if key == 'ethereum_address': + devKey = 'deliverynote_address' setattr(dlvnote, key, value) + if devKey in device_fields: + for dev in computers: + setattr(dev, devKey, value) + db.session.commit() return Response(status=204)