From 8728f26442be846b7a2cfebeebf6554d9f7671b4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 6 Nov 2013 14:19:09 +0530 Subject: [PATCH] Refactored plugin architecture to allow custom script reports --- patches/october_2013/p10_plugins_refactor.py | 24 ++++++++++++++++++++ patches/patch_list.py | 1 + utilities/demo/make_erpnext_demo.py | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 patches/october_2013/p10_plugins_refactor.py diff --git a/patches/october_2013/p10_plugins_refactor.py b/patches/october_2013/p10_plugins_refactor.py new file mode 100644 index 0000000000..b37bef4374 --- /dev/null +++ b/patches/october_2013/p10_plugins_refactor.py @@ -0,0 +1,24 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes, os, shutil + +def execute(): + # changed cache key for plugin code files + for doctype in webnotes.conn.sql_list("""select name from `tabDocType`"""): + webnotes.cache().delete_value("_server_script:"+doctype) + + # move custom script reports to plugins folder + for name in webnotes.conn.sql_list("""select name from `tabReport` + where report_type="Script Report" and is_standard="No" """): + bean = webnotes.bean("Report", name) + bean.save() + + module = webnotes.conn.get_value("DocType", bean.doc.ref_doctype, "module") + path = webnotes.modules.get_doc_path(module, "Report", name) + for extn in ["py", "js"]: + file_path = os.path.join(path, name + "." + extn) + plugins_file_path = webnotes.plugins.get_path(module, "Report", name, extn=extn) + if not os.path.exists(plugins_file_path) and os.path.exists(file_path): + shutil.copyfile(file_path, plugins_file_path) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 1581841872..f882739cdc 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -237,4 +237,5 @@ patch_list = [ "patches.october_2013.p07_rename_for_territory", "patches.june_2013.p07_taxes_price_list_for_territory", "patches.october_2013.p08_cleanup_after_item_price_module_change", + "patches.october_2013.p10_plugins_refactor", ] \ No newline at end of file diff --git a/utilities/demo/make_erpnext_demo.py b/utilities/demo/make_erpnext_demo.py index cda38d690d..a094239c4b 100644 --- a/utilities/demo/make_erpnext_demo.py +++ b/utilities/demo/make_erpnext_demo.py @@ -106,8 +106,8 @@ def make_demo_login_page(): def make_demo_on_login_script(): import shutil - from core.doctype.custom_script.custom_script import get_custom_server_script_path - custom_script_path = get_custom_server_script_path("Control Panel") + import webnotes.plugins + custom_script_path = webnotes.plugins.get_path("Core", "DocType", "Control Panel") webnotes.create_folder(os.path.dirname(custom_script_path)) shutil.copyfile(os.path.join(os.path.dirname(__file__), "demo_control_panel.py"), custom_script_path)