Add inventory audit feature
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful

This commit is contained in:
Madis Mägi 2023-08-29 20:47:53 +03:00
parent 5759a2aced
commit e67f00652b
2 changed files with 87 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import boto3
import pymongo
from datetime import datetime
from bson.objectid import ObjectId
from flask import Blueprint, abort, g, make_response, redirect, render_template, request
from jpegtran import JPEGImage
@ -398,6 +399,20 @@ def view_inventory(slug=None):
return render_template(template, **locals())
@page_inventory.route("/m/inventory/<item_id>/audit", methods=["POST"])
@login_required(groups=["k-space:janitors"])
def view_inventory_audit(item_id):
user = read_user()
db.inventory.update_one({
"_id": ObjectId(item_id),
}, {
"$set": {
"inventory.audit.username": user["username"],
"inventory.audit.timestamp": datetime.utcnow(),
},
})
return redirect("/m/inventory/%s/view" % item_id)
@page_inventory.route("/m/inventory/<item_id>/claim", methods=["POST"])
@login_required
def view_inventory_claim(item_id):

View File

@ -65,6 +65,19 @@
<td>{{ item.inventory.get("user").username | display_name }}</td>
</tr>
<tr>
<td>Last audited</td>
<td>
{% if item.inventory.get("audit") %}
{{ item.inventory.audit.timestamp | timeago }}
by
{{ item.inventory.audit.username | display_name }}
{% else %}
Never
{% endif %}
</td>
</tr>
<tr>
<td>URL slug</td>
<td>
@ -149,6 +162,48 @@
</div>
</div>
{% if can_audit %}
<div class="row">
<div class="col s12">
<button data-target="audit-modal" class="modal-trigger orange waves-effect waves-light btn"><i class="material-icons left">done</i>Audit</button>
</div>
</div>
<div id="audit-modal" class="modal">
<div class="modal-content">
<h4>Check that:</h4>
<p>
<label>
<input class="audit-check" type="checkbox"/>
<span>Object is present at the space</span>
</label>
</p>
<p>
<label>
<input class="audit-check" type="checkbox"/>
<span>There is no obvious issues and it does not present danger</span>
</label>
</p>
<p>
<label>
<input class="audit-check" type="checkbox"/>
<span>Object has QR code attached to it and it's up to date</span>
</label>
</p>
<p>
<label>
<input class="audit-check" type="checkbox"/>
<span>Picture is up to date</span>
</label>
</p>
</div>
<div class="modal-footer">
<form action="/m/inventory/{{ item._id }}/audit" method="post" style="display: inline;">
<button id="audit-modal-send" disabled="" type="submit" class="orange waves-effect waves-light btn"><i class="material-icons left">done</i>Confirm</button>
</form>
</div>
</div>
{% endif %}
</div>
<script>
$(function() {
@ -163,6 +218,23 @@ $(function() {
}
});
photoInput.change();
var auditModal = $("div#audit-modal");
var auditButton = $("button#audit-modal-send");
var auditChecks = $("input.audit-check");
auditModal.modal({
onOpenStart() {
auditChecks.prop('checked', false);
auditButton.prop("disabled", true);
}
});
auditChecks.on("change", function() {
if (auditChecks.not(":checked").length == 0) {
auditButton.prop("disabled", false);
} else {
auditButton.prop("disabled", true);
}
});
});
</script>
{% endblock %}