Merge pull request #23233 from ruchamahabal/fix-rfq-conv-factor

fix: set conversion factor while creating RFQ from Opportunity
diff --git a/erpnext/accounts/desk_page/accounting/accounting.json b/erpnext/accounts/desk_page/accounting/accounting.json
index a249783..2c52314 100644
--- a/erpnext/accounts/desk_page/accounting/accounting.json
+++ b/erpnext/accounts/desk_page/accounting/accounting.json
@@ -43,7 +43,7 @@
   {
    "hidden": 0,
    "label": "Bank Statement",
-   "links": "[\n    {\n        \"label\": \"Bank\",\n        \"name\": \"Bank\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Account\",\n        \"name\": \"Bank Account\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Statement Transaction Entry\",\n        \"name\": \"Bank Statement Transaction Entry\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Statement Settings\",\n        \"name\": \"Bank Statement Settings\",\n        \"type\": \"doctype\"\n    }\n]"
+   "links": "[\n    {\n        \"label\": \"Bank\",\n        \"name\": \"Bank\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Account\",\n        \"name\": \"Bank Account\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Reconciliation\",\n        \"name\": \"bank-reconciliation\",\n        \"type\": \"page\"\n    },\n    {\n        \"label\": \"Bank Clearance\",\n        \"name\": \"Bank Clearance\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Statement Transaction Entry\",\n        \"name\": \"Bank Statement Transaction Entry\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Bank Statement Settings\",\n        \"name\": \"Bank Statement Settings\",\n        \"type\": \"doctype\"\n    }\n]"
   },
   {
    "hidden": 0,
@@ -98,7 +98,7 @@
  "idx": 0,
  "is_standard": 1,
  "label": "Accounting",
- "modified": "2020-06-19 12:42:44.054598",
+ "modified": "2020-09-03 10:37:07.865801",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Accounting",
@@ -158,4 +158,4 @@
    "type": "Dashboard"
   }
  ]
-}
+}
\ No newline at end of file
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.json b/erpnext/accounts/report/gross_profit/gross_profit.json
index 9cfb062..cd6bac2 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.json
+++ b/erpnext/accounts/report/gross_profit/gross_profit.json
@@ -1,24 +1,23 @@
 {
- "add_total_row": 0, 
- "apply_user_permissions": 1, 
- "creation": "2013-02-25 17:03:34", 
- "disabled": 0, 
- "docstatus": 0, 
- "doctype": "Report", 
- "idx": 3, 
- "is_standard": "Yes", 
- "modified": "2017-02-24 20:12:22.464240", 
- "modified_by": "Administrator", 
- "module": "Accounts", 
- "name": "Gross Profit", 
- "owner": "Administrator", 
- "ref_doctype": "Sales Invoice", 
- "report_name": "Gross Profit", 
- "report_type": "Script Report", 
+ "add_total_row": 1,
+ "creation": "2013-02-25 17:03:34",
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "idx": 3,
+ "is_standard": "Yes",
+ "modified": "2020-08-13 11:26:39.112352",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Gross Profit",
+ "owner": "Administrator",
+ "ref_doctype": "Sales Invoice",
+ "report_name": "Gross Profit",
+ "report_type": "Script Report",
  "roles": [
   {
    "role": "Accounts Manager"
-  }, 
+  },
   {
    "role": "Accounts User"
   }
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 911fe51..1f955fc 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -396,13 +396,12 @@
 			credit_controller_users = get_users_with_role(credit_controller_role or "Sales Master Manager")
 
 			# form a list of emails and names to show to the user
-			credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users]
-
-			if not credit_controller_users:
+			credit_controller_users_formatted = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users]
+			if not credit_controller_users_formatted:
 				frappe.throw(_("Please contact your administrator to extend the credit limits for {0}.".format(customer)))
 
 			message = """Please contact any of the following users to extend the credit limits for {0}:
-				<br><br><ul><li>{1}</li></ul>""".format(customer, '<li>'.join(credit_controller_users))
+				<br><br><ul><li>{1}</li></ul>""".format(customer, '<li>'.join(credit_controller_users_formatted))
 
 			# if the current user does not have permissions to override credit limit,
 			# prompt them to send out an email to the controller users
@@ -427,7 +426,7 @@
 	subject = (_("Credit limit reached for customer {0}").format(args.get('customer')))
 	message = (_("Credit limit has been crossed for customer {0} ({1}/{2})")
 			.format(args.get('customer'), args.get('customer_outstanding'), args.get('credit_limit')))
-	frappe.sendmail(recipients=[args.get('credit_controller_users_list')], subject=subject, message=message)
+	frappe.sendmail(recipients=args.get('credit_controller_users_list'), subject=subject, message=message)
 
 def get_customer_outstanding(customer, company, ignore_outstanding_sales_order=False, cost_center=None):
 	# Outstanding based on GL Entries
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py
index dba24ef..b613718 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.py
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.py
@@ -20,29 +20,28 @@
 	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'
-		and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
+		where (date(`creation`) between %s and %s)
+		and company=%s""", (from_date, to_date, company))[0][0]
 
 	opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
 		where (date(`creation`) between %s and %s)
-		and status != "Lost" and company=%s""", (from_date, to_date, company))[0][0]
+		and opportunity_from='Lead' and company=%s""", (from_date, to_date, company))[0][0]
 
 	quotations = frappe.db.sql("""select count(*) from `tabQuotation`
 		where docstatus = 1 and (date(`creation`) between %s and %s)
-		and status != "Lost" and company=%s""", (from_date, to_date, company))[0][0]
+		and (opportunity!="" or quotation_to="Lead") and company=%s""", (from_date, to_date, company))[0][0]
 
-	sales_orders = frappe.db.sql("""select count(*) from `tabSales Order`
-		where docstatus = 1 and (date(`creation`) between %s and %s) and company=%s""", (from_date, to_date, company))[0][0]
+	converted = frappe.db.sql("""select count(*) from `tabCustomer`
+		JOIN `tabLead` ON `tabLead`.name = `tabCustomer`.lead_name 
+		WHERE (date(`tabCustomer`.creation) between %s and %s)
+		and `tabLead`.company=%s""", (from_date, to_date, company))[0][0]
+
 
 	return [
-		{ "title": _("Active Leads / Customers"), "value": active_leads, "color": "#B03B46" },
+		{ "title": _("Active Leads"), "value": active_leads, "color": "#B03B46" },
 		{ "title": _("Opportunities"), "value": opportunities, "color": "#F09C00" },
 		{ "title": _("Quotations"), "value": quotations, "color": "#006685" },
-		{ "title": _("Sales Orders"), "value": sales_orders, "color": "#00AD65" }
+		{ "title": _("Converted"), "value": converted, "color": "#00AD65" }
 	]
 
 @frappe.whitelist()