Merge pull request #1114 from rmehta/reports
[report] Customer Acquisition and Loyalty
This commit is contained in:
commit
844913a364
@ -164,6 +164,11 @@ wn.module_page["Selling"] = [
|
|||||||
"label":wn._("Sales Funnel"),
|
"label":wn._("Sales Funnel"),
|
||||||
page: "sales-funnel"
|
page: "sales-funnel"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label":wn._("Customer Acquisition and Loyalty"),
|
||||||
|
route: "query-report/Customer Acquisition and Loyalty",
|
||||||
|
doctype: "Customer"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||||
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
wn.query_reports["Customer Acquisition and Loyalty"] = {
|
||||||
|
"filters": [
|
||||||
|
{
|
||||||
|
"fieldname":"company",
|
||||||
|
"label": wn._("Company"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Company",
|
||||||
|
"default": wn.defaults.get_user_default("company")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"from_date",
|
||||||
|
"label": wn._("From Date"),
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"default": wn.defaults.get_user_default("year_start_date")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"to_date",
|
||||||
|
"label": wn._("To Date"),
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"default": wn.defaults.get_user_default("year_end_date")
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||||
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import webnotes
|
||||||
|
from webnotes.utils import getdate, cint
|
||||||
|
import calendar
|
||||||
|
|
||||||
|
def execute(filters=None):
|
||||||
|
# key yyyy-mm
|
||||||
|
new_customers_in = {}
|
||||||
|
repeat_customers_in = {}
|
||||||
|
customers = []
|
||||||
|
company_condition = ""
|
||||||
|
|
||||||
|
if filters.get("company"):
|
||||||
|
company_condition = ' and company=%(company)s'
|
||||||
|
|
||||||
|
for si in webnotes.conn.sql("""select posting_date, customer, grand_total from `tabSales Invoice`
|
||||||
|
where docstatus=1 and posting_date <= %(to_date)s
|
||||||
|
{company_condition} order by posting_date""".format(company_condition=company_condition),
|
||||||
|
filters, as_dict=1):
|
||||||
|
|
||||||
|
key = si.posting_date[:7]
|
||||||
|
if not si.customer in customers:
|
||||||
|
new_customers_in.setdefault(key, [0, 0.0])
|
||||||
|
new_customers_in[key][0] += 1
|
||||||
|
new_customers_in[key][1] += si.grand_total
|
||||||
|
customers.append(si.customer)
|
||||||
|
else:
|
||||||
|
repeat_customers_in.setdefault(key, [0, 0.0])
|
||||||
|
repeat_customers_in[key][0] += 1
|
||||||
|
repeat_customers_in[key][1] += si.grand_total
|
||||||
|
|
||||||
|
# time series
|
||||||
|
from_year, from_month, temp = filters.get("from_date").split("-")
|
||||||
|
to_year, to_month, temp = filters.get("to_date").split("-")
|
||||||
|
|
||||||
|
from_year, from_month, to_year, to_month = \
|
||||||
|
cint(from_year), cint(from_month), cint(to_year), cint(to_month)
|
||||||
|
|
||||||
|
out = []
|
||||||
|
for year in xrange(from_year, to_year+1):
|
||||||
|
for month in xrange(from_month if year==from_year else 1, (to_month+1) if year==to_year else 13):
|
||||||
|
key = "{year}-{month:02d}".format(year=year, month=month)
|
||||||
|
|
||||||
|
new = new_customers_in.get(key, [0,0.0])
|
||||||
|
repeat = repeat_customers_in.get(key, [0,0.0])
|
||||||
|
|
||||||
|
out.append([year, calendar.month_name[month],
|
||||||
|
new[0], repeat[0], new[0] + repeat[0],
|
||||||
|
new[1], repeat[1], new[1] + repeat[1]])
|
||||||
|
|
||||||
|
return [
|
||||||
|
"Year", "Month",
|
||||||
|
"New Customers:Int",
|
||||||
|
"Repeat Customers:Int",
|
||||||
|
"Total:Int",
|
||||||
|
"New Customer Revenue:Currency:150",
|
||||||
|
"Repeat Customer Revenue:Currency:150",
|
||||||
|
"Total Revenue:Currency:150"
|
||||||
|
], out
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"creation": "2013-11-28 14:58:06",
|
||||||
|
"docstatus": 0,
|
||||||
|
"modified": "2013-11-28 15:02:48",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"owner": "Administrator"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"add_total_row": 1,
|
||||||
|
"doctype": "Report",
|
||||||
|
"is_standard": "Yes",
|
||||||
|
"name": "__common__",
|
||||||
|
"ref_doctype": "Customer",
|
||||||
|
"report_name": "Customer Acquisition and Loyalty",
|
||||||
|
"report_type": "Script Report"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Report",
|
||||||
|
"name": "Customer Acquisition and Loyalty"
|
||||||
|
}
|
||||||
|
]
|
Loading…
x
Reference in New Issue
Block a user