fix: manufacturing dashboard
diff --git a/erpnext/accounts/accounts b/erpnext/accounts/accounts
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/accounts
diff --git a/erpnext/accounts/dashboard_fixtures.py b/erpnext/accounts/dashboard_fixtures.py
index cdd1661..214e467 100644
--- a/erpnext/accounts/dashboard_fixtures.py
+++ b/erpnext/accounts/dashboard_fixtures.py
@@ -1,127 +1,264 @@
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
-from erpnext import get_default_company
import frappe
import json
+from frappe.utils import nowdate, add_months, get_date_str
+from frappe import _
+from erpnext.accounts.utils import get_fiscal_year, get_account_name
+def get_company_for_dashboards():
+ company = frappe.defaults.get_defaults().company
+ if company:
+ return company
+ else:
+ company_list = frappe.get_list("Company")
+ if company_list:
+ return company_list[0].name
+ return None
def get_data():
- data = frappe._dict({
- "dashboards": [],
- "charts": []
+ return frappe._dict({
+ "dashboards": get_dashboards(),
+ "charts": get_charts(),
+ "number_cards": get_number_cards()
})
- company = get_company_for_dashboards()
- if company:
- company_doc = frappe.get_doc("Company", company)
- data.dashboards = get_dashboards()
- data.charts = get_charts(company_doc)
- return data
def get_dashboards():
return [{
- "name": "Accounts",
- "dashboard_name": "Accounts",
+ "name": "Accounts Dashboard",
+ "dashboard_name": "Accounts Dashboard",
+ "doctype": "Dashboard",
"charts": [
- { "chart": "Outgoing Bills (Sales Invoice)" },
- { "chart": "Incoming Bills (Purchase Invoice)" },
- { "chart": "Bank Balance" },
- { "chart": "Income" },
- { "chart": "Expenses" }
+ { "chart": "Profit and Loss" , "width": "Full"},
+ { "chart": "Incoming Bills (Purchase Invoice)", "width": "Half"},
+ { "chart": "Outgoing Bills (Sales Invoice)", "width": "Half"},
+ { "chart": "Accounts Receivable Ageing", "width": "Half"},
+ { "chart": "Accounts Payable Ageing", "width": "Half"},
+ { "chart": "Budget Variance", "width": "Full"},
+ { "chart": "Bank Balance", "width": "Full"}
+ ],
+ "cards": [
+ {"card": "Total Outgoing Bills"},
+ {"card": "Total Incoming Bills"},
+ {"card": "Total Incoming Payment"},
+ {"card": "Total Outgoing Payment"}
]
}]
-def get_charts(company):
- income_account = company.default_income_account or get_account("Income Account", company.name)
- expense_account = company.default_expense_account or get_account("Expense Account", company.name)
- bank_account = company.default_bank_account or get_account("Bank", company.name)
+def get_charts():
+ company = frappe.get_doc("Company", get_company_for_dashboards())
+ bank_account = company.default_bank_account or get_account_name("Bank", company=company.name)
+ fiscal_year = get_fiscal_year(date=nowdate())
+ default_cost_center = company.cost_center
return [
{
- "doctype": "Dashboard Chart",
- "time_interval": "Quarterly",
- "name": "Income",
- "chart_name": "Income",
- "timespan": "Last Year",
- "color": None,
- "filters_json": json.dumps({"company": company.name, "account": income_account}),
- "source": "Account Balance Timeline",
- "chart_type": "Custom",
- "timeseries": 1,
+ "doctype": "Dashboard Charts",
+ "name": "Profit and Loss",
"owner": "Administrator",
- "type": "Line"
- },
- {
- "doctype": "Dashboard Chart",
- "time_interval": "Quarterly",
- "name": "Expenses",
- "chart_name": "Expenses",
- "timespan": "Last Year",
- "color": None,
- "filters_json": json.dumps({"company": company.name, "account": expense_account}),
- "source": "Account Balance Timeline",
- "chart_type": "Custom",
- "timeseries": 1,
- "owner": "Administrator",
- "type": "Line"
- },
- {
- "doctype": "Dashboard Chart",
- "time_interval": "Quarterly",
- "name": "Bank Balance",
- "chart_name": "Bank Balance",
- "timespan": "Last Year",
- "color": "#ffb868",
- "filters_json": json.dumps({"company": company.name, "account": bank_account}),
- "source": "Account Balance Timeline",
- "chart_type": "Custom",
- "timeseries": 1,
- "owner": "Administrator",
- "type": "Line"
+ "report_name": "Profit and Loss Statement",
+ "filters_json": json.dumps({
+ "company": company.name,
+ "filter_based_on": "Date Range",
+ "period_start_date": get_date_str(fiscal_year[1]),
+ "period_end_date": get_date_str(fiscal_year[2]),
+ "periodicity": "Monthly",
+ "include_default_book_entries": 1
+ }),
+ "type": "Bar",
+ 'timeseries': 0,
+ "chart_type": "Report",
+ "chart_name": _("Profit and Loss"),
+ "is_custom": 1,
+ "is_public": 1
},
{
"doctype": "Dashboard Chart",
"time_interval": "Monthly",
"name": "Incoming Bills (Purchase Invoice)",
- "chart_name": "Incoming Bills (Purchase Invoice)",
+ "chart_name": _("Incoming Bills (Purchase Invoice)"),
"timespan": "Last Year",
"color": "#a83333",
- "value_based_on": "base_grand_total",
- "filters_json": json.dumps({}),
+ "value_based_on": "base_net_total",
+ "filters_json": json.dumps({"docstatus": 1}),
"chart_type": "Sum",
"timeseries": 1,
"based_on": "posting_date",
"owner": "Administrator",
"document_type": "Purchase Invoice",
- "type": "Bar"
+ "type": "Bar",
+ "width": "Half",
+ "is_public": 1
},
{
"doctype": "Dashboard Chart",
- "time_interval": "Monthly",
"name": "Outgoing Bills (Sales Invoice)",
- "chart_name": "Outgoing Bills (Sales Invoice)",
+ "time_interval": "Monthly",
+ "chart_name": _("Outgoing Bills (Sales Invoice)"),
"timespan": "Last Year",
"color": "#7b933d",
- "value_based_on": "base_grand_total",
- "filters_json": json.dumps({}),
+ "value_based_on": "base_net_total",
+ "filters_json": json.dumps({"docstatus": 1}),
"chart_type": "Sum",
"timeseries": 1,
"based_on": "posting_date",
"owner": "Administrator",
"document_type": "Sales Invoice",
- "type": "Bar"
- }
+ "type": "Bar",
+ "width": "Half",
+ "is_public": 1
+ },
+ {
+ "doctype": "Dashboard Charts",
+ "name": "Accounts Receivable Ageing",
+ "owner": "Administrator",
+ "report_name": "Accounts Receivable",
+ "filters_json": json.dumps({
+ "company": company.name,
+ "report_date": nowdate(),
+ "ageing_based_on": "Due Date",
+ "range1": 30,
+ "range2": 60,
+ "range3": 90,
+ "range4": 120
+ }),
+ "type": "Donut",
+ 'timeseries': 0,
+ "chart_type": "Report",
+ "chart_name": _("Accounts Receivable Ageing"),
+ "is_custom": 1,
+ "is_public": 1
+ },
+ {
+ "doctype": "Dashboard Charts",
+ "name": "Accounts Payable Ageing",
+ "owner": "Administrator",
+ "report_name": "Accounts Payable",
+ "filters_json": json.dumps({
+ "company": company.name,
+ "report_date": nowdate(),
+ "ageing_based_on": "Due Date",
+ "range1": 30,
+ "range2": 60,
+ "range3": 90,
+ "range4": 120
+ }),
+ "type": "Donut",
+ 'timeseries': 0,
+ "chart_type": "Report",
+ "chart_name": _("Accounts Payable Ageing"),
+ "is_custom": 1,
+ "is_public": 1
+ },
+ {
+ "doctype": "Dashboard Charts",
+ "name": "Budget Variance",
+ "owner": "Administrator",
+ "report_name": "Budget Variance Report",
+ "filters_json": json.dumps({
+ "company": company.name,
+ "from_fiscal_year": fiscal_year[0],
+ "to_fiscal_year": fiscal_year[0],
+ "period": "Monthly",
+ "budget_against": "Cost Center"
+ }),
+ "type": "Bar",
+ "timeseries": 0,
+ "chart_type": "Report",
+ "chart_name": _("Budget Variance"),
+ "is_custom": 1,
+ "is_public": 1
+ },
+ {
+ "doctype": "Dashboard Charts",
+ "name": "Bank Balance",
+ "time_interval": "Quarterly",
+ "chart_name": "Bank Balance",
+ "timespan": "Last Year",
+ "filters_json": json.dumps({
+ "company": company.name,
+ "account": bank_account
+ }),
+ "source": "Account Balance Timeline",
+ "chart_type": "Custom",
+ "timeseries": 1,
+ "owner": "Administrator",
+ "type": "Line",
+ "width": "Half",
+ "is_public": 1
+ },
]
-def get_account(account_type, company):
- accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
- if accounts:
- return accounts[0].name
-
-def get_company_for_dashboards():
- company = get_default_company()
- if not company:
- company_list = frappe.get_list("Company")
- if company_list:
- company = company_list[0].name
- return company
+def get_number_cards():
+ fiscal_year = get_fiscal_year(date=nowdate())
+ year_start_date = get_date_str(fiscal_year[1])
+ year_end_date = get_date_str(fiscal_year[2])
+ return [
+ {
+ "doctype": "Number Card",
+ "document_type": "Payment Entry",
+ "name": "Total Incoming Payment",
+ "filters_json": json.dumps([
+ ['Payment Entry', 'docstatus', '=', 1],
+ ['Payment Entry', 'posting_date', 'between', [year_start_date, year_end_date]],
+ ['Payment Entry', 'payment_type', '=', 'Receive']
+ ]),
+ "label": _("Total Incoming Payment"),
+ "function": "Sum",
+ "aggregate_function_based_on": "base_received_amount",
+ "is_public": 1,
+ "is_custom": 1,
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Monthly"
+ },
+ {
+ "doctype": "Number Card",
+ "document_type": "Payment Entry",
+ "name": "Total Outgoing Payment",
+ "filters_json": json.dumps([
+ ['Payment Entry', 'docstatus', '=', 1],
+ ['Payment Entry', 'posting_date', 'between', [year_start_date, year_end_date]],
+ ['Payment Entry', 'payment_type', '=', 'Pay']
+ ]),
+ "label": _("Total Outgoing Payment"),
+ "function": "Sum",
+ "aggregate_function_based_on": "base_paid_amount",
+ "is_public": 1,
+ "is_custom": 1,
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Monthly"
+ },
+ {
+ "doctype": "Number Card",
+ "document_type": "Sales Invoice",
+ "name": "Total Outgoing Bills",
+ "filters_json": json.dumps([
+ ['Sales Invoice', 'docstatus', '=', 1],
+ ['Sales Invoice', 'posting_date', 'between', [year_start_date, year_end_date]]
+ ]),
+ "label": _("Total Outgoing Bills"),
+ "function": "Sum",
+ "aggregate_function_based_on": "base_net_total",
+ "is_public": 1,
+ "is_custom": 1,
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Monthly"
+ },
+ {
+ "doctype": "Number Card",
+ "document_type": "Purchase Invoice",
+ "name": "Total Incoming Bills",
+ "filters_json": json.dumps([
+ ['Purchase Invoice', 'docstatus', '=', 1],
+ ['Purchase Invoice', 'posting_date', 'between', [year_start_date, year_end_date]]
+ ]),
+ "label": _("Total Incoming Bills"),
+ "function": "Sum",
+ "aggregate_function_based_on": "base_net_total",
+ "is_public": 1,
+ "is_custom": 1,
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Monthly"
+ }
+ ]
diff --git a/erpnext/accounts/desk_page/accounting/accounting.json b/erpnext/accounts/desk_page/accounting/accounting.json
index 0d6aca6..a783b1d 100644
--- a/erpnext/accounts/desk_page/accounting/accounting.json
+++ b/erpnext/accounts/desk_page/accounting/accounting.json
@@ -47,11 +47,6 @@
},
{
"hidden": 0,
- "links": "[\n {\n \"description\": \"Match non-linked Invoices and Payments.\",\n \"label\": \"Match Payments with Invoices\",\n \"name\": \"Payment Reconciliation\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Update bank payment dates with journals.\",\n \"label\": \"Update Bank Clearance Dates\",\n \"name\": \"Bank Clearance\",\n \"type\": \"doctype\"\n },\n {\n \"label\": \"Invoice Discounting\",\n \"name\": \"Invoice Discounting\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Journal Entry\"\n ],\n \"doctype\": \"Journal Entry\",\n \"is_query_report\": true,\n \"label\": \"Bank Reconciliation Statement\",\n \"name\": \"Bank Reconciliation Statement\",\n \"type\": \"report\"\n },\n {\n \"icon\": \"fa fa-bar-chart\",\n \"label\": \"Bank Reconciliation\",\n \"name\": \"bank-reconciliation\",\n \"type\": \"page\"\n },\n {\n \"dependencies\": [\n \"Journal Entry\"\n ],\n \"doctype\": \"Journal Entry\",\n \"is_query_report\": true,\n \"label\": \"Bank Clearance Summary\",\n \"name\": \"Bank Clearance Summary\",\n \"type\": \"report\"\n },\n {\n \"label\": \"Bank Guarantee\",\n \"name\": \"Bank Guarantee\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Setup cheque dimensions for printing\",\n \"label\": \"Cheque Print Template\",\n \"name\": \"Cheque Print Template\",\n \"type\": \"doctype\"\n }\n]",
- "title": "Banking and Payments"
- },
- {
- "hidden": 0,
"label": "Subscription Management",
"links": "[\n {\n \"label\": \"Subscription Plan\",\n \"name\": \"Subscription Plan\",\n \"type\": \"doctype\"\n },\n {\n \"label\": \"Subscription\",\n \"name\": \"Subscription\",\n \"type\": \"doctype\"\n },\n {\n \"label\": \"Subscription Settings\",\n \"name\": \"Subscription Settings\",\n \"type\": \"doctype\"\n }\n]"
},
@@ -89,8 +84,8 @@
"category": "Modules",
"charts": [
{
- "chart_name": "Bank Balance",
- "label": "Bank Balance"
+ "chart_name": "Profit and Loss",
+ "label": "Profit and Loss"
}
],
"creation": "2020-03-02 15:41:59.515192",
@@ -99,24 +94,39 @@
"docstatus": 0,
"doctype": "Desk Page",
"extends_another_page": 0,
- "icon": "",
"idx": 0,
"is_standard": 1,
"label": "Accounting",
- "modified": "2020-04-29 12:17:34.844397",
+ "modified": "2020-05-18 17:27:26.882340",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounting",
+ "onboarding": "Accounts",
"owner": "Administrator",
"pin_to_bottom": 0,
"pin_to_top": 0,
"shortcuts": [
{
- "label": "Account",
+ "label": "Chart Of Accounts",
"link_to": "Account",
"type": "DocType"
},
{
+ "label": "Sales Invoice",
+ "link_to": "Sales Invoice",
+ "type": "DocType"
+ },
+ {
+ "label": "Purchase Invoice",
+ "link_to": "Purchase Invoice",
+ "type": "DocType"
+ },
+ {
+ "label": "Accounts Dashboard",
+ "link_to": "Accounts Dashboard",
+ "type": "Dashboard"
+ },
+ {
"label": "Journal Entry",
"link_to": "Journal Entry",
"type": "DocType"
@@ -137,11 +147,6 @@
"type": "Report"
},
{
- "label": "Profit and Loss Statement",
- "link_to": "Profit and Loss Statement",
- "type": "Report"
- },
- {
"label": "Trial Balance",
"link_to": "Trial Balance",
"type": "Report"
diff --git a/erpnext/accounts/module_onboarding/accounts/accounts.json b/erpnext/accounts/module_onboarding/accounts/accounts.json
new file mode 100644
index 0000000..12da440
--- /dev/null
+++ b/erpnext/accounts/module_onboarding/accounts/accounts.json
@@ -0,0 +1,51 @@
+{
+ "allow_roles": [
+ {
+ "role": "Accounts Manager"
+ },
+ {
+ "role": "Accounts User"
+ }
+ ],
+ "creation": "2020-05-13 19:03:32.564049",
+ "docstatus": 0,
+ "doctype": "Module Onboarding",
+ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/accounts",
+ "idx": 0,
+ "is_complete": 0,
+ "modified": "2020-05-14 22:11:06.475938",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Accounts",
+ "owner": "Administrator",
+ "steps": [
+ {
+ "step": "Chart Of Accounts"
+ },
+ {
+ "step": "Setup Taxes"
+ },
+ {
+ "step": "Create a Product"
+ },
+ {
+ "step": "Create a Supplier"
+ },
+ {
+ "step": "Create Your First Purchase Invoice"
+ },
+ {
+ "step": "Create a Customer"
+ },
+ {
+ "step": "Create Your First Sales Invoice"
+ },
+ {
+ "step": "Configure Account Settings"
+ }
+ ],
+ "subtitle": "Accounts, invoices and taxation.",
+ "success_message": "The Accounts module is now set up!",
+ "title": "Let's Setup Your Accounts and Taxes.",
+ "user_can_dismiss": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/chart_of_accounts/chart_of_accounts.json b/erpnext/accounts/onboarding_step/chart_of_accounts/chart_of_accounts.json
new file mode 100644
index 0000000..cbd022b
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/chart_of_accounts/chart_of_accounts.json
@@ -0,0 +1,20 @@
+{
+ "action": "Go to Page",
+ "creation": "2020-05-13 19:58:20.928127",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 17:40:28.410447",
+ "modified_by": "Administrator",
+ "name": "Chart Of Accounts",
+ "owner": "Administrator",
+ "path": "Tree/Account",
+ "reference_document": "Account",
+ "show_full_form": 0,
+ "title": "Review Chart Of Accounts",
+ "validate_action": 0
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/configure_account_settings/configure_account_settings.json b/erpnext/accounts/onboarding_step/configure_account_settings/configure_account_settings.json
new file mode 100644
index 0000000..c8be357
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/configure_account_settings/configure_account_settings.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-14 17:53:00.876946",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 1,
+ "is_skipped": 0,
+ "modified": "2020-05-14 18:06:25.212923",
+ "modified_by": "Administrator",
+ "name": "Configure Account Settings",
+ "owner": "Administrator",
+ "reference_document": "Accounts Settings",
+ "show_full_form": 1,
+ "title": "Configure Account Settings",
+ "validate_action": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/create_a_customer/create_a_customer.json b/erpnext/accounts/onboarding_step/create_a_customer/create_a_customer.json
new file mode 100644
index 0000000..bb396d2
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/create_a_customer/create_a_customer.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-14 17:46:41.831517",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 17:46:41.831517",
+ "modified_by": "Administrator",
+ "name": "Create a Customer",
+ "owner": "Administrator",
+ "reference_document": "Customer",
+ "show_full_form": 0,
+ "title": "Create a Customer",
+ "validate_action": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/create_a_product/create_a_product.json b/erpnext/accounts/onboarding_step/create_a_product/create_a_product.json
new file mode 100644
index 0000000..450bee1
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/create_a_product/create_a_product.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-14 17:45:28.554605",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 17:45:28.554605",
+ "modified_by": "Administrator",
+ "name": "Create a Product",
+ "owner": "Administrator",
+ "reference_document": "Item",
+ "show_full_form": 0,
+ "title": "Create a Product",
+ "validate_action": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/create_a_supplier/create_a_supplier.json b/erpnext/accounts/onboarding_step/create_a_supplier/create_a_supplier.json
new file mode 100644
index 0000000..7a64224
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/create_a_supplier/create_a_supplier.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-14 22:09:10.043554",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 22:09:10.043554",
+ "modified_by": "Administrator",
+ "name": "Create a Supplier",
+ "owner": "Administrator",
+ "reference_document": "Supplier",
+ "show_full_form": 0,
+ "title": "Create a Supplier",
+ "validate_action": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/create_your_first_purchase_invoice/create_your_first_purchase_invoice.json b/erpnext/accounts/onboarding_step/create_your_first_purchase_invoice/create_your_first_purchase_invoice.json
new file mode 100644
index 0000000..3a2b8d3
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/create_your_first_purchase_invoice/create_your_first_purchase_invoice.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-14 22:10:07.049704",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 22:10:07.049704",
+ "modified_by": "Administrator",
+ "name": "Create Your First Purchase Invoice",
+ "owner": "Administrator",
+ "reference_document": "Purchase Invoice",
+ "show_full_form": 1,
+ "title": "Create Your First Purchase Invoice ",
+ "validate_action": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/create_your_first_sales_invoice/create_your_first_sales_invoice.json b/erpnext/accounts/onboarding_step/create_your_first_sales_invoice/create_your_first_sales_invoice.json
new file mode 100644
index 0000000..473de50
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/create_your_first_sales_invoice/create_your_first_sales_invoice.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-14 17:48:21.019019",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 17:48:21.019019",
+ "modified_by": "Administrator",
+ "name": "Create Your First Sales Invoice",
+ "owner": "Administrator",
+ "reference_document": "Sales Invoice",
+ "show_full_form": 1,
+ "title": "Create Your First Sales Invoice ",
+ "validate_action": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/onboarding_step/setup_taxes/setup_taxes.json b/erpnext/accounts/onboarding_step/setup_taxes/setup_taxes.json
new file mode 100644
index 0000000..8e00067
--- /dev/null
+++ b/erpnext/accounts/onboarding_step/setup_taxes/setup_taxes.json
@@ -0,0 +1,19 @@
+{
+ "action": "Create Entry",
+ "creation": "2020-05-13 19:29:43.844463",
+ "docstatus": 0,
+ "doctype": "Onboarding Step",
+ "idx": 0,
+ "is_complete": 0,
+ "is_mandatory": 0,
+ "is_single": 0,
+ "is_skipped": 0,
+ "modified": "2020-05-14 17:40:16.014413",
+ "modified_by": "Administrator",
+ "name": "Setup Taxes",
+ "owner": "Administrator",
+ "reference_document": "Sales Taxes and Charges Template",
+ "show_full_form": 1,
+ "title": "Lets create a Tax Template for Sales ",
+ "validate_action": 0
+}
\ No newline at end of file
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index e9c286f..a0a1b97 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -546,7 +546,7 @@
self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4 = 30, 60, 90, 120
for i, days in enumerate([self.filters.range1, self.filters.range2, self.filters.range3, self.filters.range4]):
- if row.age <= days:
+ if cint(row.age) <= cint(days):
index = i
break
diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
index 49c1d0f..05dc282 100644
--- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
+++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py
@@ -56,14 +56,26 @@
row += totals
data.append(row)
- return columns, data
+ chart = get_chart_data(filters, columns, data)
+ return columns, data, None, chart
def get_columns(filters):
columns = [
- _(filters.get("budget_against"))
- + ":Link/%s:150" % (filters.get("budget_against")),
- _("Account") + ":Link/Account:150"
+ {
+ 'label': _(filters.get("budget_against")),
+ 'fieldtype': 'Link',
+ 'fieldname': 'budget_against',
+ 'options': filters.get('budget_against'),
+ 'width': 150
+ },
+ {
+ 'label': _('Account'),
+ 'fieldname': 'Account',
+ 'fieldtype': 'Link',
+ 'options': 'Account',
+ 'width': 150
+ }
]
group_months = False if filters["period"] == "Monthly" else True
@@ -79,7 +91,12 @@
_("Variance ") + " " + str(year[0])
]
for label in labels:
- columns.append(label + ":Float:150")
+ columns.append({
+ 'label': label,
+ 'fieldtype': 'Float',
+ 'fieldname': frappe.scrub(label),
+ 'width': 150
+ })
else:
for label in [
_("Budget") + " (%s)" + " " + str(year[0]),
@@ -95,14 +112,23 @@
else:
label = label % formatdate(from_date, format_string="MMM")
- columns.append(label + ":Float:150")
+ columns.append({
+ 'label': label,
+ 'fieldtype': 'Float',
+ 'fieldname': frappe.scrub(label),
+ 'width': 150
+ })
if filters["period"] != "Yearly":
- return columns + [
- _("Total Budget") + ":Float:150",
- _("Total Actual") + ":Float:150",
- _("Total Variance") + ":Float:150"
- ]
+ for label in [_("Total Budget"), _("Total Actual"), _("Total Variance")]:
+ columns.append({
+ 'label': label,
+ 'fieldtype': 'Float',
+ 'fieldname': frappe.scrub(label),
+ 'width': 150
+ })
+
+ return columns
else:
return columns
@@ -173,7 +199,7 @@
filters.budget_against,
filters.company,
]
- + filters.get("budget_against_filter")
+ + (filters.get("budget_against_filter") or [])
), as_dict=True)
@@ -305,3 +331,49 @@
})
return fiscal_year
+
+def get_chart_data(filters, columns, data):
+
+ if not data:
+ return None
+
+ labels = []
+
+ fiscal_year = get_fiscal_years(filters)
+ group_months = False if filters["period"] == "Monthly" else True
+
+ for year in fiscal_year:
+ for from_date, to_date in get_period_date_ranges(filters["period"], year[0]):
+ if filters['period'] == 'Yearly':
+ labels.append(year[0])
+ else:
+ if group_months:
+ label = formatdate(from_date, format_string="MMM") + "-" \
+ + formatdate(to_date, format_string="MMM")
+ labels.append(label)
+ else:
+ label = formatdate(from_date, format_string="MMM")
+ labels.append(label)
+
+ no_of_columns = len(labels)
+
+ budget_values, actual_values = [0] * no_of_columns, [0] * no_of_columns
+ for d in data:
+ values = d[2:]
+ index = 0
+
+ for i in range(no_of_columns):
+ budget_values[i] += values[index]
+ actual_values[i] += values[index+1]
+ index += 3
+
+ return {
+ 'data': {
+ 'labels': labels,
+ 'datasets': [
+ {'name': 'Budget', 'chartType': 'bar', 'values': budget_values},
+ {'name': 'Actual Expense', 'chartType': 'bar', 'values': actual_values}
+ ]
+ }
+ }
+
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 5febfd6..5fbc460 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -8,11 +8,14 @@
from frappe.utils import nowdate, getdate
from collections import defaultdict
from erpnext.stock.get_item_details import _get_item_tax_template
+from frappe.utils import unique
# searches for active employees
def employee_query(doctype, txt, searchfield, start, page_len, filters):
conditions = []
- return frappe.db.sql("""select name, employee_name from `tabEmployee`
+ fields = get_fields("Employee", ["name", "employee_name"])
+
+ return frappe.db.sql("""select {fields} from `tabEmployee`
where status = 'Active'
and docstatus < 2
and ({key} like %(txt)s
@@ -24,6 +27,7 @@
idx desc,
name, employee_name
limit %(start)s, %(page_len)s""".format(**{
+ 'fields': ", ".join(fields),
'key': searchfield,
'fcond': get_filters_cond(doctype, filters, conditions),
'mcond': get_match_cond(doctype)
@@ -34,9 +38,12 @@
'page_len': page_len
})
- # searches for leads which are not converted
+
+# searches for leads which are not converted
def lead_query(doctype, txt, searchfield, start, page_len, filters):
- return frappe.db.sql("""select name, lead_name, company_name from `tabLead`
+ fields = get_fields("Lead", ["name", "lead_name", "company_name"])
+
+ return frappe.db.sql("""select {fields} from `tabLead`
where docstatus < 2
and ifnull(status, '') != 'Converted'
and ({key} like %(txt)s
@@ -50,6 +57,7 @@
idx desc,
name, lead_name
limit %(start)s, %(page_len)s""".format(**{
+ 'fields': ", ".join(fields),
'key': searchfield,
'mcond':get_match_cond(doctype)
}), {
@@ -59,6 +67,7 @@
'page_len': page_len
})
+
# searches for customer
def customer_query(doctype, txt, searchfield, start, page_len, filters):
conditions = []
@@ -69,13 +78,9 @@
else:
fields = ["name", "customer_name", "customer_group", "territory"]
- meta = frappe.get_meta("Customer")
- searchfields = meta.get_search_fields()
- searchfields = searchfields + [f for f in [searchfield or "name", "customer_name"] \
- if not f in searchfields]
- fields = fields + [f for f in searchfields if not f in fields]
+ fields = get_fields("Customer", fields)
- fields = ", ".join(fields)
+ searchfields = frappe.get_meta("Customer").get_search_fields()
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
return frappe.db.sql("""select {fields} from `tabCustomer`
@@ -88,7 +93,7 @@
idx desc,
name, customer_name
limit %(start)s, %(page_len)s""".format(**{
- "fields": fields,
+ "fields": ", ".join(fields),
"scond": searchfields,
"mcond": get_match_cond(doctype),
"fcond": get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
@@ -99,6 +104,7 @@
'page_len': page_len
})
+
# searches for supplier
def supplier_query(doctype, txt, searchfield, start, page_len, filters):
supp_master_name = frappe.defaults.get_user_default("supp_master_name")
@@ -106,7 +112,8 @@
fields = ["name", "supplier_group"]
else:
fields = ["name", "supplier_name", "supplier_group"]
- fields = ", ".join(fields)
+
+ fields = get_fields("Supplier", fields)
return frappe.db.sql("""select {field} from `tabSupplier`
where docstatus < 2
@@ -119,7 +126,7 @@
idx desc,
name, supplier_name
limit %(start)s, %(page_len)s """.format(**{
- 'field': fields,
+ 'field': ', '.join(fields),
'key': searchfield,
'mcond':get_match_cond(doctype)
}), {
@@ -129,6 +136,7 @@
'page_len': page_len
})
+
def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
company_currency = erpnext.get_company_currency(filters.get('company'))
@@ -153,6 +161,7 @@
return tax_accounts
+
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
conditions = []
@@ -221,10 +230,12 @@
"page_len": page_len
}, as_dict=as_dict)
+
def bom(doctype, txt, searchfield, start, page_len, filters):
conditions = []
+ fields = get_fields("BOM", ["name", "item"])
- return frappe.db.sql("""select tabBOM.name, tabBOM.item
+ return frappe.db.sql("""select {fields}
from tabBOM
where tabBOM.docstatus=1
and tabBOM.is_active=1
@@ -234,6 +245,7 @@
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
idx desc, name
limit %(start)s, %(page_len)s """.format(
+ fields=", ".join(fields),
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
mcond=get_match_cond(doctype).replace('%', '%%'),
key=searchfield),
@@ -244,13 +256,16 @@
'page_len': page_len or 20
})
+
def get_project_name(doctype, txt, searchfield, start, page_len, filters):
cond = ''
if filters.get('customer'):
cond = """(`tabProject`.customer = %s or
ifnull(`tabProject`.customer,"")="") and""" %(frappe.db.escape(filters.get("customer")))
- return frappe.db.sql("""select `tabProject`.name from `tabProject`
+ fields = get_fields("Project", ["name"])
+
+ return frappe.db.sql("""select {fields} from `tabProject`
where `tabProject`.status not in ("Completed", "Cancelled")
and {cond} `tabProject`.name like %(txt)s {match_cond}
order by
@@ -258,6 +273,7 @@
idx desc,
`tabProject`.name asc
limit {start}, {page_len}""".format(
+ fields=", ".join(['`tabProject`.{0}'.format(f) for f in fields]),
cond=cond,
match_cond=get_match_cond(doctype),
start=start,
@@ -268,8 +284,10 @@
def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, filters, as_dict):
+ fields = get_fields("Delivery Note", ["name", "customer", "posting_date"])
+
return frappe.db.sql("""
- select `tabDelivery Note`.name, `tabDelivery Note`.customer, `tabDelivery Note`.posting_date
+ select %(fields)s
from `tabDelivery Note`
where `tabDelivery Note`.`%(key)s` like %(txt)s and
`tabDelivery Note`.docstatus = 1
@@ -284,6 +302,7 @@
)
%(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(start)s, %(page_len)s
""" % {
+ "fields": ", ".join(["`tabDelivery Note`.{0}".format(f) for f in fields]),
"key": searchfield,
"fcond": get_filters_cond(doctype, filters, []),
"mcond": get_match_cond(doctype),
@@ -349,6 +368,7 @@
order by expiry_date, name desc
limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args)
+
def get_account_list(doctype, txt, searchfield, start, page_len, filters):
filter_list = []
@@ -371,6 +391,7 @@
fields = ["name", "parent_account"],
limit_start=start, limit_page_length=page_len, as_list=True)
+
def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date
from `tabBlanket Order` bo, `tabBlanket Order Item` boi
@@ -385,6 +406,7 @@
company = frappe.db.escape(filters.get("company"))
))
+
@frappe.whitelist()
def get_income_account(doctype, txt, searchfield, start, page_len, filters):
from erpnext.controllers.queries import get_match_cond
@@ -490,6 +512,7 @@
return frappe.db.sql(query, filters)
+
@frappe.whitelist()
def item_manufacturer_query(doctype, txt, searchfield, start, page_len, filters):
item_filters = [
@@ -507,6 +530,7 @@
)
return item_manufacturers
+
@frappe.whitelist()
def get_purchase_receipts(doctype, txt, searchfield, start, page_len, filters):
query = """
@@ -520,6 +544,7 @@
return frappe.db.sql(query, filters)
+
@frappe.whitelist()
def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters):
query = """
@@ -533,6 +558,7 @@
return frappe.db.sql(query, filters)
+
@frappe.whitelist()
def get_tax_template(doctype, txt, searchfield, start, page_len, filters):
@@ -556,3 +582,13 @@
taxes = _get_item_tax_template(args, taxes, for_validate=True)
return [(d,) for d in set(taxes)]
+
+
+def get_fields(doctype, fields=[]):
+ meta = frappe.get_meta(doctype)
+ fields.extend(meta.get_search_fields())
+
+ if meta.title_field and not meta.title_field.strip() in fields:
+ fields.insert(1, meta.title_field.strip())
+
+ return unique(fields)
diff --git a/erpnext/manufacturing/dashboard_fixtures.py b/erpnext/manufacturing/dashboard_fixtures.py
index 3029f48..587a032 100644
--- a/erpnext/manufacturing/dashboard_fixtures.py
+++ b/erpnext/manufacturing/dashboard_fixtures.py
@@ -3,6 +3,8 @@
import frappe, erpnext, json
from frappe import _
+from frappe.utils import nowdate, get_date_str
+from erpnext.accounts.utils import get_fiscal_year
def get_data():
return frappe._dict({
@@ -41,19 +43,19 @@
return [{
"doctype": "Dashboard Chart",
- "based_on": "creation",
+ "based_on": "modified",
"time_interval": "Yearly",
"chart_type": "Sum",
- "chart_name": "Produced Quantity",
+ "chart_name": _("Produced Quantity"),
"name": "Produced Quantity",
"document_type": "Work Order",
- "filters_json": json.dumps({}),
+ "filters_json": json.dumps([['Work Order', 'docstatus', '=', 1, False]]),
"group_by_type": "Count",
- "time_interval": "Quarterly",
+ "time_interval": "Monthly",
"timespan": "Last Year",
"owner": "Administrator",
"type": "Line",
- "value_based_on": "qty",
+ "value_based_on": "produced_qty",
"is_public": 1,
"timeseries": 1
}, {
@@ -61,10 +63,10 @@
"based_on": "creation",
"time_interval": "Yearly",
"chart_type": "Sum",
- "chart_name": "Completed Operation",
+ "chart_name": _("Completed Operation"),
"name": "Completed Operation",
"document_type": "Work Order Operation",
- "filters_json": json.dumps({}),
+ "filters_json": json.dumps([['Work Order Operation', 'docstatus', '=', 1, False]]),
"group_by_type": "Count",
"time_interval": "Quarterly",
"timespan": "Last Year",
@@ -77,7 +79,7 @@
"doctype": "Dashboard Chart",
"time_interval": "Yearly",
"chart_type": "Report",
- "chart_name": "Work Order Analysis",
+ "chart_name": _("Work Order Analysis"),
"name": "Work Order Analysis",
"timespan": "Last Year",
"report_name": "Work Order Summary",
@@ -96,7 +98,7 @@
"doctype": "Dashboard Chart",
"time_interval": "Yearly",
"chart_type": "Report",
- "chart_name": "Quality Inspection Analysis",
+ "chart_name": _("Quality Inspection Analysis"),
"name": "Quality Inspection Analysis",
"timespan": "Last Year",
"report_name": "Quality Inspection Summary",
@@ -115,7 +117,7 @@
"doctype": "Dashboard Chart",
"time_interval": "Yearly",
"chart_type": "Report",
- "chart_name": "Pending Work Order",
+ "chart_name": _("Pending Work Order"),
"name": "Pending Work Order",
"timespan": "Last Year",
"report_name": "Work Order Summary",
@@ -134,7 +136,7 @@
"doctype": "Dashboard Chart",
"time_interval": "Yearly",
"chart_type": "Report",
- "chart_name": "Last Month Downtime Analysis",
+ "chart_name": _("Last Month Downtime Analysis"),
"name": "Last Month Downtime Analysis",
"timespan": "Last Year",
"filters_json": json.dumps({}),
@@ -148,7 +150,7 @@
"time_interval": "Yearly",
"chart_type": "Report",
"chart_name": _("Work Order Qty Analysis"),
- "name": _("Work Order Qty Analysis"),
+ "name": "Work Order Qty Analysis",
"timespan": "Last Year",
"report_name": "Work Order Summary",
"filters_json": json.dumps({"company": company, "charts_based_on": "Quantity"}),
@@ -163,14 +165,14 @@
"doctype": "Dashboard Chart",
"time_interval": "Yearly",
"chart_type": "Report",
- "chart_name": "Job Card Analysis",
+ "chart_name": _("Job Card Analysis"),
"name": "Job Card Analysis",
"timespan": "Last Year",
"report_name": "Job Card Summary",
"owner": "Administrator",
"is_public": 1,
"is_custom": 1,
- "filters_json": json.dumps({"company": company, "range":"Monthly"}),
+ "filters_json": json.dumps({"company": company, "docstatus": 1, "range":"Monthly"}),
"custom_options": json.dumps({
"barOptions": { "stacked": 1 }
}),
@@ -178,47 +180,61 @@
}]
def get_number_cards():
+ fiscal_year = get_fiscal_year(date=nowdate())
+ year_start_date = get_date_str(fiscal_year[1])
+ year_end_date = get_date_str(fiscal_year[2])
+
return [{
"doctype": "Number Card",
"document_type": "Work Order",
"name": "Total Work Order",
- "filters_json": json.dumps([]),
+ "filters_json": json.dumps([
+ ['Work Order', 'docstatus', '=', 1],
+ ['Work Order', 'creation', 'between', [year_start_date, year_end_date]]
+ ]),
"function": "Count",
"is_public": 1,
"label": _("Total Work Order"),
"show_percentage_stats": 1,
- "stats_time_interval": "Daily"
+ "stats_time_interval": "Monthly"
},
{
"doctype": "Number Card",
"document_type": "Work Order",
"name": "Completed Work Order",
- "filters_json": json.dumps([['Work Order', 'status','=','Completed', False]]),
+ "filters_json": json.dumps([
+ ['Work Order', 'status', '=', 'Completed'],
+ ['Work Order', 'docstatus', '=', 1],
+ ['Work Order', 'creation', 'between', [year_start_date, year_end_date]]
+ ]),
"function": "Count",
"is_public": 1,
"label": _("Completed Work Order"),
"show_percentage_stats": 1,
- "stats_time_interval": "Daily"
+ "stats_time_interval": "Monthly"
},
{
"doctype": "Number Card",
"document_type": "Job Card",
"name": "Ongoing Job Card",
- "filters_json": json.dumps([['Job Card', 'status','!=','Completed', False]]),
+ "filters_json": json.dumps([
+ ['Job Card', 'status','!=','Completed'],
+ ['Job Card', 'docstatus', '=', 1]
+ ]),
"function": "Count",
"is_public": 1,
"label": _("Ongoing Job Card"),
"show_percentage_stats": 1,
- "stats_time_interval": "Daily"
+ "stats_time_interval": "Monthly"
},
{
"doctype": "Number Card",
"document_type": "Quality Inspection",
"name": "Total Quality Inspection",
- "filters_json": json.dumps([]),
+ "filters_json": json.dumps([['Quality Inspection', 'docstatus', '=', 1]]),
"function": "Count",
"is_public": 1,
"label": _("Total Quality Inspection"),
"show_percentage_stats": 1,
- "stats_time_interval": "Daily"
+ "stats_time_interval": "Monthly"
}]
\ No newline at end of file
diff --git a/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json b/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json
index 6288169..c181d5d 100644
--- a/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json
+++ b/erpnext/manufacturing/desk_page/manufacturing/manufacturing.json
@@ -43,10 +43,11 @@
"docstatus": 0,
"doctype": "Desk Page",
"extends_another_page": 0,
+ "hide_custom": 0,
"idx": 0,
"is_standard": 1,
"label": "Manufacturing",
- "modified": "2020-05-14 18:57:26.810652",
+ "modified": "2020-05-19 12:06:25.047481",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Manufacturing",
@@ -95,10 +96,10 @@
"type": "Report"
},
{
- "label": "BOM Stock Report",
- "link_to": "BOM Stock Report",
+ "label": "Manufacturing Dashboard",
+ "link_to": "Manufacturing Dashboard",
"restrict_to_domain": "Manufacturing",
- "type": "Report"
+ "type": "Dashboard"
}
]
}
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index ebfb762..44da9ca 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -212,6 +212,12 @@
});
},
+ rm_cost_as_per: function(frm) {
+ if (in_list(["Valuation Rate", "Last Purchase Rate"], frm.doc.rm_cost_as_per)) {
+ frm.set_value("plc_conversion_rate", 1.0);
+ }
+ },
+
routing: function(frm) {
if (frm.doc.routing) {
frappe.call({
@@ -242,7 +248,7 @@
item_code: function(doc, cdt, cdn){
var scrap_items = false;
var child = locals[cdt][cdn];
- if(child.doctype == 'BOM Scrap Item') {
+ if (child.doctype == 'BOM Scrap Item') {
scrap_items = true;
}
@@ -252,8 +258,19 @@
get_bom_material_detail(doc, cdt, cdn, scrap_items);
},
+
+ buying_price_list: function(doc) {
+ this.apply_price_list();
+ },
+
+ plc_conversion_rate: function(doc) {
+ if (!this.in_apply_price_list) {
+ this.apply_price_list();
+ }
+ },
+
conversion_factor: function(doc, cdt, cdn) {
- if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
+ if (frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json
index 63f4f97..4ce0ecf 100644
--- a/erpnext/manufacturing/doctype/bom/bom.json
+++ b/erpnext/manufacturing/doctype/bom/bom.json
@@ -1,4 +1,5 @@
{
+ "actions": [],
"allow_import": 1,
"creation": "2013-01-22 15:11:38",
"doctype": "DocType",
@@ -6,23 +7,25 @@
"engine": "InnoDB",
"field_order": [
"item",
- "quantity",
- "set_rate_of_sub_assembly_item_based_on_bom",
+ "company",
+ "item_name",
+ "uom",
"cb0",
"is_active",
"is_default",
"allow_alternative_item",
- "image",
- "item_name",
- "uom",
- "currency_detail",
- "company",
+ "set_rate_of_sub_assembly_item_based_on_bom",
"project",
+ "quantity",
+ "image",
+ "currency_detail",
+ "currency",
"conversion_rate",
"column_break_12",
- "currency",
"rm_cost_as_per",
"buying_price_list",
+ "price_list_currency",
+ "plc_conversion_rate",
"section_break_21",
"with_operations",
"column_break_23",
@@ -176,7 +179,8 @@
},
{
"fieldname": "currency_detail",
- "fieldtype": "Section Break"
+ "fieldtype": "Section Break",
+ "label": "Currency and Price List"
},
{
"fieldname": "company",
@@ -324,7 +328,7 @@
},
{
"fieldname": "base_scrap_material_cost",
- "fieldtype": "Data",
+ "fieldtype": "Currency",
"label": "Scrap Material Cost(Company Currency)",
"no_copy": 1,
"options": "Company:company:default_currency",
@@ -477,13 +481,31 @@
{
"fieldname": "column_break_52",
"fieldtype": "Column Break"
+ },
+ {
+ "allow_on_submit": 1,
+ "depends_on": "eval:doc.rm_cost_as_per=='Price List'",
+ "fieldname": "plc_conversion_rate",
+ "fieldtype": "Float",
+ "label": "Price List Exchange Rate"
+ },
+ {
+ "allow_on_submit": 1,
+ "depends_on": "eval:doc.rm_cost_as_per=='Price List'",
+ "fieldname": "price_list_currency",
+ "fieldtype": "Link",
+ "label": "Price List Currency",
+ "options": "Currency",
+ "print_hide": 1,
+ "read_only": 1
}
],
"icon": "fa fa-sitemap",
"idx": 1,
"image_field": "image",
"is_submittable": 1,
- "modified": "2019-11-22 14:35:12.142150",
+ "links": [],
+ "modified": "2020-05-05 14:29:32.634952",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM",
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index b1fc4de..6ac653e 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -70,11 +70,13 @@
self.validate_main_item()
self.validate_currency()
self.set_conversion_rate()
+ self.set_plc_conversion_rate()
self.validate_uom_is_interger()
self.set_bom_material_details()
self.validate_materials()
self.validate_operations()
self.calculate_cost()
+ self.update_cost(update_parent=False, from_child_bom=True, save=False)
def get_context(self, context):
context.parents = [{'name': 'boms', 'title': _('All BOMs') }]
@@ -165,7 +167,7 @@
'rate' : rate,
'qty' : args.get("qty") or args.get("stock_qty") or 1,
'stock_qty' : args.get("qty") or args.get("stock_qty") or 1,
- 'base_rate' : rate,
+ 'base_rate' : flt(rate) * (flt(self.conversion_rate) or 1),
'include_item_in_manufacturing': cint(args['transfer_for_manufacture']) or 0
}
@@ -226,7 +228,7 @@
frappe.msgprint(_("{0} not found for item {1}")
.format(self.rm_cost_as_per, arg["item_code"]), alert=True)
- return flt(rate) / (self.conversion_rate or 1)
+ return flt(rate) * flt(self.plc_conversion_rate or 1) / (self.conversion_rate or 1)
def update_cost(self, update_parent=True, from_child_bom=False, save=True):
if self.docstatus == 2:
@@ -243,10 +245,15 @@
"stock_uom": d.stock_uom,
"conversion_factor": d.conversion_factor
})
+
if rate:
d.rate = rate
d.amount = flt(d.rate) * flt(d.qty)
- d.db_update()
+ d.base_rate = flt(d.rate) * flt(self.conversion_rate)
+ d.base_amount = flt(d.amount) * flt(self.conversion_rate)
+
+ if save:
+ d.db_update()
if self.docstatus == 1:
self.flags.ignore_validate_update_after_submit = True
@@ -372,6 +379,13 @@
elif self.conversion_rate == 1 or flt(self.conversion_rate) <= 0:
self.conversion_rate = get_exchange_rate(self.currency, self.company_currency(), args="for_buying")
+ def set_plc_conversion_rate(self):
+ if self.rm_cost_as_per in ["Valuation Rate", "Last Purchase Rate"]:
+ self.plc_conversion_rate = 1
+ elif not self.plc_conversion_rate and self.price_list_currency:
+ self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
+ self.company_currency(), args="for_buying")
+
def validate_materials(self):
""" Validate raw material entries """
diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py
index 45a7b93..3dfd03b 100644
--- a/erpnext/manufacturing/doctype/bom/test_bom.py
+++ b/erpnext/manufacturing/doctype/bom/test_bom.py
@@ -81,13 +81,13 @@
# test amounts in selected currency
self.assertEqual(bom.operating_cost, 100)
- self.assertEqual(bom.raw_material_cost, 8000)
- self.assertEqual(bom.total_cost, 8100)
+ self.assertEqual(bom.raw_material_cost, 351.68)
+ self.assertEqual(bom.total_cost, 451.68)
# test amounts in selected currency
self.assertEqual(bom.base_operating_cost, 6000)
- self.assertEqual(bom.base_raw_material_cost, 480000)
- self.assertEqual(bom.base_total_cost, 486000)
+ self.assertEqual(bom.base_raw_material_cost, 21100.80)
+ self.assertEqual(bom.base_total_cost, 27100.80)
def test_bom_cost_multi_uom_multi_currency_based_on_price_list(self):
frappe.db.set_value("Price List", "_Test Price List", "price_not_uom_dependent", 1)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index b920d03..dc88ffb 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -685,4 +685,6 @@
erpnext.patches.v12_0.unset_customer_supplier_based_on_type_of_item_price
erpnext.patches.v12_0.set_valid_till_date_in_supplier_quotation
erpnext.patches.v12_0.set_serial_no_status
+erpnext.patches.v12_0.update_price_list_currency_in_bom
+execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts')
erpnext.patches.v13_0.update_actual_start_and_end_date_in_wo
diff --git a/erpnext/patches/v12_0/update_price_list_currency_in_bom.py b/erpnext/patches/v12_0/update_price_list_currency_in_bom.py
new file mode 100644
index 0000000..f5e7b94
--- /dev/null
+++ b/erpnext/patches/v12_0/update_price_list_currency_in_bom.py
@@ -0,0 +1,31 @@
+from __future__ import unicode_literals
+import frappe
+from frappe.utils import getdate, flt
+from erpnext.setup.utils import get_exchange_rate
+
+def execute():
+ frappe.reload_doc("manufacturing", "doctype", "bom")
+ frappe.reload_doc("manufacturing", "doctype", "bom_item")
+
+ frappe.db.sql(""" UPDATE `tabBOM`, `tabPrice List`
+ SET
+ `tabBOM`.price_list_currency = `tabPrice List`.currency,
+ `tabBOM`.plc_conversion_rate = 1.0
+ WHERE
+ `tabBOM`.buying_price_list = `tabPrice List`.name AND `tabBOM`.docstatus < 2
+ AND `tabBOM`.rm_cost_as_per = 'Price List'
+ """)
+
+ for d in frappe.db.sql("""
+ SELECT
+ bom.creation, bom.name, bom.price_list_currency as currency,
+ company.default_currency as company_currency
+ FROM
+ `tabBOM` as bom, `tabCompany` as company
+ WHERE
+ bom.company = company.name AND bom.rm_cost_as_per = 'Price List' AND
+ bom.price_list_currency != company.default_currency AND bom.docstatus < 2""", as_dict=1):
+ plc_conversion_rate = get_exchange_rate(d.currency,
+ d.company_currency, getdate(d.creation), "for_buying")
+
+ frappe.db.set_value("BOM", d.name, "plc_conversion_rate", plc_conversion_rate)
\ No newline at end of file
diff --git a/erpnext/selling/desk_page/selling/selling.json b/erpnext/selling/desk_page/selling/selling.json
deleted file mode 100644
index a20806b..0000000
--- a/erpnext/selling/desk_page/selling/selling.json
+++ /dev/null
@@ -1,85 +0,0 @@
-{
- "cards": [
- {
- "hidden": 0,
- "label": "Items and Pricing",
- "links": "[\n {\n \"description\": \"All Products or Services.\",\n \"label\": \"Item\",\n \"name\": \"Item\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Price List\"\n ],\n \"description\": \"Multiple Item prices.\",\n \"label\": \"Item Price\",\n \"name\": \"Item Price\",\n \"onboard\": 1,\n \"route\": \"#Report/Item Price\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Price List master.\",\n \"label\": \"Price List\",\n \"name\": \"Price List\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Tree of Item Groups.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Item Group\",\n \"link\": \"Tree/Item Group\",\n \"name\": \"Item Group\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"description\": \"Bundle items at time of sale.\",\n \"label\": \"Product Bundle\",\n \"name\": \"Product Bundle\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Rules for applying different promotional schemes.\",\n \"label\": \"Promotional Scheme\",\n \"name\": \"Promotional Scheme\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"description\": \"Rules for applying pricing and discount.\",\n \"label\": \"Pricing Rule\",\n \"name\": \"Pricing Rule\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Rules for adding shipping costs.\",\n \"label\": \"Shipping Rule\",\n \"name\": \"Shipping Rule\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Define coupon codes.\",\n \"label\": \"Coupon Code\",\n \"name\": \"Coupon Code\",\n \"type\": \"doctype\"\n }\n]"
- },
- {
- "hidden": 0,
- "label": "Settings",
- "links": "[\n {\n \"description\": \"Default settings for selling transactions.\",\n \"label\": \"Selling Settings\",\n \"name\": \"Selling Settings\",\n \"settings\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Template of terms or contract.\",\n \"label\": \"Terms and Conditions Template\",\n \"name\": \"Terms and Conditions\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Tax template for selling transactions.\",\n \"label\": \"Sales Taxes and Charges Template\",\n \"name\": \"Sales Taxes and Charges Template\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Track Leads by Lead Source.\",\n \"label\": \"Lead Source\",\n \"name\": \"Lead Source\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Manage Customer Group Tree.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Customer Group\",\n \"link\": \"Tree/Customer Group\",\n \"name\": \"Customer Group\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"All Contacts.\",\n \"label\": \"Contact\",\n \"name\": \"Contact\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"All Addresses.\",\n \"label\": \"Address\",\n \"name\": \"Address\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Manage Territory Tree.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Territory\",\n \"link\": \"Tree/Territory\",\n \"name\": \"Territory\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Sales campaigns.\",\n \"label\": \"Campaign\",\n \"name\": \"Campaign\",\n \"type\": \"doctype\"\n }\n]"
- },
- {
- "hidden": 0,
- "label": "Other Reports",
- "links": "[\n {\n \"dependencies\": [\n \"Lead\"\n ],\n \"doctype\": \"Lead\",\n \"is_query_report\": true,\n \"label\": \"Lead Details\",\n \"name\": \"Lead Details\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Address\"\n ],\n \"doctype\": \"Address\",\n \"is_query_report\": true,\n \"label\": \"Customer Addresses And Contacts\",\n \"name\": \"Address And Contacts\",\n \"route_options\": {\n \"party_type\": \"Customer\"\n },\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"BOM\"\n ],\n \"doctype\": \"BOM\",\n \"is_query_report\": true,\n \"label\": \"BOM Search\",\n \"name\": \"BOM Search\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"doctype\": \"Item\",\n \"is_query_report\": true,\n \"label\": \"Available Stock for Packing Items\",\n \"name\": \"Available Stock for Packing Items\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Pending SO Items For Purchase Request\",\n \"name\": \"Pending SO Items For Purchase Request\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customer Credit Balance\",\n \"name\": \"Customer Credit Balance\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Customers Without Any Sales Transactions\",\n \"name\": \"Customers Without Any Sales Transactions\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"is_query_report\": true,\n \"label\": \"Sales Partners Commission\",\n \"name\": \"Sales Partners Commission\",\n \"type\": \"report\"\n }\n]"
- },
- {
- "hidden": 0,
- "label": "Sales",
- "links": "[\n {\n \"description\": \"Customer Database.\",\n \"label\": \"Customer\",\n \"name\": \"Customer\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Quotes to Leads or Customers.\",\n \"label\": \"Quotation\",\n \"name\": \"Quotation\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Confirmed orders from Customers.\",\n \"label\": \"Sales Order\",\n \"name\": \"Sales Order\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Invoices for Costumers.\",\n \"label\": \"Sales Invoice\",\n \"name\": \"Sales Invoice\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Blanket Orders from Costumers.\",\n \"label\": \"Blanket Order\",\n \"name\": \"Blanket Order\",\n \"onboard\": 1,\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"description\": \"Manage Sales Partners.\",\n \"label\": \"Sales Partner\",\n \"name\": \"Sales Partner\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"Item\",\n \"Customer\"\n ],\n \"description\": \"Manage Sales Person Tree.\",\n \"icon\": \"fa fa-sitemap\",\n \"label\": \"Sales Person\",\n \"link\": \"Tree/Sales Person\",\n \"name\": \"Sales Person\",\n \"type\": \"doctype\"\n }\n]"
- },
- {
- "hidden": 0,
- "label": "Key Reports",
- "links": "[\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Sales Analytics\",\n \"name\": \"Sales Analytics\",\n \"onboard\": 1,\n \"type\": \"report\"\n },\n {\n \"icon\": \"fa fa-bar-chart\",\n \"label\": \"Sales Funnel\",\n \"name\": \"sales-funnel\",\n \"onboard\": 1,\n \"type\": \"page\"\n },\n {\n \"dependencies\": [\n \"Customer\"\n ],\n \"doctype\": \"Customer\",\n \"icon\": \"fa fa-bar-chart\",\n \"is_query_report\": true,\n \"label\": \"Customer Acquisition and Loyalty\",\n \"name\": \"Customer Acquisition and Loyalty\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Inactive Customers\",\n \"name\": \"Inactive Customers\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Ordered Items To Be Delivered\",\n \"name\": \"Ordered Items To Be Delivered\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Sales Person-wise Transaction Summary\",\n \"name\": \"Sales Person-wise Transaction Summary\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Item\"\n ],\n \"doctype\": \"Item\",\n \"is_query_report\": true,\n \"label\": \"Item-wise Sales History\",\n \"name\": \"Item-wise Sales History\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Quotation\"\n ],\n \"doctype\": \"Quotation\",\n \"is_query_report\": true,\n \"label\": \"Quotation Trends\",\n \"name\": \"Quotation Trends\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Order\"\n ],\n \"doctype\": \"Sales Order\",\n \"is_query_report\": true,\n \"label\": \"Sales Order Trends\",\n \"name\": \"Sales Order Trends\",\n \"type\": \"report\"\n }\n]"
- }
- ],
- "category": "Modules",
- "charts": [
- {
- "chart_name": "Income",
- "label": "Income"
- }
- ],
- "creation": "2020-01-28 11:49:12.092882",
- "developer_mode_only": 0,
- "disable_user_customization": 0,
- "docstatus": 0,
- "doctype": "Desk Page",
- "extends_another_page": 0,
- "icon": "",
- "idx": 0,
- "is_standard": 1,
- "label": "Selling",
- "modified": "2020-04-01 11:28:51.047373",
- "modified_by": "Administrator",
- "module": "Selling",
- "name": "Selling",
- "owner": "Administrator",
- "pin_to_bottom": 0,
- "pin_to_top": 0,
- "shortcuts": [
- {
- "label": "Sales Invoice",
- "link_to": "Sales Invoice",
- "type": "DocType"
- },
- {
- "label": "Sales Order",
- "link_to": "Sales Order",
- "type": "DocType"
- },
- {
- "label": "Quotation",
- "link_to": "Quotation",
- "type": "DocType"
- },
- {
- "label": "Delivery Note",
- "link_to": "Delivery Note",
- "type": "DocType"
- },
- {
- "label": "Accounts Receivable",
- "link_to": "Accounts Receivable",
- "type": "Report"
- },
- {
- "label": "Sales Register",
- "link_to": "Sales Register",
- "type": "Report"
- }
- ]
-}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 3d172ac..a6889e0 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -337,11 +337,15 @@
return lp_details
def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None):
+ from erpnext.controllers.queries import get_fields
+
if frappe.db.get_default("cust_master_name") == "Customer Name":
fields = ["name", "customer_group", "territory"]
else:
fields = ["name", "customer_name", "customer_group", "territory"]
+ fields = get_fields("Customer", fields)
+
match_conditions = build_match_conditions("Customer")
match_conditions = "and {}".format(match_conditions) if match_conditions else ""
@@ -349,14 +353,17 @@
filter_conditions = get_filters_cond(doctype, filters, [])
match_conditions += "{}".format(filter_conditions)
- return frappe.db.sql("""select %s from `tabCustomer` where docstatus < 2
- and (%s like %s or customer_name like %s)
- {match_conditions}
+ return frappe.db.sql("""
+ select %s
+ from `tabCustomer`
+ where docstatus < 2
+ and (%s like %s or customer_name like %s)
+ {match_conditions}
order by
- case when name like %s then 0 else 1 end,
- case when customer_name like %s then 0 else 1 end,
- name, customer_name limit %s, %s""".format(match_conditions=match_conditions) %
- (", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
+ case when name like %s then 0 else 1 end,
+ case when customer_name like %s then 0 else 1 end,
+ name, customer_name limit %s, %s
+ """.format(match_conditions=match_conditions) % (", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len))
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.js b/erpnext/selling/page/sales_funnel/sales_funnel.js
index 85c0cd8..e3d0a55 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.js
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.js
@@ -90,6 +90,10 @@
get_data(btn) {
var me = this;
+ if (!this.company) {
+ frappe.throw(__("Please Select a Company."));
+ }
+
const method_map = {
"sales_funnel": "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data",
"opp_by_lead_source": "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source",
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py
index d62e209..dba24ef 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.py
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.py
@@ -8,14 +8,23 @@
from erpnext.accounts.report.utils import convert
import pandas as pd
+def validate_filters(from_date, to_date, company):
+ if from_date and to_date and (from_date >= to_date):
+ frappe.throw(_("To Date must be greater than From Date"))
+
+ if not company:
+ frappe.throw(_("Please Select a Company"))
+
@frappe.whitelist()
def get_funnel_data(from_date, to_date, company):
+ validate_filters(from_date, to_date, company)
+
active_leads = frappe.db.sql("""select count(*) from `tabLead`
where (date(`modified`) between %s and %s)
and status != "Do Not Contact" and company=%s""", (from_date, to_date, company))[0][0]
active_leads += frappe.db.sql("""select count(distinct contact.name) from `tabContact` contact
- left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer'
+ left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer'
and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
@@ -38,6 +47,8 @@
@frappe.whitelist()
def get_opp_by_lead_source(from_date, to_date, company):
+ validate_filters(from_date, to_date, company)
+
opportunities = frappe.get_all("Opportunity", filters=[['status', 'in', ['Open', 'Quotation', 'Replied']], ['company', '=', company], ['transaction_date', 'Between', [from_date, to_date]]], fields=['currency', 'sales_stage', 'opportunity_amount', 'probability', 'source'])
if opportunities:
@@ -68,11 +79,13 @@
@frappe.whitelist()
def get_pipeline_data(from_date, to_date, company):
+ validate_filters(from_date, to_date, company)
+
opportunities = frappe.get_all("Opportunity", filters=[['status', 'in', ['Open', 'Quotation', 'Replied']], ['company', '=', company], ['transaction_date', 'Between', [from_date, to_date]]], fields=['currency', 'sales_stage', 'opportunity_amount', 'probability'])
if opportunities:
default_currency = frappe.get_cached_value('Global Defaults', 'None', 'default_currency')
-
+
cp_opportunities = [dict(x, **{'compound_amount': (convert(x['opportunity_amount'], x['currency'], default_currency, to_date) * x['probability']/100)}) for x in opportunities]
df = pd.DataFrame(cp_opportunities).groupby(['sales_stage'], as_index=True).agg({'compound_amount': 'sum'}).to_dict()