From 242218d2b7a7a7ff810a6889b1201b2c61909244 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 13 Sep 2017 18:41:01 +0530 Subject: [PATCH] Progress fixes (#10710) * [progress] sales target slide * [fix] rerun patch for sales target slide --- erpnext/patches.txt | 2 +- .../v8_9/add_setup_progress_actions.py | 5 ++ .../doctype/setup_progress/setup_progress.py | 19 ++++-- .../setup_progress_action.json | 63 ++++++++++++++++++- .../setup/setup_wizard/install_fixtures.py | 4 ++ erpnext/utilities/user_progress.py | 31 ++++++++- erpnext/utilities/user_progress_utils.py | 6 ++ 7 files changed, 121 insertions(+), 9 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 6829bd4033..c7b331c6c1 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -436,7 +436,7 @@ erpnext.patches.v8_7.add_more_gst_fields erpnext.patches.v8_7.fix_purchase_receipt_status erpnext.patches.v8_6.rename_bom_update_tool erpnext.patches.v8_7.set_offline_in_pos_settings #11-09-17 -erpnext.patches.v8_9.add_setup_progress_actions +erpnext.patches.v8_9.add_setup_progress_actions #08-09-2017 erpnext.patches.v8_9.rename_company_sales_target_field erpnext.patches.v8_8.set_bom_rate_as_per_uom erpnext.patches.v8_7.make_subscription_from_recurring_data \ No newline at end of file diff --git a/erpnext/patches/v8_9/add_setup_progress_actions.py b/erpnext/patches/v8_9/add_setup_progress_actions.py index 25698cc167..97d2d1450a 100644 --- a/erpnext/patches/v8_9/add_setup_progress_actions.py +++ b/erpnext/patches/v8_9/add_setup_progress_actions.py @@ -11,6 +11,10 @@ def execute(): actions = [ {"action_name": _("Add Company"), "action_doctype": "Company", "min_doc_count": 1, "is_completed": 1, "domains": '[]' }, + {"action_name": _("Set Sales Target"), "action_doctype": "Company", "min_doc_count": 99, + "action_document": frappe.defaults.get_defaults().get("company") or '', + "action_field": "monthly_sales_target", "is_completed": 0, + "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, {"action_name": _("Add Customers"), "action_doctype": "Customer", "min_doc_count": 1, "is_completed": 0, "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, {"action_name": _("Add Suppliers"), "action_doctype": "Supplier", "min_doc_count": 1, "is_completed": 0, @@ -30,6 +34,7 @@ def execute(): ] setup_progress = frappe.get_doc("Setup Progress", "Setup Progress") + setup_progress.actions = [] for action in actions: setup_progress.append("actions", action) diff --git a/erpnext/setup/doctype/setup_progress/setup_progress.py b/erpnext/setup/doctype/setup_progress/setup_progress.py index 26eecd9634..9187eb7996 100644 --- a/erpnext/setup/doctype/setup_progress/setup_progress.py +++ b/erpnext/setup/doctype/setup_progress/setup_progress.py @@ -24,10 +24,21 @@ def update_action_completed_state(action_name): if d.action_name == action_name][0] update_action(action_table_doc) -def update_action(action_table_doc): - if not action_table_doc.is_completed and frappe.db.count(action_table_doc.action_doctype) >= action_table_doc.min_doc_count: - action_table_doc.is_completed = 1 - action_table_doc.save() +def update_action(doc): + doctype = doc.action_doctype + docname = doc.action_document + field = doc.action_field + + if not doc.is_completed: + if doc.min_doc_count: + if frappe.db.count(doctype) >= doc.min_doc_count: + doc.is_completed = 1 + doc.save() + if docname and field: + d = frappe.get_doc(doctype, docname) + if d.get(field): + doc.is_completed = 1 + doc.save() def update_domain_actions(domain): for d in get_setup_progress().actions: diff --git a/erpnext/setup/doctype/setup_progress_action/setup_progress_action.json b/erpnext/setup/doctype/setup_progress_action/setup_progress_action.json index 030fd99a33..e9abcbcd1a 100644 --- a/erpnext/setup/doctype/setup_progress_action/setup_progress_action.json +++ b/erpnext/setup/doctype/setup_progress_action/setup_progress_action.json @@ -73,6 +73,67 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "action_document", + "fieldtype": "Dynamic Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Action Document", + "length": 0, + "no_copy": 0, + "options": "action_doctype", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "action_field", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Action Field", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -174,7 +235,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-08-28 17:44:58.008526", + "modified": "2017-09-01 14:34:59.685730", "modified_by": "Administrator", "module": "Setup", "name": "Setup Progress Action", diff --git a/erpnext/setup/setup_wizard/install_fixtures.py b/erpnext/setup/setup_wizard/install_fixtures.py index 8e0973d365..54620122b2 100644 --- a/erpnext/setup/setup_wizard/install_fixtures.py +++ b/erpnext/setup/setup_wizard/install_fixtures.py @@ -25,6 +25,10 @@ def install(country=None): {'doctype': "Setup Progress", "actions": [ {"action_name": _("Add Company"), "action_doctype": "Company", "min_doc_count": 1, "is_completed": 1, "domains": '[]' }, + {"action_name": _("Set Sales Target"), "action_doctype": "Company", "min_doc_count": 99, + "action_document": frappe.defaults.get_defaults().get("company") or '', + "action_field": "monthly_sales_target", "is_completed": 0, + "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, {"action_name": _("Add Customers"), "action_doctype": "Customer", "min_doc_count": 1, "is_completed": 0, "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, {"action_name": _("Add Suppliers"), "action_doctype": "Supplier", "min_doc_count": 1, "is_completed": 0, diff --git a/erpnext/utilities/user_progress.py b/erpnext/utilities/user_progress.py index 482179beee..250951159a 100644 --- a/erpnext/utilities/user_progress.py +++ b/erpnext/utilities/user_progress.py @@ -9,6 +9,14 @@ def get_slide_settings(): defaults = frappe.defaults.get_defaults() domain = frappe.db.get_value('Company', erpnext.get_default_company(), 'domain') company = defaults.get("company") or '' + currency = defaults.get("currency") or '' + + doc = frappe.get_doc("Setup Progress") + item = [d for d in doc.get("actions") if d.action_name == "Set Sales Target"][0] + item.action_document = company + item.save() + doc.save() + # Initial state of slides return [ frappe._dict( @@ -29,12 +37,29 @@ def get_slide_settings(): "video_id": "U5wPIvEn-0c" } ] - ) - , + ), + frappe._dict( + action_name='Set Sales Target', + domains=('Manufacturing', 'Services', 'Retail', 'Distribution'), + title=_("Set a Target"), + help=_("Set a sales goal you'd like to achieve for your company."), + fields=[ + {"fieldtype":"Currency", "fieldname":"monthly_sales_target", + "label":_("Monthly Sales Target (" + currency + ")")}, + ], + submit_method="erpnext.utilities.user_progress_utils.set_sales_target", + done_state_title=_("Go to " + company), + done_state_title_route=["Form", "Company", company], + help_links=[ + { + "label": _('Learn More'), + "url": ["https://erpnext.org/docs/user/manual/en/setting-up/setting-company-sales-goal"] + } + ] + ), frappe._dict( action_name='Add Customers', domains=('Manufacturing', 'Services', 'Retail', 'Distribution'), - icon="fa fa-group", title=_("Add Customers"), help=_("List a few of your customers. They could be organizations or individuals."), fields=[ diff --git a/erpnext/utilities/user_progress_utils.py b/erpnext/utilities/user_progress_utils.py index 1c9c9e8aa1..709da574c2 100644 --- a/erpnext/utilities/user_progress_utils.py +++ b/erpnext/utilities/user_progress_utils.py @@ -8,6 +8,12 @@ from frappe import _ from frappe.utils import flt from erpnext.setup.doctype.setup_progress.setup_progress import update_domain_actions, get_domain_actions_state +@frappe.whitelist() +def set_sales_target(args_data): + args = json.loads(args_data) + defaults = frappe.defaults.get_defaults() + frappe.db.set_value("Company", defaults.get("company"), "monthly_sales_target", args.get('monthly_sales_target')) + @frappe.whitelist() def create_customers(args_data): args = json.loads(args_data)