From 3dbaa3c2d9dfc30205f378c1db69afcd09d845f2 Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Fri, 19 Apr 2019 16:31:23 +0530 Subject: [PATCH 1/4] fix(site_sync): return more data in level --- erpnext/utilities/activation.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py index 16391e073e2..8e59bdc966b 100644 --- a/erpnext/utilities/activation.py +++ b/erpnext/utilities/activation.py @@ -48,7 +48,27 @@ def get_level(): if frappe.db.sql('select name from tabUser where last_login > date_sub(now(), interval 2 day) limit 1'): activation_level += 1 - return activation_level + level = {"activation_level": 10, "sales_data": [ + {"Item": frappe.db.count('Item')}, + {"Sales Order": frappe.db.count('Sales Order')}, + {"Purchase Order": frappe.db.count('Purchase Order')}, + {"Employee": frappe.db.count('Employee')}, + {"Lead": frappe.db.count('Lead')}, + {"Payment Entry": frappe.db.count('Payment Entry')}, + {"Communication": frappe.db.count('Communication')}, + {"User": frappe.db.count('User')}, + {"Student": frappe.db.count('Student')}, + {"Instructor": frappe.db.count('Instructor')}, + {"Sales Invoice": frappe.db.count('Sales Invoice')}, + {"BOM": frappe.db.count('BOM')}, + {"Quotation": frappe.db.count('Quotation')}, + {"Lead": frappe.db.count('Lead')}, + {"Payment Entry": frappe.db.count('Payment Entry')}, + {"Journal Entry": frappe.db.count('Journal Entry')}, + {"Stock Entry": frappe.db.count('Stock Entry')}, + ]} + + return level def get_help_messages(): '''Returns help messages to be shown on Desktop''' From 3889d0f0a0628e64e499d3840175b3ec9b6e0826 Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Sat, 20 Apr 2019 14:26:49 +0530 Subject: [PATCH 2/4] fix: refactor level --- erpnext/utilities/activation.py | 64 ++++++++------------------------- 1 file changed, 14 insertions(+), 50 deletions(-) diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py index 8e59bdc966b..ea1b0ea3a6a 100644 --- a/erpnext/utilities/activation.py +++ b/erpnext/utilities/activation.py @@ -7,66 +7,30 @@ import frappe, erpnext from frappe import _ def get_level(): + activation_level = 0 + sales_data = [] + doctypes = {"Item": 5, "Customer": 5, "Sales Order": 2, "Sales Invoice": 2, "Purchase Order": 2, "Employee": 3, "Lead": 3, "Quotation": 3 + "Payment Entry": 2, "User": 5, "Student": 5, "Instructor": 5, "BOM": 3, "Journal Entry": 3, "Stock Entry": 3} + for doctype, min_count in iteritems(doctypes): + count = frappe.db.count(doctype) + if count > min_count: + activation_level += 1 + sales_data.append({doctype: count}) + if frappe.db.get_single_value('System Settings', 'setup_complete'): - activation_level = 1 - - if frappe.db.count('Item') > 5: activation_level += 1 - if frappe.db.count('Customer') > 5: - activation_level += 1 - - if frappe.db.count('Sales Order') > 2: - activation_level += 1 - - if frappe.db.count('Purchase Order') > 2: - activation_level += 1 - - if frappe.db.count('Employee') > 3: - activation_level += 1 - - if frappe.db.count('Lead') > 3: - activation_level += 1 - - if frappe.db.count('Payment Entry') > 2: - activation_level += 1 - - if frappe.db.count('Communication', dict(communication_medium='Email')) > 10: - activation_level += 1 - - if frappe.db.count('User') > 5: - activation_level += 1 - - if frappe.db.count('Student') > 5: - activation_level += 1 - - if frappe.db.count('Instructor') > 5: + communication_number = frappe.db.count('Communication', dict(communication_medium='Email')) + if communication_number > 10: activation_level += 1 + sales_data.append({"Communication": communication_number}) # recent login if frappe.db.sql('select name from tabUser where last_login > date_sub(now(), interval 2 day) limit 1'): activation_level += 1 - level = {"activation_level": 10, "sales_data": [ - {"Item": frappe.db.count('Item')}, - {"Sales Order": frappe.db.count('Sales Order')}, - {"Purchase Order": frappe.db.count('Purchase Order')}, - {"Employee": frappe.db.count('Employee')}, - {"Lead": frappe.db.count('Lead')}, - {"Payment Entry": frappe.db.count('Payment Entry')}, - {"Communication": frappe.db.count('Communication')}, - {"User": frappe.db.count('User')}, - {"Student": frappe.db.count('Student')}, - {"Instructor": frappe.db.count('Instructor')}, - {"Sales Invoice": frappe.db.count('Sales Invoice')}, - {"BOM": frappe.db.count('BOM')}, - {"Quotation": frappe.db.count('Quotation')}, - {"Lead": frappe.db.count('Lead')}, - {"Payment Entry": frappe.db.count('Payment Entry')}, - {"Journal Entry": frappe.db.count('Journal Entry')}, - {"Stock Entry": frappe.db.count('Stock Entry')}, - ]} + level = {"activation_level": activation_level, "sales_data": sales_data} return level From cb4b86512dc28386bcd76fb1e7c8dda65722d0cc Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Mon, 22 Apr 2019 10:10:50 +0530 Subject: [PATCH 3/4] fix: syntax error --- erpnext/utilities/activation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py index ea1b0ea3a6a..e617cbaada0 100644 --- a/erpnext/utilities/activation.py +++ b/erpnext/utilities/activation.py @@ -10,7 +10,7 @@ def get_level(): activation_level = 0 sales_data = [] - doctypes = {"Item": 5, "Customer": 5, "Sales Order": 2, "Sales Invoice": 2, "Purchase Order": 2, "Employee": 3, "Lead": 3, "Quotation": 3 + doctypes = {"Item": 5, "Customer": 5, "Sales Order": 2, "Sales Invoice": 2, "Purchase Order": 2, "Employee": 3, "Lead": 3, "Quotation": 3, "Payment Entry": 2, "User": 5, "Student": 5, "Instructor": 5, "BOM": 3, "Journal Entry": 3, "Stock Entry": 3} for doctype, min_count in iteritems(doctypes): count = frappe.db.count(doctype) From afb59fa5c084b1e3238f8442779e9f1d0761aab0 Mon Sep 17 00:00:00 2001 From: Sahil Khan Date: Mon, 22 Apr 2019 10:47:37 +0530 Subject: [PATCH 4/4] fix: import iteritems --- erpnext/utilities/activation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py index e617cbaada0..d6e7c9ea458 100644 --- a/erpnext/utilities/activation.py +++ b/erpnext/utilities/activation.py @@ -5,11 +5,13 @@ from __future__ import unicode_literals import frappe, erpnext from frappe import _ +from six import iteritems def get_level(): activation_level = 0 sales_data = [] + min_count = 0 doctypes = {"Item": 5, "Customer": 5, "Sales Order": 2, "Sales Invoice": 2, "Purchase Order": 2, "Employee": 3, "Lead": 3, "Quotation": 3, "Payment Entry": 2, "User": 5, "Student": 5, "Instructor": 5, "BOM": 3, "Journal Entry": 3, "Stock Entry": 3} for doctype, min_count in iteritems(doctypes):