More work to add work logs to inventory.
This commit is contained in:
parent
57104824a1
commit
29dc740725
3 changed files with 22 additions and 21 deletions
|
|
@ -4,7 +4,7 @@ from sqlalchemy.inspection import inspect
|
|||
from typing import Any, Dict, List, Tuple, Callable, Optional
|
||||
|
||||
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
|
||||
|
||||
bp_entry = Blueprint("entry", __name__)
|
||||
|
|
@ -15,10 +15,7 @@ def _fields_for_model(model: str):
|
|||
layout = []
|
||||
|
||||
if model == "inventory":
|
||||
fields = ["label", "name", "serial", "barcode", "brand", "model",
|
||||
"device_type", "owner", "location", "condition", "image",
|
||||
"notes", "work_logs.start_time", "work_logs.work_item.label",
|
||||
"work_logs.contact.label", "work_logs.complete"]
|
||||
fields = []
|
||||
fields_spec = [
|
||||
{"name": "label", "type": "display", "label": "", "row": "label",
|
||||
"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"}},
|
||||
{"name": "notes", "type": "template", "label": "Notes", "row": "notes", "wrap": {"class": "col"},
|
||||
"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 = [
|
||||
{"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"]
|
||||
|
||||
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"},
|
||||
])
|
||||
|
||||
form = render_form(
|
||||
cls,
|
||||
obj.as_dict(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue