import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_field def create_custom_fields(): custom_fields = { "Payment Entry": [ dict( fieldname='custom_note', label='Note', fieldtype='Data', insert_after='status' ) ], "Bank": [ dict( fieldname='bank_code', label='Code', fieldtype='Data', insert_after='swift_number' ) ], "Employee Transfer": [ dict( fieldname='reason', label='Reason', fieldtype='Data', insert_after='amended_from' ) ], "Company": [ dict( fieldname='ceo', label='Chief Executive Officer', fieldtype='Link', options='Employee', insert_after='default_holiday_list', read_only=1 ), dict( fieldname='director', label='Director', fieldtype='Link', options='Employee', insert_after='ceo' ), dict( fieldname='city_print', label='City (for print formats)', fieldtype='Data', insert_after='director' ) ] } for doctype, fields in custom_fields.items(): for field in fields: # Попытка удалить поле, если оно существует if frappe.db.exists("Custom Field", {"dt": doctype, "fieldname": field['fieldname']}): try: custom_field_name = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": field['fieldname']}, "name") frappe.delete_doc("Custom Field", custom_field_name) frappe.db.commit() print(f"Deleted field {field['fieldname']} in {doctype}") except Exception as e: print(f"Failed to delete field {field['fieldname']} in {doctype}: {e}") # Создание поля create_custom_field(doctype, field) print(f"Created field {field['fieldname']} in {doctype}")