From a26e2c064a70971e6bfee9d9ac5ad432427c3314 Mon Sep 17 00:00:00 2001 From: Don-Leopardo <46027152+Don-Leopardo@users.noreply.github.com> Date: Sat, 20 Apr 2019 12:42:23 -0300 Subject: [PATCH] fix: Campaign Efficiency report only works in english (#17284) * fix column translation and match * fix float results * fix import missing --- .../campaign_efficiency.py | 88 ++++++++++++++----- 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/erpnext/crm/report/campaign_efficiency/campaign_efficiency.py b/erpnext/crm/report/campaign_efficiency/campaign_efficiency.py index b20fe15ce27..52b848ed504 100644 --- a/erpnext/crm/report/campaign_efficiency/campaign_efficiency.py +++ b/erpnext/crm/report/campaign_efficiency/campaign_efficiency.py @@ -4,24 +4,70 @@ from __future__ import unicode_literals import frappe from frappe import _ +from frappe.utils import flt def execute(filters=None): columns, data = [], [] - columns=get_columns() - data=get_lead_data(filters, "Campaign Name") + columns=get_columns("Campaign Name") + data=get_lead_data(filters or {}, "Campaign Name") return columns, data -def get_columns(): +def get_columns(based_on): return [ - _("Campaign Name") + ":data:130", - _("Lead Count") + ":Int:80", - _("Opp Count") + ":Int:80", - _("Quot Count") + ":Int:80", - _("Order Count") + ":Int:100", - _("Order Value") + ":Float:100", - _("Opp/Lead %") + ":Float:100", - _("Quot/Lead %") + ":Float:100", - _("Order/Quot %") + ":Float:100" + { + "fieldname": frappe.scrub(based_on), + "label": _(based_on), + "fieldtype": "Data", + "width": 150 + }, + { + "fieldname": "lead_count", + "label": _("Lead Count"), + "fieldtype": "Int", + "width": 80 + }, + { + "fieldname": "opp_count", + "label": _("Opp Count"), + "fieldtype": "Int", + "width": 80 + }, + { + "fieldname": "quot_count", + "label": _("Quot Count"), + "fieldtype": "Int", + "width": 80 + }, + { + "fieldname": "order_count", + "label": _("Order Count"), + "fieldtype": "Int", + "width": 100 + }, + { + "fieldname": "order_value", + "label": _("Order Value"), + "fieldtype": "Float", + "width": 100 + }, + { + "fieldname": "opp_lead", + "label": _("Opp/Lead %"), + "fieldtype": "Float", + "width": 100 + }, + { + "fieldname": "quot_lead", + "label": _("Quot/Lead %"), + "fieldtype": "Float", + "width": 100 + }, + { + "fieldname": "order_quot", + "label": _("Order/Quot %"), + "fieldtype": "Float", + "width": 100 + } ] def get_lead_data(filters, based_on): @@ -41,18 +87,18 @@ def get_lead_data(filters, based_on): data = [] for based_on_value, leads in lead_map.items(): row = { - based_on: based_on_value, - "Lead Count": len(leads) + based_on_field: based_on_value, + "lead_count": len(leads) } - row["Quot Count"]= get_lead_quotation_count(leads) - row["Opp Count"] = get_lead_opp_count(leads) - row["Order Count"] = get_quotation_ordered_count(leads) - row["Order Value"] = get_order_amount(leads) + row["quot_count"]= get_lead_quotation_count(leads) + row["opp_count"] = get_lead_opp_count(leads) + row["order_count"] = get_quotation_ordered_count(leads) + row["order_value"] = get_order_amount(leads) or 0 - row["Opp/Lead %"] = row["Opp Count"] / row["Lead Count"] * 100 - row["Quot/Lead %"] = row["Quot Count"] / row["Lead Count"] * 100 + row["opp_lead"] = flt(row["opp_count"]) / flt(row["lead_count"] or 1.0) * 100.0 + row["quot_lead"] = flt(row["quot_count"]) / flt(row["lead_count"] or 1.0) * 100.0 - row["Order/Quot %"] = row["Order Count"] / (row["Quot Count"] or 1) * 100 + row["order_quot"] = flt(row["order_count"]) / flt(row["quot_count"] or 1.0) * 100.0 data.append(row)