Clone
6
Script zum Anlegen von Feldern
JensFalk edited this page 2026-06-08 18:01:47 +02:00
cd frappe-bench
bench --site xxx console
import frappe

fields = [
    {"label": "Berchmans Status", "fieldname": "custom_berchmans_status", "fieldtype": "Select", "options": "publish\ndraft\nprivate", "default": "publish"},
    {"label": "ISBN", "fieldname": "isbn", "fieldtype": "Data"},
    {"label": "Autor", "fieldname": "autor", "fieldtype": "Data"},
    {"label": "Untertitel", "fieldname": "untertitel", "fieldtype": "Data"},
    {"label": "Verlag", "fieldname": "verlag", "fieldtype": "Data"},
    {"label": "Erscheinungsjahr", "fieldname": "erscheinungsjahr", "fieldtype": "Data"},
    {"label": "Edition", "fieldname": "edition", "fieldtype": "Data"},
    {"label": "Produkttyp", "fieldname": "produkttyp", "fieldtype": "Select", "options": "Buch\nComic\nKarte\nFoto\nSchallplatte\nCD\nDVD"},
    {"label": "Bindung", "fieldname": "bindung", "fieldtype": "Select", "options": "Hardcover\nPaperback\nTaschenbuch\nBroschiert"},
    {"label": "Zustand", "fieldname": "zustand", "fieldtype": "Select", "options": "Wie neu\nTadellos\nSehr gut\nGut\nBefriedigend\nAusreichend\nSchlecht"},
    {"label": "Zustand des Schutzumschlages", "fieldname": "zustand_schutzumschlag", "fieldtype": "Select", "options": "Wie neu\nTadellos\nSehr gut\nGut\nBefriedigend\nAusreichend\nSchlecht"},
    {"label": "Zustandsbeschreibung", "fieldname": "zustandsbeschreibung", "fieldtype": "Small Text"},
    {"label": "Zusaetzliches", "fieldname": "zusaetzliches", "fieldtype": "Small Text"},
    {"label": "Kuenstler", "fieldname": "kuenstler", "fieldtype": "Data"},
    {"label": "Format", "fieldname": "format", "fieldtype": "Data"},
    {"label": "Umdrehung", "fieldname": "umdrehung", "fieldtype": "Data"},
    {"label": "Zustand Huelle", "fieldname": "zustand_huelle", "fieldtype": "Select", "options": "Mint\nNear Mint\nFine\nVery Good\nGood\nFair\nPoor"},
    {"label": "Zustand Platte", "fieldname": "zustand_platte", "fieldtype": "Select", "options": "Mint\nNear Mint\nFine\nVery Good\nGood\nFair\nPoor"},
]

for field in fields:
    try:
        if not frappe.db.exists("Custom Field", {"fieldname": field["fieldname"], "dt": "Item"}):
            doc = frappe.get_doc({
                "doctype": "Custom Field",
                "dt": "Item",
                "fieldname": field["fieldname"],
                "label": field["label"],
                "fieldtype": field["fieldtype"],
                "options": field.get("options"),
                "default": field.get("default")
            })
            doc.insert()
            print("Feld angelegt: " + field["label"])
        else:
            print("Feld existiert bereits: " + field["label"])
    except Exception as e:
        print("Fehler bei " + field["label"] + ": " + str(e))

frappe.db.commit()
print("\n=== Alle Felder verarbeitet ===")