fix add amount placeholder

This commit is contained in:
Cayo Puigdefabregas 2022-06-29 18:07:57 +02:00
parent 3dae7e3a58
commit b22ea880dd
2 changed files with 25 additions and 18 deletions

View file

@ -424,27 +424,11 @@ class NewDeviceForm(FlaskForm):
if self.serial_number.data:
self.serial_number.data = self.serial_number.data.lower()
if not self.phid.data:
_hid = Placeholder.query.order_by(Placeholder.id.desc()).first()
if _hid:
_hid = str(_hid.id + 1)
else:
_hid = '1'
self.phid.data = _hid.lower()
self.phid.data = self.phid.data.lower()
if self.amount.data > 1:
self.phid.data = None
self.id_device_supplier.data = None
self.serial_number.data = None
self.sku.data = None
self.imei.data = None
self.meid.data = None
return True
def save(self, commit=True):
for n in range(self.amount.data):
self.reset_ids()
self.create_device()
if commit:
@ -500,6 +484,8 @@ class NewDeviceForm(FlaskForm):
snapshot_json['device'].meid = self.meid.data
snapshot_json['device'].placeholder = self.get_placeholder()
snapshot_json['device'].hid = self.phid.data
snapshot = upload_form.build(snapshot_json)
move_json(self.tmp_snapshots, path_snapshot, g.user.email)
@ -509,6 +495,27 @@ class NewDeviceForm(FlaskForm):
return snapshot
def get_phid(self):
_hid = self.phid.data
if not _hid:
_hid = Placeholder.query.order_by(Placeholder.id.desc()).first()
if _hid:
_hid = str(_hid.id + 1)
else:
_hid = '1'
self.phid.data = _hid.lower()
def reset_ids(self):
if self.amount.data > 1:
self.phid.data = None
self.id_device_supplier.data = None
self.serial_number.data = None
self.sku.data = None
self.imei.data = None
self.meid.data = None
self.get_phid()
def get_placeholder(self):
self.placeholder = Placeholder(
**{

View file

@ -627,7 +627,7 @@ def test_add_with_ammount_laptops(user3: UserClientFlask):
assert 'Device "Laptop" created successfully!' in body
for dev in Device.query.all():
assert dev.type == 'Laptop'
assert dev.placeholder.id_device_supplier == "b2"
assert dev.placeholder.id_device_supplier is None
assert dev.hid in [str(x) for x in range(1, num + 1)]
assert Device.query.count() == num