various fixes from review
- Rename the report to title case - Added company filter - fixed checks in filter and += operator for total
This commit is contained in:
parent
6280609c25
commit
75adb808e5
@ -10,7 +10,13 @@ frappe.query_reports["Territory wise Sales"] = {
|
|||||||
fieldname:"expected_closing_date",
|
fieldname:"expected_closing_date",
|
||||||
label: __("Expected Closing Date"),
|
label: __("Expected Closing Date"),
|
||||||
fieldtype: "DateRange",
|
fieldtype: "DateRange",
|
||||||
default: [frappe.datetime.add_months(frappe.datetime.get_today(),-1), frappe.datetime.get_today()]
|
default: [frappe.datetime.add_months(frappe.datetime.get_today(),-1), frappe.datetime.get_today()],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldname: "company",
|
||||||
|
label: __("Company"),
|
||||||
|
fieldtype: "Link",
|
||||||
|
options: "Company",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -1,21 +1,27 @@
|
|||||||
{
|
{
|
||||||
"add_total_row": 0,
|
"add_total_row": 0,
|
||||||
"creation": "2020-01-10 13:02:23.312515",
|
"creation": "2020-01-31 10:34:33.319047",
|
||||||
"disable_prepared_report": 0,
|
"disable_prepared_report": 0,
|
||||||
"disabled": 0,
|
"disabled": 0,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "Report",
|
"doctype": "Report",
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"is_standard": "Yes",
|
"is_standard": "Yes",
|
||||||
"modified": "2020-01-14 14:50:33.863423",
|
"modified": "2020-01-31 10:34:33.319047",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Territory wise Sales",
|
"name": "Territory-wise Sales",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"prepared_report": 0,
|
"prepared_report": 0,
|
||||||
"query": "",
|
|
||||||
"ref_doctype": "Opportunity",
|
"ref_doctype": "Opportunity",
|
||||||
"report_name": "Territory wise Sales",
|
"report_name": "Territory-wise Sales",
|
||||||
"report_type": "Script Report",
|
"report_type": "Script Report",
|
||||||
"roles": []
|
"roles": [
|
||||||
|
{
|
||||||
|
"role": "Sales User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Sales Manager"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
@ -57,16 +57,16 @@ def get_data(filters=None):
|
|||||||
sales_invoices = get_sales_invoice(sales_orders)
|
sales_invoices = get_sales_invoice(sales_orders)
|
||||||
|
|
||||||
for territory in frappe.get_all("Territory"):
|
for territory in frappe.get_all("Territory"):
|
||||||
territory_opportunities = list(filter(lambda x: x.territory == territory.name, opportunities)) if opportunities and opportunities else None
|
territory_opportunities = list(filter(lambda x: x.territory == territory.name, opportunities)) if opportunities and opportunities else []
|
||||||
t_opportunity_names = [t.name for t in territory_opportunities] if territory_opportunities else None
|
t_opportunity_names = [t.name for t in territory_opportunities] if territory_opportunities else None
|
||||||
|
|
||||||
territory_quotations = list(filter(lambda x: x.opportunity in t_opportunity_names, quotations)) if t_opportunity_names and quotations else None
|
territory_quotations = list(filter(lambda x: x.opportunity in t_opportunity_names, quotations)) if t_opportunity_names and quotations else []
|
||||||
t_quotation_names = [t.name for t in territory_quotations] if territory_quotations else None
|
t_quotation_names = [t.name for t in territory_quotations] if territory_quotations else None
|
||||||
|
|
||||||
territory_orders = list(filter(lambda x: x.quotation in t_quotation_names, sales_orders)) if t_quotation_names and sales_orders else None
|
territory_orders = list(filter(lambda x: x.quotation in t_quotation_names, sales_orders)) if t_quotation_names and sales_orders else []
|
||||||
t_order_names = [t.name for t in territory_orders] if territory_orders else None
|
t_order_names = [t.name for t in territory_orders] if territory_orders else None
|
||||||
|
|
||||||
territory_invoices = list(filter(lambda x: x.sales_order in t_order_names, sales_invoices)) if t_order_names and sales_invoices else None
|
territory_invoices = list(filter(lambda x: x.sales_order in t_order_names, sales_invoices)) if t_order_names and sales_invoices else []
|
||||||
|
|
||||||
territory_data = {
|
territory_data = {
|
||||||
"territory": territory.name,
|
"territory": territory.name,
|
||||||
@ -84,11 +84,19 @@ def get_opportunities(filters):
|
|||||||
|
|
||||||
if filters.from_date and filters.to_date:
|
if filters.from_date and filters.to_date:
|
||||||
conditions = " WHERE expected_closing between %(from_date)s and %(to_date)s"
|
conditions = " WHERE expected_closing between %(from_date)s and %(to_date)s"
|
||||||
|
|
||||||
|
if filters.company:
|
||||||
|
if conditions:
|
||||||
|
conditions += " AND"
|
||||||
|
else:
|
||||||
|
conditions += " WHERE"
|
||||||
|
conditions += " company = %(company)s"
|
||||||
|
|
||||||
|
|
||||||
return frappe.db.sql("""
|
return frappe.db.sql("""
|
||||||
SELECT name, territory, opportunity_amount
|
SELECT name, territory, opportunity_amount
|
||||||
FROM `tabOpportunity` {0}
|
FROM `tabOpportunity` {0}
|
||||||
""".format(conditions), filters, as_dict=1)
|
""".format(conditions), filters, as_dict=1) #nosec
|
||||||
|
|
||||||
def get_quotations(opportunities):
|
def get_quotations(opportunities):
|
||||||
if not opportunities:
|
if not opportunities:
|
||||||
@ -100,7 +108,7 @@ def get_quotations(opportunities):
|
|||||||
SELECT `name`,`base_grand_total`, `opportunity`
|
SELECT `name`,`base_grand_total`, `opportunity`
|
||||||
FROM `tabQuotation`
|
FROM `tabQuotation`
|
||||||
WHERE docstatus=1 AND opportunity in ({0})
|
WHERE docstatus=1 AND opportunity in ({0})
|
||||||
""".format(', '.join(["%s"]*len(opportunity_names))), tuple(opportunity_names), as_dict=1)
|
""".format(', '.join(["%s"]*len(opportunity_names))), tuple(opportunity_names), as_dict=1) #nosec
|
||||||
|
|
||||||
def get_sales_orders(quotations):
|
def get_sales_orders(quotations):
|
||||||
if not quotations:
|
if not quotations:
|
||||||
@ -112,7 +120,7 @@ def get_sales_orders(quotations):
|
|||||||
SELECT so.`name`, so.`base_grand_total`, soi.prevdoc_docname as quotation
|
SELECT so.`name`, so.`base_grand_total`, soi.prevdoc_docname as quotation
|
||||||
FROM `tabSales Order` so, `tabSales Order Item` soi
|
FROM `tabSales Order` so, `tabSales Order Item` soi
|
||||||
WHERE so.docstatus=1 AND so.name = soi.parent AND soi.prevdoc_docname in ({0})
|
WHERE so.docstatus=1 AND so.name = soi.parent AND soi.prevdoc_docname in ({0})
|
||||||
""".format(', '.join(["%s"]*len(quotation_names))), tuple(quotation_names), as_dict=1)
|
""".format(', '.join(["%s"]*len(quotation_names))), tuple(quotation_names), as_dict=1) #nosec
|
||||||
|
|
||||||
def get_sales_invoice(sales_orders):
|
def get_sales_invoice(sales_orders):
|
||||||
if not sales_orders:
|
if not sales_orders:
|
||||||
@ -124,7 +132,7 @@ def get_sales_invoice(sales_orders):
|
|||||||
SELECT si.name, si.base_grand_total, sii.sales_order
|
SELECT si.name, si.base_grand_total, sii.sales_order
|
||||||
FROM `tabSales Invoice` si, `tabSales Invoice Item` sii
|
FROM `tabSales Invoice` si, `tabSales Invoice Item` sii
|
||||||
WHERE si.docstatus=1 AND si.name = sii.parent AND sii.sales_order in ({0})
|
WHERE si.docstatus=1 AND si.name = sii.parent AND sii.sales_order in ({0})
|
||||||
""".format(', '.join(["%s"]*len(so_names))), tuple(so_names), as_dict=1)
|
""".format(', '.join(["%s"]*len(so_names))), tuple(so_names), as_dict=1) #nosec
|
||||||
|
|
||||||
def _get_total(doclist, amount_field="base_grand_total"):
|
def _get_total(doclist, amount_field="base_grand_total"):
|
||||||
if not doclist:
|
if not doclist:
|
||||||
@ -132,6 +140,6 @@ def _get_total(doclist, amount_field="base_grand_total"):
|
|||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
for doc in doclist:
|
for doc in doclist:
|
||||||
total = total + doc.get(amount_field, 0)
|
total += doc.get(amount_field, 0)
|
||||||
|
|
||||||
return total
|
return total
|
||||||
|
Loading…
Reference in New Issue
Block a user