|
|
|
@@ -1,4 +1,5 @@
|
|
|
|
|
import frappe
|
|
|
|
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FIELDS = [
|
|
|
|
@@ -13,6 +14,7 @@ FIELDS = [
|
|
|
|
|
("Sales Order", "makap_acceptance_reference", "Acceptance Reference", "Data", None, 0),
|
|
|
|
|
# Module 4 — manufacturing readiness and process classification
|
|
|
|
|
("Operation", "makap_process_type", "Makap Process Type", "Select", "Printing — Gravure\nPrinting — Flexographic\nLamination\nSlitting\nRewinding\nConversion / Bag Making\nFinishing\nOther", 0),
|
|
|
|
|
("Work Order", "makap_release_section", "Release Readiness", "Section Break", None, 0),
|
|
|
|
|
("Work Order", "makap_packaging_specification", "Packaging Specification", "Link", "Packaging Specification", 1),
|
|
|
|
|
("Work Order", "makap_specification_revision", "Specification Revision", "Data", None, 1),
|
|
|
|
|
("Work Order", "makap_sales_order_item_reference", "Sales Order Item Reference", "Data", None, 0),
|
|
|
|
@@ -25,9 +27,10 @@ FIELDS = [
|
|
|
|
|
("Work Order", "makap_bom_compatibility_confirmed_by", "BOM Compatibility Confirmed By", "Link", "User", 1),
|
|
|
|
|
("Work Order", "makap_bom_compatibility_confirmed_on", "BOM Compatibility Confirmed On", "Datetime", None, 1),
|
|
|
|
|
("Work Order", "makap_process_compatibility_status", "Process Compatibility Status", "Select", "Not Checked\nCompatible\nIncompatible\nNot Applicable", 0),
|
|
|
|
|
("Work Order", "makap_tooling_readiness_status", "Tooling Readiness Status", "Select", "Not Checked\nReady\nBlocked\nNot Required", 0),
|
|
|
|
|
("Work Order", "makap_tooling_readiness_status", "Tooling Readiness Status", "Select", "Not Checked\nReady\nBlocked\nNot Required", 1),
|
|
|
|
|
# Module 5 — bounded material accountability controls
|
|
|
|
|
("Item", "makap_material_control_class", "Material Control Class", "Select", "Standard\nControlled\nHigh Traceability", 0),
|
|
|
|
|
("Work Order", "makap_material_section", "Material Accountability", "Section Break", None, 0),
|
|
|
|
|
("Work Order", "makap_material_availability_status", "Material Availability Status", "Select", "Not Checked\nBlocked\nPartially Available\nAvailable", 0),
|
|
|
|
|
("Work Order", "makap_material_availability_checked_by", "Material Availability Checked By", "Link", "User", 1),
|
|
|
|
|
("Work Order", "makap_material_availability_checked_on", "Material Availability Checked On", "Datetime", None, 1),
|
|
|
|
@@ -42,6 +45,7 @@ FIELDS = [
|
|
|
|
|
("Quality Inspection", "makap_work_order", "Work Order", "Link", "Work Order", 0),
|
|
|
|
|
("Quality Inspection", "makap_quality_gate_stage", "Quality Gate Stage", "Select", "First-Off\nIn-Process\nFinal\nIncoming\nOutgoing\nNot Applicable", 0),
|
|
|
|
|
("Quality Inspection", "makap_inspection_trigger", "Inspection Trigger", "Select", "Routine\nFirst-Off\nPeriodic\nPost-Adjustment\nPost-Rework\nComplaint\nRetrospective Hold", 0),
|
|
|
|
|
("Quality Inspection", "makap_eligibility_section", "Eligibility and Disposition", "Section Break", None, 0),
|
|
|
|
|
("Quality Inspection", "makap_quality_eligibility", "Quality Eligibility", "Select", "Not Determined\nEligible\nIneligible\nHold", 0),
|
|
|
|
|
("Quality Inspection", "makap_inspection_population_quantity", "Inspection Population Quantity", "Float", None, 0),
|
|
|
|
|
("Quality Inspection", "makap_population_uom", "Population UOM", "Link", "UOM", 0),
|
|
|
|
@@ -53,6 +57,7 @@ FIELDS = [
|
|
|
|
|
("Quality Inspection", "makap_disposition_on", "Disposition On", "Datetime", None, 1),
|
|
|
|
|
("Quality Inspection", "makap_disposition_reason", "Disposition Reason", "Small Text", None, 0),
|
|
|
|
|
("Quality Inspection", "makap_defect_failure_category", "Defect / Failure Category", "Data", None, 0),
|
|
|
|
|
("Quality Inspection", "makap_exception_section", "Exceptions, Reinspection and Concessions", "Section Break", None, 0),
|
|
|
|
|
("Quality Inspection", "makap_quality_exception_type", "Quality Exception Type", "Select", "None\nConcession\nReinspection\nRetrospective Hold\nTraceability Exception", 0),
|
|
|
|
|
("Quality Inspection", "makap_reinspection_of", "Reinspection Of", "Link", "Quality Inspection", 0),
|
|
|
|
|
("Quality Inspection", "makap_reinspection_type", "Reinspection Type", "Select", "Full\nPartial\nTargeted", 0),
|
|
|
|
@@ -84,6 +89,7 @@ FIELDS = [
|
|
|
|
|
("Delivery Note", "makap_dispatch_accountability_notes", "Dispatch Accountability Notes", "Small Text", None, 0),
|
|
|
|
|
# Placeholder only — real deposit/credit logic lands in Module 8B. Defaults to Not Required
|
|
|
|
|
# so the Dispatch Gate can already evaluate it without blocking every delivery today.
|
|
|
|
|
("Delivery Note", "makap_release_section", "Financial Release and Short-Close", "Section Break", None, 0),
|
|
|
|
|
("Delivery Note", "makap_financial_release_status", "Financial Release Status", "Select", "Not Required\nNot Assessed\nBlocked\nCleared\nException Approved", 0),
|
|
|
|
|
("Delivery Note", "makap_short_close", "Short-Close", "Check", None, 0),
|
|
|
|
|
("Delivery Note", "makap_short_close_reason", "Short-Close Reason", "Small Text", None, 0),
|
|
|
|
@@ -130,32 +136,97 @@ FIELDS = [
|
|
|
|
|
("Purchase Invoice Item", "makap_quantity_variance", "Quantity Variance", "Float", None, 1),
|
|
|
|
|
("Purchase Invoice Item", "makap_rate_variance", "Rate Variance", "Float", None, 1),
|
|
|
|
|
# Module 8F — manufacturing execution cost interpretation
|
|
|
|
|
("Work Order", "makap_cost_section", "Cost Interpretation", "Section Break", None, 0),
|
|
|
|
|
("Work Order", "makap_cost_status", "Cost Status", "Select", "Not Assessed\nProvisional\nReady to Close\nClosed\nRestatement Required", 0),
|
|
|
|
|
("Work Order", "makap_cost_confidence", "Cost Confidence", "Select", "Not Assessed\nHigh\nQualified\nLow / Provisional", 0),
|
|
|
|
|
("Work Order", "makap_cost_attribution_basis", "Cost Attribution Basis", "Select", "Not Assessed\nExact\nDirectly Derived\nPooled / Valuation-Based\nQualified", 0),
|
|
|
|
|
# Roll tracking — every film/roll batch carries its physical dimensions (PRD 4, B3)
|
|
|
|
|
("Batch", "makap_roll_stage", "Roll Stage", "Select", "\nResin / Raw Material\nBase Film\nPrinted Roll\nLaminated Roll\nSlit Reel\nFinished Goods", 0),
|
|
|
|
|
("Batch", "makap_width_mm", "Width (mm)", "Float", None, 0),
|
|
|
|
|
("Batch", "makap_length_m", "Length (m)", "Float", None, 0),
|
|
|
|
|
("Batch", "makap_micron", "Thickness (micron)", "Float", None, 0),
|
|
|
|
|
("Batch", "makap_roll_col", None, "Column Break", None, 0),
|
|
|
|
|
("Batch", "makap_net_weight_kg", "Net Weight (kg)", "Float", None, 0),
|
|
|
|
|
("Batch", "makap_gross_weight_kg", "Gross Weight (kg)", "Float", None, 0),
|
|
|
|
|
("Batch", "makap_supplier_lot", "Supplier Lot / Roll No", "Data", None, 0),
|
|
|
|
|
("Batch", "makap_workstation", "Produced On", "Link", "Workstation", 0),
|
|
|
|
|
("Batch", "makap_work_order", "Work Order", "Link", "Work Order", 0),
|
|
|
|
|
# Operator capture on each stage's Job Card (PRD 4 stage 3, problem 4)
|
|
|
|
|
("Job Card", "makap_output_rolls", "Output Rolls", "Int", None, 0),
|
|
|
|
|
("Job Card", "makap_output_length_m", "Output Length (m)", "Float", None, 0),
|
|
|
|
|
("Job Card", "makap_output_weight_kg", "Output Weight (kg)", "Float", None, 0),
|
|
|
|
|
("Job Card", "makap_output_col", None, "Column Break", None, 0),
|
|
|
|
|
("Job Card", "makap_setup_waste_kg", "Set-up Waste (kg)", "Float", None, 0),
|
|
|
|
|
("Job Card", "makap_running_waste_kg", "Running Waste (kg)", "Float", None, 0),
|
|
|
|
|
("Job Card", "makap_waste_pct", "Waste %", "Percent", None, 1),
|
|
|
|
|
("Job Card", "makap_waste_reason", "Main Waste Reason", "Select", "\nSet-up / Make-ready\nRegistration\nColour Match\nWeb Break\nWrinkles / Creasing\nBond Failure\nSeal Failure\nEdge Trim\nMaterial Defect\nMachine Fault\nOther", 0),
|
|
|
|
|
("Job Card", "makap_waste_notes", "Waste Notes", "Small Text", None, 0),
|
|
|
|
|
# Quotation cost estimate from an estimating BOM (PRD 4 stage 1, M4)
|
|
|
|
|
("Quotation Item", "makap_estimate_bom", "Estimating BOM", "Link", "BOM", 0),
|
|
|
|
|
("Quotation Item", "makap_waste_pct", "Expected Waste %", "Percent", None, 0),
|
|
|
|
|
("Quotation Item", "makap_setup_cost", "Set-up Cost", "Currency", None, 0),
|
|
|
|
|
("Quotation Item", "makap_cylinder_charge", "Cylinder / Plate Charge", "Currency", None, 0),
|
|
|
|
|
("Quotation Item", "makap_estimate_col", None, "Column Break", None, 0),
|
|
|
|
|
("Quotation Item", "makap_material_cost", "Estimated Material Cost", "Currency", None, 1),
|
|
|
|
|
("Quotation Item", "makap_conversion_cost", "Estimated Conversion Cost", "Currency", None, 1),
|
|
|
|
|
("Quotation Item", "makap_estimated_cost", "Estimated Total Cost", "Currency", None, 1),
|
|
|
|
|
("Quotation Item", "makap_estimated_margin_pct", "Estimated Margin %", "Percent", None, 1),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_custom_fields():
|
|
|
|
|
created = []
|
|
|
|
|
# Where each DocType's Makap fields live. Parent forms get one "Makap" tab;
|
|
|
|
|
# child rows get a section. Operator and roll fields sit in the main view
|
|
|
|
|
# because they are filled in on the shop floor, not reviewed later.
|
|
|
|
|
CONTAINERS = {
|
|
|
|
|
"Job Card": ("Section Break", "Output and Waste", "actual_end_date"),
|
|
|
|
|
"Batch": ("Section Break", "Roll Details", None),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _end_anchor(meta):
|
|
|
|
|
"""Last standard field, keeping a trailing Connections tab last."""
|
|
|
|
|
standard = [df for df in meta.fields if not df.get("is_custom_field")]
|
|
|
|
|
if len(standard) > 1 and standard[-1].fieldtype == "Tab Break":
|
|
|
|
|
return standard[-2].fieldname
|
|
|
|
|
return standard[-1].fieldname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_custom_fields():
|
|
|
|
|
grouped = {}
|
|
|
|
|
for dt, fieldname, label, fieldtype, options, read_only in FIELDS:
|
|
|
|
|
grouped.setdefault(dt, []).append(
|
|
|
|
|
{"fieldname": fieldname, "label": label, "fieldtype": fieldtype, "options": options, "read_only": read_only}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
for dt, fields in grouped.items():
|
|
|
|
|
if not frappe.db.exists("DocType", dt):
|
|
|
|
|
continue
|
|
|
|
|
if frappe.db.exists("Custom Field", {"dt": dt, "fieldname": fieldname}):
|
|
|
|
|
continue
|
|
|
|
|
doc = frappe.get_doc(
|
|
|
|
|
meta = frappe.get_meta(dt)
|
|
|
|
|
if dt in CONTAINERS:
|
|
|
|
|
break_type, label, anchor = CONTAINERS[dt]
|
|
|
|
|
elif meta.istable:
|
|
|
|
|
break_type, label, anchor = "Section Break", "Makap", None
|
|
|
|
|
else:
|
|
|
|
|
break_type, label, anchor = "Tab Break", "Makap", None
|
|
|
|
|
|
|
|
|
|
chain = [
|
|
|
|
|
{
|
|
|
|
|
"doctype": "Custom Field",
|
|
|
|
|
"dt": dt,
|
|
|
|
|
"fieldname": fieldname,
|
|
|
|
|
"fieldname": "makap_tab" if break_type == "Tab Break" else "makap_section",
|
|
|
|
|
"label": label,
|
|
|
|
|
"fieldtype": fieldtype,
|
|
|
|
|
"options": options,
|
|
|
|
|
"read_only": read_only,
|
|
|
|
|
"insert_after": "amended_from" if dt in {"Sales Order", "Work Order", "Quality Inspection", "Delivery Note", "Sales Invoice", "Purchase Invoice"} else None,
|
|
|
|
|
"fieldtype": break_type,
|
|
|
|
|
"insert_after": anchor or _end_anchor(meta),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
doc.insert(ignore_permissions=True)
|
|
|
|
|
created.append(f"{dt}.{fieldname}")
|
|
|
|
|
frappe.db.commit()
|
|
|
|
|
return created
|
|
|
|
|
]
|
|
|
|
|
for field in fields:
|
|
|
|
|
field["insert_after"] = chain[-1]["fieldname"]
|
|
|
|
|
chain.append(field)
|
|
|
|
|
result[dt] = chain
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_custom_fields():
|
|
|
|
|
"""Create or update every Makap custom field, including its position on the form."""
|
|
|
|
|
fields = build_custom_fields()
|
|
|
|
|
create_custom_fields(fields, update=True)
|
|
|
|
|
return sorted(f"{dt}.{f['fieldname']}" for dt, rows in fields.items() for f in rows)
|
|
|
|
|