在Frappe.Cloud的ERPNext中调用服务端方法时出现模块不存在错误
问题排查与解决
核心错误原因
报错提示找不到模块frappe.core.doctype.B_Online_test,本质是你填写的method路径完全错误:B_Online_test不可能是frappe核心(frappe.core)下的Doctype,它应该是你自定义的Doctype,路径格式不符合规则;另外也可能存在Doctype名称拼写错误、服务端方法未正确定义的情况。
具体排查与修复步骤
- 核对自定义Doctype的正确路径
自定义Doctype的服务端方法路径格式为:[你的应用名称].doctype.[小写Doctype名].[小写Doctype名].[方法名]
比如你的应用叫custom_order,Doctype是B_Online_test,那正确路径应该是:
custom_order.doctype.b_online_test.b_online_test.create_sales_invoice
- 确认服务端方法的有效性
- 找到
B_Online_test对应的Python文件(通常在[应用根目录]/doctype/b_online_test/b_online_test.py),检查是否存在create_sales_invoice函数,且函数顶部必须加上@frappe.whitelist()装饰器(允许客户端调用):@frappe.whitelist() def create_sales_invoice(): # 你的方法逻辑代码 pass - 后台Doctype列表中确认
B_Online_test确实存在,名称大小写完全匹配。
- 修正客户端脚本的method参数
根据实际需求调整:
- 如果你的脚本目的是获取Customer的custom_fcm_token(从args参数看是这个需求),根本不需要自定义方法,直接调用frappe内置的
frappe.db.get_value即可,修正后的脚本:frappe.call({ method: "frappe.db.get_value", args: { doctype: "Customer", filters: { "name": frm.doc.customer }, fieldname: ["custom_fcm_token"] }, callback: function(r) { if(r.message) { frm.set_value('order_status', 'Cancelled'); send_fcm(frm, r.message.custom_fcm_token, "Order Status Updated", "Your Order is Cancelled"); frm.save(); } } }); - 如果确实需要调用
create_sales_invoice方法,把method改成第一步确认的正确路径即可。
内容的提问来源于stack exchange,提问作者Abdul Hanan
相关产品推荐
相关产品推荐

