90% ready formula editor with small bugs

This commit is contained in:
Ali 2025-03-28 20:15:29 +04:00
parent 2f077b7752
commit 282ba65f58
3 changed files with 3222 additions and 1981 deletions

View File

@ -3,10 +3,10 @@ import frappe
def get_doctype_fields(doctype):
meta = frappe.get_meta(doctype)
fields = []
# Получаем все int-поля
# Получаем все числовые поля
for field in meta.fields:
if field.fieldtype in ["Int", "Float", "Currency"]:
fields.append({"fieldname": field.fieldname, "label": field.label})
fields.append({"fieldname": field.fieldname, "label": field.label, "fieldtype": field.fieldtype})
# Проверяем таблицы внутри DocType (например, items в Sales Invoice)
for child in meta.fields:
if child.fieldtype == "Table":
@ -14,14 +14,15 @@ def get_doctype_fields(doctype):
for sub_field in child_meta.fields:
if sub_field.fieldtype in ["Int", "Float", "Currency"]:
fields.append({
"fieldname": f"{child.fieldname}{sub_field.fieldname}",
"label": f"{child.label}{sub_field.label}"
"fieldname": f"{child.fieldname}_{sub_field.fieldname}",
"label": f"{child.label}{sub_field.label}",
"fieldtype": sub_field.fieldtype
})
return fields
@frappe.whitelist()
def get_all_doctype_fields(doctype):
"""Получение отфильтрованных полей DocType без служебных полей"""
"""Получение отфильтрованных полей DocType включая расширенные типы для фильтров"""
meta = frappe.get_meta(doctype)
fields = []
@ -29,18 +30,46 @@ def get_all_doctype_fields(doctype):
excluded_types = [
"Tab Break", "Column Break", "Button", "Section Break", "Column Break",
"HTML", "Table", "Attach", "Attach Image", "Code", "Text Editor", "Image",
"Read Only", "Heading", "Fold", "Table MultiSelect"
"Heading", "Fold", "Table MultiSelect"
]
# Получаем все поля, которые не входят в исключенные типы
for field in meta.fields:
if field.fieldname and field.fieldtype not in excluded_types:
fields.append({
field_data = {
"fieldname": field.fieldname,
"label": field.label or field.fieldname,
"fieldtype": field.fieldtype
})
}
# Мы не добавляем поля из таблиц, так как они были исключены из списка
# Добавляем опции для полей типа Select и Link
if field.fieldtype in ["Select", "Link"] and field.options:
field_data["options"] = field.options
fields.append(field_data)
return fields
@frappe.whitelist()
def on_trash(doc, method=None):
"""Удаляет клиентские скрипты, созданные для DocType при удалении Formula Editor"""
if not doc.target_doctype:
return
# Ищем клиентские скрипты, созданные для целевого DocType
client_scripts = frappe.get_all(
"Client Script",
filters={
"dt": doc.target_doctype,
"name": ["like", "Formula_Editor_Script_for_%"]
},
fields=["name"]
)
# Удаляем найденные скрипты
for script in client_scripts:
try:
frappe.delete_doc("Client Script", script.name, force=True)
frappe.db.commit()
except Exception as e:
frappe.log_error(f"Не удалось удалить клиентский скрипт {script.name}: {str(e)}")

View File

@ -140,13 +140,11 @@ app_license = "unlicense"
# ---------------
# Hook on document methods and events
# doc_events = {
# "*": {
# "on_update": "method",
# "on_cancel": "method",
# "on_trash": "method"
# }
# }
doc_events = {
"Formula Editor": {
"on_trash": "formula_editor.api.on_trash"
}
}
# Scheduled Tasks
# ---------------