fix add amount placeholder
This commit is contained in:
parent
3dae7e3a58
commit
b22ea880dd
|
@ -424,27 +424,11 @@ class NewDeviceForm(FlaskForm):
|
||||||
if self.serial_number.data:
|
if self.serial_number.data:
|
||||||
self.serial_number.data = self.serial_number.data.lower()
|
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
|
return True
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
for n in range(self.amount.data):
|
for n in range(self.amount.data):
|
||||||
|
self.reset_ids()
|
||||||
self.create_device()
|
self.create_device()
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
|
@ -500,6 +484,8 @@ class NewDeviceForm(FlaskForm):
|
||||||
snapshot_json['device'].meid = self.meid.data
|
snapshot_json['device'].meid = self.meid.data
|
||||||
|
|
||||||
snapshot_json['device'].placeholder = self.get_placeholder()
|
snapshot_json['device'].placeholder = self.get_placeholder()
|
||||||
|
snapshot_json['device'].hid = self.phid.data
|
||||||
|
|
||||||
snapshot = upload_form.build(snapshot_json)
|
snapshot = upload_form.build(snapshot_json)
|
||||||
move_json(self.tmp_snapshots, path_snapshot, g.user.email)
|
move_json(self.tmp_snapshots, path_snapshot, g.user.email)
|
||||||
|
|
||||||
|
@ -509,6 +495,27 @@ class NewDeviceForm(FlaskForm):
|
||||||
|
|
||||||
return snapshot
|
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):
|
def get_placeholder(self):
|
||||||
self.placeholder = Placeholder(
|
self.placeholder = Placeholder(
|
||||||
**{
|
**{
|
||||||
|
|
|
@ -627,7 +627,7 @@ def test_add_with_ammount_laptops(user3: UserClientFlask):
|
||||||
assert 'Device "Laptop" created successfully!' in body
|
assert 'Device "Laptop" created successfully!' in body
|
||||||
for dev in Device.query.all():
|
for dev in Device.query.all():
|
||||||
assert dev.type == 'Laptop'
|
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 dev.hid in [str(x) for x in range(1, num + 1)]
|
||||||
assert Device.query.count() == num
|
assert Device.query.count() == num
|
||||||
|
|
||||||
|
|
Reference in New Issue