Implements #13, but currently can be applied only

to transferred devices
This commit is contained in:
emmdim 2020-03-20 15:20:22 +01:00
parent dfb518068d
commit b70c229485

View file

@ -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)