fix bug when add or delete one device of a lot. For fix this we use the pattern of flask doing the commit in the view
This commit is contained in:
parent
5df74d7742
commit
54a938071b
|
@ -72,13 +72,11 @@ class LotDeviceForm(FlaskForm):
|
|||
if self._devices:
|
||||
self._lot.devices.update(self._devices)
|
||||
db.session.add(self._lot)
|
||||
db.session.commit()
|
||||
|
||||
def remove(self):
|
||||
if self._devices:
|
||||
self._lot.devices.difference_update(self._devices)
|
||||
db.session.add(self._lot)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
class LotForm(FlaskForm):
|
||||
|
|
|
@ -32,6 +32,7 @@ from ereuse_devicehub.resources.documents.device_row import ActionRow, DeviceRow
|
|||
from ereuse_devicehub.resources.hash_reports import insert_hash
|
||||
from ereuse_devicehub.resources.lot.models import Lot
|
||||
from ereuse_devicehub.resources.tag.model import Tag
|
||||
from ereuse_devicehub.db import db
|
||||
|
||||
# TODO(@slamora): rename base 'inventory.devices' --> 'inventory'
|
||||
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
||||
|
@ -142,6 +143,7 @@ class LotDeviceAddView(View):
|
|||
messages.success(
|
||||
'Add devices to lot "{}" successfully!'.format(form._lot.name)
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
messages.error('Error adding devices to lot!')
|
||||
|
||||
|
@ -161,6 +163,7 @@ class LotDeviceDeleteView(View):
|
|||
messages.success(
|
||||
'Remove devices from lot "{}" successfully!'.format(form._lot.name)
|
||||
)
|
||||
db.session.commit()
|
||||
else:
|
||||
messages.error('Error removing devices from lot!')
|
||||
|
||||
|
|
Reference in New Issue