From a3e846a978492f48773cba53a5cae474795e2cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E5=88=99=E9=9C=96?= <7624863+yuzelin@user.noreply.gitee.com> Date: Wed, 7 Jan 2026 09:54:42 +0800 Subject: [PATCH] company update and insert events, refine readme --- README.md | 10 ++++++++++ erpnext_china/doc_events.py | 25 +++++++++++++++++++++++++ erpnext_china/hooks.py | 7 +++++++ 3 files changed, 42 insertions(+) create mode 100644 erpnext_china/doc_events.py diff --git a/README.md b/README.md index 89b8eef..a47e369 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,12 @@ ## 安装 +``` +没有设置默认站点的,install-app时请加--site参数 + bench get-app erpnext_china https://gitee.com/yuzlin/erpnext_china.git bench install-app erpnext_china +``` ## 功能说明 @@ -57,6 +61,12 @@ bench install-app erpnext_china 2. 隐藏本地化不适用字段(如PAN号等印度专用字段) 3. 修改默认系统流水码前缀-改短 +## 常见问题 + +1. 是否与之前的中文汉化与开箱即用冲突 + +建议卸载中文汉化和开箱即用后再安装这个 + #### License MIT \ No newline at end of file diff --git a/erpnext_china/doc_events.py b/erpnext_china/doc_events.py new file mode 100644 index 0000000..06969dd --- /dev/null +++ b/erpnext_china/doc_events.py @@ -0,0 +1,25 @@ +import frappe +from erpnext_china.chart_of_accounts.company_default.utils import set_company_default +from erpnext_china.chart_of_accounts.custom_accounts.custom_account import erpnext_china_create_charts + + +def company_after_insert(doc, method): + doc.erpnext_china_in_insert = True + +def company_on_update(doc, method): + if not frappe.db.sql( + """select name from tabAccount + where company=%s and docstatus<2 limit 1""", + doc.name, + ): + if not frappe.local.flags.ignore_chart_of_accounts: + frappe.flags.country_change = True + frappe.local.flags.ignore_root_company_validation = True + frappe.local.flags.ignore_chart_of_accounts = 1 + zelin_ac_create_charts(doc.name, doc.chart_of_accounts, doc.existing_company) + + if doc.get("erpnext_china_in_insert") and doc.chart_of_accounts and doc.country == "China": + try: + set_company_default(doc.name) + except: + frappe.log_error("erpnext_china.doc_events.company_on_update set company default error") \ No newline at end of file diff --git a/erpnext_china/hooks.py b/erpnext_china/hooks.py index 4af815e..bcb17f2 100644 --- a/erpnext_china/hooks.py +++ b/erpnext_china/hooks.py @@ -18,4 +18,11 @@ override_whitelisted_methods = { "erpnext_china.chart_of_accounts.custom_accounts.custom_account.get_chart", "erpnext.accounts.utils.get_coa": "erpnext_china.chart_of_accounts.custom_accounts.custom_account.get_coa", "frappe.desk.treeview.get_all_nodes": "erpnext_china.chart_of_accounts.custom_accounts.custom_account.get_all_nodes", +} + +doc_events = { + "Company": { + "on_update": "erpnext_china.doc_events.company_on_update", + "after_insert": "erpnext_china.doc_events.company_after_insert" + } } \ No newline at end of file