This commit is contained in:
Cayo Puigdefabregas 2022-07-18 10:56:36 +02:00
parent 83ea86705d
commit 26b322ba70
2 changed files with 5 additions and 4 deletions

View File

@ -335,6 +335,7 @@ class NewDeviceForm(FlaskForm):
screen = FloatField('Screen size', [validators.Optional()]) screen = FloatField('Screen size', [validators.Optional()])
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.objs = set()
self._obj = kwargs.pop('_obj', None) self._obj = kwargs.pop('_obj', None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if self._obj: if self._obj:
@ -545,6 +546,7 @@ class NewDeviceForm(FlaskForm):
type="New device", source='Web form', placeholder=device.placeholder type="New device", source='Web form', placeholder=device.placeholder
) )
db.session.add(placeholder_log) db.session.add(placeholder_log)
self.objs.add(device)
def reset_ids(self): def reset_ids(self):
if self.amount.data > 1: if self.amount.data > 1:

View File

@ -257,15 +257,14 @@ class DeviceCreateView(GenericMixin):
} }
) )
if form.validate_on_submit(): if form.validate_on_submit():
snapshot = form.save(commit=False) form.save(commit=False)
next_url = url_for('inventory.devicelist') next_url = url_for('inventory.devicelist')
if lot_id: if lot_id:
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
if snapshot and snapshot.device: if form.objs:
lots = self.context['lots'] lots = self.context['lots']
lot = lots.filter(Lot.id == lot_id).one() lot = lots.filter(Lot.id == lot_id).one()
lot.devices.add(snapshot.device) lot.devices = lot.devices.union(form.objs)
db.session.add(lot)
else: else:
messages.error('Sorry, the device could not be created') messages.error('Sorry, the device could not be created')