Compare commits

..

2 commits

Author SHA1 Message Date
Yaro Kasear
5a1f978aa2 Final push on work logs on inventory page. 2025-10-06 10:16:33 -05:00
Yaro Kasear
29dc740725 More work to add work logs to inventory. 2025-10-06 09:45:07 -05:00
3 changed files with 22 additions and 21 deletions

View file

@ -51,8 +51,6 @@ class User(Base, CRUDMixin):
@hybrid_property @hybrid_property
def label(self): def label(self):
out = f"{self.first_name} {self.last_name}" out = f"{self.first_name} {self.last_name}"
if self.title:
out = out + f" ({self.title})"
return out return out
@label.expression @label.expression
@ -68,9 +66,4 @@ class User(Base, CRUDMixin):
space = case((have_first & have_last, literal(" ")), else_=literal("")) space = case((have_first & have_last, literal(" ")), else_=literal(""))
title_part = case( return func.concat(first, space, last)
(func.length(sql_trim(title, backend)) > 0, func.concat(" (", title, ")")),
else_=literal("")
)
return func.concat(first, space, last, title_part)

View file

@ -4,7 +4,7 @@ from sqlalchemy.inspection import inspect
from typing import Any, Dict, List, Tuple, Callable, Optional from typing import Any, Dict, List, Tuple, Callable, Optional
import crudkit import crudkit
from crudkit.ui.fragments import render_form, register_template_globals from crudkit.ui.fragments import render_form, render_table, register_template_globals
from crudkit.core import normalize_payload from crudkit.core import normalize_payload
bp_entry = Blueprint("entry", __name__) bp_entry = Blueprint("entry", __name__)
@ -15,10 +15,7 @@ def _fields_for_model(model: str):
layout = [] layout = []
if model == "inventory": if model == "inventory":
fields = ["label", "name", "serial", "barcode", "brand", "model", fields = []
"device_type", "owner", "location", "condition", "image",
"notes", "work_logs.start_time", "work_logs.work_item.label",
"work_logs.contact.label", "work_logs.complete"]
fields_spec = [ fields_spec = [
{"name": "label", "type": "display", "label": "", "row": "label", {"name": "label", "type": "display", "label": "", "row": "label",
"attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}}, "attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}},
@ -58,7 +55,8 @@ def _fields_for_model(model: str):
"wrap": {"class": "h-100 w-100"}}, "wrap": {"class": "h-100 w-100"}},
{"name": "notes", "type": "template", "label": "Notes", "row": "notes", "wrap": {"class": "col"}, {"name": "notes", "type": "template", "label": "Notes", "row": "notes", "wrap": {"class": "col"},
"template": "inventory_note.html"}, "template": "inventory_note.html"},
{"name": "work_logs", "type": "template", "row": "notes", "wrap": {"class": "col"}, "template": "inventory_logs.html"}, {"name": "work_logs", "type": "template", "template_ctx": {}, "row": "notes", "wrap": {"class": "col"},
"template": "inventory_logs.html"},
] ]
layout = [ layout = [
{"name": "label", "order": 5, "attrs": {"class": "row align-items-center"}}, {"name": "label", "order": 5, "attrs": {"class": "row align-items-center"}},
@ -187,6 +185,22 @@ def init_entry_routes(app):
ScopedSession = current_app.extensions["crudkit"]["Session"] ScopedSession = current_app.extensions["crudkit"]["Session"]
if model == "inventory":
log_cls = crudkit.crud.get_model("worklog")
log_svc = crudkit.crud.get_service(log_cls)
logs = log_svc.list({
"work_item_id__eq": id,
"fields": "id,contact.label,complete,created_at,updated_at",
})
fields_spec[13]["template_ctx"]["table"] = render_table(logs, [
{"field": "id", "label": "ID"},
{"field": "contact.label", "label": "Contact",
"link": {"endpoint": "entry.entry", "params": {"id": "{contact.id}", "model": "user"}}},
{"field": "created_at", "label": "Created", "format": "datetime"},
{"field": "updated_at", "label": "Updated", "format": "datetime"},
{"field": "complete", "format": "yesno"},
], opts={"object_class": "worklog"})
form = render_form( form = render_form(
cls, cls,
obj.as_dict(), obj.as_dict(),

View file

@ -1,8 +1,2 @@
<label class="form-label">Work Logs</label> <label class="form-label">Work Logs</label>
<p> {{ field['template_ctx']['table'] | safe }}
{{ field }}
</p>
<p>
{{ field['template_ctx']['values']['work_logs'] }}
</p>
{% include "table.html" %}