服务端代码调试方法
有时候,我们经常要在应用端写Python脚本做调试。如下为列示的2种方法。
bench execute方法
不带参数的:
bench execute erpnextcn.utils.GetMail.get_mail
bench execute erpnextcn.utils.Test.get_search_date
带2个参数:
bench execute erpnextcn.utils.vue.enapi.getChartOfAccountItemTree --kwargs "{'company': 'x023', 'roottype': 'Asset'}"
带1个参数且带地址的:
bench execute erpnextcn.utils.QRCodeExtractor.extract_qr_info --args r"/home/frappe/frappe-bench/apps/erpnextcn/erpnextcn/滴滴电子发票.pdf"
其中 --args 的参数 r是必须带的, 涉及到一些路径问题, 否则容易被转义
参考函数定义:
@frappe.whitelist()
def getChartOfAccountItemTree(**args):
all_accounts = frappe.get_all(
"Account",
filters={"company": args.get('company'),
"root_type": args.get('roottype')
},
fields=[
"name",
"parent_account",
"account_number"
],
order_by="lft, rgt",
)
# print(all_accounts)
result = create_coa_account_tree(all_accounts, None)
# 返回JSON数据给前端
return result
bench console 方法:
bench console
Apps in this namespace:
frappe, erpnext, erpituc
In [1]: import erpituc.ituchelper.try_it as try_it
In [2]: try_it.test(1,2,3,4,5)
1
2
3
4
5
在console里头查看dict:
from frappe import as_json
doc = make_purchase_receipt_doc('PUR-ORD-DTY2024-00047')
print(as_json(doc))