Problem report expanded.
This commit is contained in:
parent
f249a935d5
commit
11998b6b31
2 changed files with 71 additions and 1 deletions
|
|
@ -127,7 +127,51 @@ def init_reports_routes(app):
|
||||||
{"field": "condition"},
|
{"field": "condition"},
|
||||||
], opts={"object_class": "inventory"})
|
], opts={"object_class": "inventory"})
|
||||||
|
|
||||||
return render_template("problems.html", orphans=orphans)
|
rows = inventory_svc.list({
|
||||||
|
"fields": ["id", "name", "serial", "barcode", "brand.name", "model", "device_type.description", "owner.label", "location.label"],
|
||||||
|
"limit": 0,
|
||||||
|
"$or": [
|
||||||
|
{"name__ne": None},
|
||||||
|
{"serial__ne": None},
|
||||||
|
{"barcode__ne": None},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
duplicates = pd.DataFrame([r.as_dict() for r in rows]).set_index("id", drop=True)
|
||||||
|
subset = ["name", "serial", "barcode"]
|
||||||
|
|
||||||
|
mask = (
|
||||||
|
(duplicates["name"].notna() & duplicates.duplicated("name", keep=False)) |
|
||||||
|
(duplicates["serial"].notna() & duplicates.duplicated("serial", keep=False)) |
|
||||||
|
(duplicates["barcode"].notna() & duplicates.duplicated("barcode", keep=False))
|
||||||
|
)
|
||||||
|
|
||||||
|
duplicates = duplicates.loc[mask].sort_values(subset)
|
||||||
|
# you already have this
|
||||||
|
cols = [
|
||||||
|
{"name": "name", "label": "Name"},
|
||||||
|
{"name": "serial", "label": "Serial #"},
|
||||||
|
{"name": "barcode", "label": "Bar Code"},
|
||||||
|
{"name": "brand.name", "label": "Brand"},
|
||||||
|
{"name": "model", "label": "Model"},
|
||||||
|
{"name": "device_type.description", "label": "Device Type"},
|
||||||
|
{"name": "owner.label", "label": "Owner"},
|
||||||
|
{"name": "location.label", "label": "Location"},
|
||||||
|
]
|
||||||
|
|
||||||
|
col_names = [c["name"] for c in cols if c["name"] in duplicates.columns]
|
||||||
|
col_labels = [c["label"] for c in cols if c["name"] in duplicates.columns]
|
||||||
|
|
||||||
|
out = duplicates[col_names].fillna("")
|
||||||
|
|
||||||
|
# Best for Jinja: list of dicts (each row keyed by column name)
|
||||||
|
duplicates = (
|
||||||
|
out.reset_index()
|
||||||
|
.rename(columns={"index": "id"})
|
||||||
|
.to_dict(orient="records")
|
||||||
|
)
|
||||||
|
headers_for_template = ["ID"] + col_labels
|
||||||
|
|
||||||
|
return render_template("problems.html", orphans=orphans, duplicates=duplicates, duplicate_columns=headers_for_template)
|
||||||
|
|
||||||
app.register_blueprint(bp_reports)
|
app.register_blueprint(bp_reports)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,31 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p>Equipment Without Active Owner</p>
|
<p>Equipment Without Active Owner</p>
|
||||||
{{ orphans | safe }}
|
{{ orphans | safe }}
|
||||||
|
<p>Duplicate Inventory Entries</p>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-sm table-info table-bordered table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{% for col in duplicate_columns %}
|
||||||
|
<th>
|
||||||
|
{{ col }}
|
||||||
|
</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for record in duplicates %}
|
||||||
|
<tr style="cursor: pointer;"
|
||||||
|
onclick="location.href='{{ url_for('entry.entry', model='inventory', id=record['id']) }}'">
|
||||||
|
{% for cell in record.values() %}
|
||||||
|
<td>
|
||||||
|
{{ cell }}
|
||||||
|
</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue