Implements #13, but currently can be applied only
to transferred devices
This commit is contained in:
parent
dfb518068d
commit
b70c229485
|
@ -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)
|
||||
|
||||
|
|
Reference in New Issue