This commit is contained in:
Cayo Puigdefabregas 2022-06-29 17:31:54 +02:00
parent a4aced0238
commit 3dae7e3a58
5 changed files with 53 additions and 30 deletions

View File

@ -388,12 +388,12 @@ class NewDeviceForm(FlaskForm):
self.depth.errors = error self.depth.errors = error
is_valid = False is_valid = False
if self.imei.data: if self.imei.data and self.amount.data == 1:
if not 13 < len(str(self.imei.data)) < 17: if not 13 < len(str(self.imei.data)) < 17:
self.imei.errors = error self.imei.errors = error
is_valid = False is_valid = False
if self.meid.data: if self.meid.data and self.amount.data == 1:
meid = self.meid.data meid = self.meid.data
if not 13 < len(meid) < 17: if not 13 < len(meid) < 17:
is_valid = False is_valid = False
@ -407,7 +407,7 @@ class NewDeviceForm(FlaskForm):
dev = Device.query.filter_by( dev = Device.query.filter_by(
hid=self.phid.data, owner=g.user, active=True hid=self.phid.data, owner=g.user, active=True
).first() ).first()
if dev and not dev.placeholder: if dev:
msg = "Sorry, exist one snapshot device with this HID" msg = "Sorry, exist one snapshot device with this HID"
self.phid.errors = [msg] self.phid.errors = [msg]
is_valid = False is_valid = False
@ -424,12 +424,26 @@ 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):
if self.amount.data > 1:
self.phid.data = None
for n in range(self.amount.data): for n in range(self.amount.data):
self.create_device() self.create_device()
@ -486,20 +500,9 @@ 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()
_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'
snapshot_json['device'].hid = _hid.lower()
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)
if self.type.data == 'ComputerMonitor': if self.type.data == 'ComputerMonitor':
snapshot.device.resolution = self.resolution.data snapshot.device.resolution = self.resolution.data
snapshot.device.screen = self.screen.data snapshot.device.screen = self.screen.data

View File

@ -28,7 +28,17 @@ function deviceInputs() {
function amountInputs() { function amountInputs() {
if ($("#amount").val() > 1) { if ($("#amount").val() > 1) {
$("#Phid").hide(); $("#Phid").hide();
$("#Id_device_supplier").hide();
$("#Serial_number").hide();
$("#Sku").hide();
$("#imei").hide();
$("#meid").hide();
} else { } else {
$("#Phid").show(); $("#Phid").show();
$("#Id_device_supplier").show();
$("#Serial_number").show();
$("#Sku").show();
$("#imei").show();
$("#meid").show();
}; };
} }

View File

@ -103,7 +103,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="form-group mb-2"> <div class="form-group mb-2" id="Id_device_supplier">
<label for="label" class="form-label">{{ form.id_device_supplier.label }}</label> <label for="label" class="form-label">{{ form.id_device_supplier.label }}</label>
{{ form.id_device_supplier(class_="form-control") }} {{ form.id_device_supplier(class_="form-control") }}
<small class="text-muted form-text">Identity of device for the Supplier</small> <small class="text-muted form-text">Identity of device for the Supplier</small>
@ -142,7 +142,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="from-group has-validation mb-2"> <div class="from-group has-validation mb-2" id="Serial_number">
<label for="serialNumber" class="form-label">{{ form.serial_number.label }}</label> <label for="serialNumber" class="form-label">{{ form.serial_number.label }}</label>
{{ form.serial_number(class_="form-control") }} {{ form.serial_number(class_="form-control") }}
<small class="text-muted form-text">Serial number of this device</small> <small class="text-muted form-text">Serial number of this device</small>
@ -349,7 +349,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="from-group has-validation mb-2"> <div class="from-group has-validation mb-2" id="Sku">
<label for="model" class="form-label">{{ form.sku.label }}</label> <label for="model" class="form-label">{{ form.sku.label }}</label>
{{ form.sku(class_="form-control") }} {{ form.sku(class_="form-control") }}
<small class="text-muted form-text">The Stock Keeping Unit (SKU), i.e. a merchant-specific identifier for a product or service.</small> <small class="text-muted form-text">The Stock Keeping Unit (SKU), i.e. a merchant-specific identifier for a product or service.</small>

View File

@ -315,7 +315,7 @@
<div class="btn-group dropdown m-1" uib-dropdown=""> <div class="btn-group dropdown m-1" uib-dropdown="">
<button id="btnSnapshot" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> <button id="btnSnapshot" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-laptop"></i> <i class="bi bi-laptop"></i>
New Device New Devices
</button> </button>
<ul class="dropdown-menu" aria-labelledby="btnSnapshot"> <ul class="dropdown-menu" aria-labelledby="btnSnapshot">
<li> <li>
@ -325,7 +325,17 @@
<a href="{{ url_for('inventory.upload_snapshot') }}" class="dropdown-item"> <a href="{{ url_for('inventory.upload_snapshot') }}" class="dropdown-item">
{% endif %} {% endif %}
<i class="bi bi-upload"></i> <i class="bi bi-upload"></i>
Upload a new Snapshot Upload Snapshot files
</a>
</li>
<li>
{% if lot %}
<a href="{{ url_for('inventory.lot_upload_snapshot', lot_id=lot.id) }}" class="dropdown-item">
{% else %}
<a href="{{ url_for('inventory.upload_snapshot') }}" class="dropdown-item">
{% endif %}
<i class="bi bi-upload"></i>
Upload Placeholder Spreadsheet
</a> </a>
</li> </li>
<li> <li>
@ -335,7 +345,7 @@
<a href="{{ url_for('inventory.device_add') }}" class="dropdown-item"> <a href="{{ url_for('inventory.device_add') }}" class="dropdown-item">
{% endif %} {% endif %}
<i class="bi bi-plus"></i> <i class="bi bi-plus"></i>
Create a new Device Create a new Placeholder
</a> </a>
</li> </li>
</ul> </ul>

View File

@ -504,14 +504,14 @@ def test_update_monitor(user3: UserClientFlask):
} }
body, status = user3.post(uri, data=data) body, status = user3.post(uri, data=data)
assert status == '200 OK' assert status == '200 OK'
assert 'Device &#34;Monitor&#34; created successfully!' in body assert 'Sorry, exist one snapshot device with this HID' in body
dev = Device.query.one() dev = Device.query.one()
assert dev.type == 'Monitor' assert dev.type == 'Monitor'
assert dev.placeholder.id_device_supplier == "b3" assert dev.placeholder.id_device_supplier == "b2"
assert dev.hid == '1' assert dev.hid == '1'
assert dev.model == 'lcd 43 b' assert dev.model == 'lc27t55'
assert dev.depth == 0.2 assert dev.depth == 0.1
assert dev.placeholder.pallet == "l20" assert dev.placeholder.pallet == "l34"
@pytest.mark.mvp @pytest.mark.mvp
@ -628,7 +628,7 @@ def test_add_with_ammount_laptops(user3: UserClientFlask):
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 == "b2"
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