frappe.ui.form.on(‘Truck Pre-Trip Checklist’, {
onload: function(frm) {
if (frm.is_new()) {
frappe.call({
method: ‘logistics.logistics.doctype.truck_pre_trip_checklist.truck_pre_trip_checklist.get_sections’,
callback: function(r) {
if (!r.message) return;
frm.doc.sections = [];
r.message.forEach(function(sec) {
let s = frappe.model.add_child(frm.doc, ‘Checklist Section’, ‘sections’);
s.section_name = sec.section_name;
s.description = sec.description || ‘’;
s.status = ‘Okay’;
s.remarks = ‘’;
});
frm.refresh_field(‘sections’);
}
});
}
}
});
frappe.ui.form.on(‘Checklist Section’, {
status: function(frm, cdt, cdn) {
frm.dirty();
}
});
and this is python script
import frappe
from frappe.model.document import Document
DEFAULT_STATUS = “Okay”
@frappe.whitelist()
def get_sections():
return frappe.get_all(
“Checklist Section Template”,
fields=[
“section_name”,
“description”,
“is_critical”
\],
order_by=“order asc”
)
class TruckPreTripChecklist(Document):
def before_save(self):
self._set_default_statuses()
self.overall_result = self._calculate_overall_result()
def validate(self):
self._validate_defective_remarks()
def on_submit(self):
self._validate_comments()
self._validate_critical_sections()
def _set_default_statuses(self):
for section in self.sections:
if not section.status:
section.status = DEFAULT_STATUS
def _validate_defective_remarks(self):
for section in self.sections:
if section.status == “Defective” and not section.remarks:
frappe.throw(
title=“Missing Remarks”,
msg=(
f"Remarks required for defective section: "
f"{section.section_name}"
)
)
def _calculate_overall_result(self):
if not self.sections:
return “Okay”
statuses = \[row.status for row in self.sections\]
if all(status == “Okay” for status in statuses):
return “Okay”
if any(status == “Defective” for status in statuses):
return “Defective”
return “Defective”
def _validate_comments(self):
if not self.comments_defects_report:
frappe.throw(
title=“Missing Comments”,
msg=“Comments / Defects Report is mandatory before submitting.”
)
def _validate_critical_sections(self):
critical_sections = set(
frappe.get_all(
“Checklist Section Template”,
filters={“is_critical”: 1},
pluck=“section_name”
)
)
failed_sections = \[
row.section_name
for row in self.sections
if (
row.section_name in critical_sections
and row.status != “Okay”
)
\]
if failed_sections:
failed_list = "<br>".join(
f"• {section}"
for section in failed_sections
)
frappe.throw(
title=“Critical Sections Failed”,
msg=(
"Cannot submit. "
“Critical sections not Okay:
”
f"{failed_list}"
)
)
and this is its json i dont know where the erro is coming from
{
“actions”: [],
“allow_rename”: 1,
“autoname”: “PTCHK-.YYYY.-.#####”,
“creation”: “2026-05-09 22:27:39.447616”,
“doctype”: “DocType”,
“editable_grid”: 1,
“engine”: “InnoDB”,
“field_order”: [
“driver”,
“col1”,
“vehicle”,
“col2”,
“date”,
“sec_checklist”,
“sections”,
“amended_from”,
“sec_break_comments”,
“comments_defects_report”
],
“fields”: [
{
“fieldname”: “driver”,
“fieldtype”: “Link”,
“in_list_view”: 1,
“in_standard_filter”: 1,
“label”: “Driver’s Name”,
“options”: “Driver”,
“reqd”: 1
},
{
“fieldname”: “col1”,
“fieldtype”: “Column Break”
},
{
“fieldname”: “vehicle”,
“fieldtype”: “Link”,
“in_list_view”: 1,
“in_standard_filter”: 1,
“label”: “Truck Reg. No.”,
“options”: “Vehicle”,
“reqd”: 1
},
{
“fieldname”: “col2”,
“fieldtype”: “Column Break”
},
{
“default”: “Today”,
“fieldname”: “date”,
“fieldtype”: “Date”,
“in_list_view”: 1,
“label”: “Date”,
“reqd”: 1
},
{
“fieldname”: “sec_checklist”,
“fieldtype”: “Section Break”,
“label”: “Inspection Checklist”
},
{
“fieldname”: “sections”,
“fieldtype”: “Table”,
“label”: “Checklist Sections”,
“options”: “Checklist Section”
},
{
“fieldname”: “amended_from”,
“fieldtype”: “Link”,
“label”: “Amended From”,
“no_copy”: 1,
“options”: “Truck Pre-Trip Checklist”,
“print_hide”: 1,
“read_only”: 1,
“search_index”: 1
},
{
“fieldname”: “sec_break_comments”,
“fieldtype”: “Section Break”,
“label”: “Comments / Defects Report”
},
{
“fieldname”: “comments_defects_report”,
“fieldtype”: “Text Editor”,
“label”: “Comments / Defects Report”
}
],
“grid_page_length”: 12,
“index_web_pages_for_search”: 1,
“is_submittable”: 1,
“links”: [],
“modified”: “2026-05-13 15:52:56.858266”,
“modified_by”: “Administrator”,
“module”: “Logistics”,
“name”: “Truck Pre-Trip Checklist”,
“naming_rule”: “Expression”,
“owner”: “Administrator”,
“permissions”: [
{
“create”: 1,
“delete”: 1,
“email”: 1,
“export”: 1,
“print”: 1,
“read”: 1,
“report”: 1,
“role”: “Driver”,
“share”: 1,
“submit”: 1,
“write”: 1
},
{
“amend”: 1,
“cancel”: 1,
“create”: 1,
“delete”: 1,
“email”: 1,
“export”: 1,
“print”: 1,
“read”: 1,
“report”: 1,
“role”: “System Manager”,
“share”: 1,
“submit”: 1,
“write”: 1
}
],
“row_format”: “Dynamic”,
“rows_threshold_for_grid_search”: 20,
“sort_field”: “creation”,
“sort_order”: “DESC”,
“states”: [
{
“color”: “Gray”,
“title”: “Pending”
},
{
“color”: “Green”,
“title”: “Pass”
},
{
“color”: “Orange”,
“title”: “Pass with Defects”
},
{
“color”: “Red”,
“title”: “Fail”
}
],
“track_changes”: 1
}
