在版本 12.1 中新增
操作和链接(也称为连接)是为终端用户提供与文档更多交互的两种方式。下图展示了它们是什么:
操作
一个 DocType 可能有一些 DocType Action,这会导致在 DocType 视图上生成一个按钮。支持的操作有:
- 服务器操作:这将触发一个已列入白名单的服务器操作。
- 路由:这将重定向到给定的路由。
操作配置
在自定义应用中配置操作
要在您自己的应用中调用操作,您需要一个使用 frappe.whitelist 装饰的 Python 函数:
import frappe
@frappe.whitelist()
def execute_function(*args,**kwargs):
"""
This function will be executed when the Execute Action Button will be clicked
"""
print('Hello World')
# The data is transmitted via keyword argument
print(kwargs)
此代码应放在您应用中的某个位置,通常放在类似 apps/my_app/my_app/api.py 的文件中
然后,配置相应的操作路径:
连接(关联文档)
DocType 视图的一个标准导航辅助工具是仪表板上的 Connections 部分。这有助于查看者一目了然地识别哪些文档类型与此 DocType 相关联,并可以快速创建新的相关文档。
这些链接还支持添加内部链接(指向子表中的 DocType 的链接)。
配置连接
通过脚本
要为您的应用中的文档类型配置连接,请在 <doctype>_dashboard.py</doctype> 中创建一个 get_data() 函数。以下示例来自 ERPNext 中销售发票文档类型的 sales_invoice_dashboard.py:
from frappe import _
def get_data():
return {
"fieldname": "sales_invoice",
"non_standard_fieldnames": {
"Delivery Note": "against_sales_invoice",
"Journal Entry": "reference_name",
"Payment Entry": "reference_name",
"Payment Request": "reference_name",
"Sales Invoice": "return_against",
"Auto Repeat": "reference_document",
"Purchase Invoice": "inter_company_invoice_reference",
},
"internal_links": {
"Sales Order": ["items", "sales_order"],
"Timesheet": ["timesheets", "time_sheet"],
},
"internal_and_external_links": {
"Delivery Note": ["items", "delivery_note"],
},
"transactions": [
{
"label": _("Payment"),
"items": [
"Payment Entry",
"Payment Request",
"Journal Entry",
"Invoice Discounting",
"Dunning",
],
},
{"label": _("Reference"), "items": ["Timesheet", "Delivery Note", "Sales Order"]},
{"label": _("Returns"), "items": ["Sales Invoice"]},
{"label": _("Subscription"), "items": ["Auto Repeat"]},
{"label": _("Internal Transfers"), "items": ["Purchase Invoice"]},
],
}
transactions定义所有连接以及它们所属的相应分组。internal_links定义文档类型具有内部链接的连接。例如,销售发票通过其项目子表与销售订单文档类型具有内部链接。internal_and_external_links定义文档类型同时具有内部和外部链接的连接。例如,销售发票通过其项目子表与交货单文档类型具有内部链接,并且销售发票也通过其项目子表与交货单文档类型具有外部链接。fieldname定义在查找文档类型的外部链接时要搜索的默认字段名。non_standard_fieldnames定义在查找文档类型的外部链接时要搜索的字段名及其相应的文档类型。
这将产生以下连接:
操作和链接的自定义
DocType 操作和链接可通过自定义表单进行扩展