SMall bug fix plus initial addition to "problem" records.

This commit is contained in:
Yaro Kasear 2025-10-23 10:54:44 -05:00
parent 46b3e2600f
commit f249a935d5
5 changed files with 52 additions and 1 deletions

View file

@ -17,7 +17,8 @@ class WorkLog(Base, CRUDMixin):
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
contact_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
updates: Mapped[List['WorkNote']] = relationship('WorkNote', back_populates='work_log', cascade='all, delete-orphan', order_by='WorkNote.timestamp.desc()')
updates: Mapped[List['WorkNote']] = relationship('WorkNote', back_populates='work_log', cascade='all, delete-orphan',
order_by="desc(WorkNote.timestamp), desc(WorkNote.id)", lazy="selectin")
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
work_item_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('inventory.id'), nullable=True, index=True)

View file

@ -3,6 +3,8 @@ from urllib.parse import urlencode
import pandas as pd
from crudkit.ui.fragments import render_table
import crudkit
bp_reports = Blueprint("reports", __name__)
@ -92,4 +94,40 @@ def init_reports_routes(app):
table_rows=table_rows,
)
@bp_reports.get("/problems")
def problems():
inventory_model = crudkit.crud.get_model('inventory')
inventory_svc = crudkit.crud.get_service(inventory_model)
rows = inventory_svc.list({
"limit": 0,
"$or": [
{"owner.active__eq": False},
{"owner_id": None}
],
"fields": [
"owner.label",
"label",
"brand.name",
"model",
"device_type.description",
"location.label",
"condition"
],
})
orphans = render_table(rows, [
{"field": "owner.label", "label": "Owner", "link": {"endpoint": "entry.entry", "params": {"id": "{owner.id}", "model": "user"}}},
{"field": "label", "label": "Device"},
{"field": "brand.name", "label": "Brand"},
{"field": "model"},
{"field": "device_type.description", "label": "Device Type"},
{"field": "location.label", "label": "Location"},
{"field": "condition"},
], opts={"object_class": "inventory"})
return render_template("problems.html", orphans=orphans)
app.register_blueprint(bp_reports)

View file

@ -40,6 +40,7 @@
<a class="nav-link dropdown-toggle link-success fw-semibold" data-bs-toggle="dropdown">Reports</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="{{ url_for('reports.summary') }}">Inventory Summary</a></li>
<li><a class="dropdown-item" href="{{ url_for('reports.problems') }}">Problems</a></li>
</ul>
</li>
</ul>

View file

@ -0,0 +1,10 @@
{% extends 'base.html' %}
{% block main %}
<h1 class="display-4 mb-3 text-center">Records With Problems</h1>
<div class="container">
<p>Equipment Without Active Owner</p>
{{ orphans | safe }}
</div>
{% endblock %}