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:
Cayo Puigdefabregas 2022-03-07 11:31:38 +01:00
parent 5df74d7742
commit 54a938071b
2 changed files with 3 additions and 2 deletions

View file

@ -72,13 +72,11 @@ class LotDeviceForm(FlaskForm):
if self._devices: if self._devices:
self._lot.devices.update(self._devices) self._lot.devices.update(self._devices)
db.session.add(self._lot) db.session.add(self._lot)
db.session.commit()
def remove(self): def remove(self):
if self._devices: if self._devices:
self._lot.devices.difference_update(self._devices) self._lot.devices.difference_update(self._devices)
db.session.add(self._lot) db.session.add(self._lot)
db.session.commit()
class LotForm(FlaskForm): class LotForm(FlaskForm):

View file

@ -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.hash_reports import insert_hash
from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.db import db
# TODO(@slamora): rename base 'inventory.devices' --> 'inventory' # TODO(@slamora): rename base 'inventory.devices' --> 'inventory'
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory') devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
@ -142,6 +143,7 @@ class LotDeviceAddView(View):
messages.success( messages.success(
'Add devices to lot "{}" successfully!'.format(form._lot.name) 'Add devices to lot "{}" successfully!'.format(form._lot.name)
) )
db.session.commit()
else: else:
messages.error('Error adding devices to lot!') messages.error('Error adding devices to lot!')
@ -161,6 +163,7 @@ class LotDeviceDeleteView(View):
messages.success( messages.success(
'Remove devices from lot "{}" successfully!'.format(form._lot.name) 'Remove devices from lot "{}" successfully!'.format(form._lot.name)
) )
db.session.commit()
else: else:
messages.error('Error removing devices from lot!') messages.error('Error removing devices from lot!')