import frappe

def add_depends_on():
    """Add depends_on field to Dispatch Job."""
    fieldname = "depends_on"
    if frappe.db.exists("Custom Field", {"dt": "Dispatch Job", "fieldname": fieldname}):
        print(f"  Field {fieldname} already exists, skipping.")
        return
    frappe.get_doc({
        "doctype": "Custom Field",
        "dt": "Dispatch Job",
        "fieldname": "depends_on",
        "fieldtype": "Link",
        "label": "Dépend de",
        "options": "Dispatch Job",
        "insert_after": "source_issue",
    }).insert(ignore_permissions=True)
    frappe.db.commit()
    print(f"  ✓ Dispatch Job.depends_on field added.")

if __name__ == "__main__":
    frappe.connect(site="erp.gigafibre.ca")
    add_depends_on()
    frappe.destroy()
