2020-07-27 19:56:07 +05:30
|
|
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
|
|
|
# For license information, please see license.txt
|
|
|
|
|
2021-09-02 16:44:59 +05:30
|
|
|
|
2020-07-27 19:56:07 +05:30
|
|
|
import frappe
|
|
|
|
from frappe import _
|
2023-10-01 13:27:44 +05:30
|
|
|
from frappe.query_builder.functions import Concat_ws, Date
|
2021-09-02 16:44:59 +05:30
|
|
|
|
2020-07-27 19:56:07 +05:30
|
|
|
|
|
|
|
def execute(filters=None):
|
2020-07-30 00:41:06 +05:30
|
|
|
columns, data = get_columns(), get_data(filters)
|
2020-07-27 19:56:07 +05:30
|
|
|
return columns, data
|
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2020-07-27 19:56:07 +05:30
|
|
|
def get_columns():
|
|
|
|
columns = [
|
|
|
|
{
|
|
|
|
"label": _("Lead"),
|
|
|
|
"fieldname": "name",
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Lead",
|
|
|
|
"width": 150,
|
|
|
|
},
|
|
|
|
{"label": _("Lead Name"), "fieldname": "lead_name", "fieldtype": "Data", "width": 120},
|
|
|
|
{"fieldname": "status", "label": _("Status"), "fieldtype": "Data", "width": 100},
|
|
|
|
{
|
|
|
|
"fieldname": "lead_owner",
|
|
|
|
"label": _("Lead Owner"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "User",
|
|
|
|
"width": 100,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": _("Territory"),
|
|
|
|
"fieldname": "territory",
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Territory",
|
|
|
|
"width": 100,
|
|
|
|
},
|
|
|
|
{"label": _("Source"), "fieldname": "source", "fieldtype": "Data", "width": 120},
|
|
|
|
{"label": _("Email"), "fieldname": "email_id", "fieldtype": "Data", "width": 120},
|
|
|
|
{"label": _("Mobile"), "fieldname": "mobile_no", "fieldtype": "Data", "width": 120},
|
|
|
|
{"label": _("Phone"), "fieldname": "phone", "fieldtype": "Data", "width": 120},
|
|
|
|
{
|
|
|
|
"label": _("Owner"),
|
|
|
|
"fieldname": "owner",
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "user",
|
|
|
|
"width": 120,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": _("Company"),
|
|
|
|
"fieldname": "company",
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Company",
|
|
|
|
"width": 120,
|
|
|
|
},
|
|
|
|
{"fieldname": "address", "label": _("Address"), "fieldtype": "Data", "width": 130},
|
|
|
|
{"fieldname": "state", "label": _("State"), "fieldtype": "Data", "width": 100},
|
|
|
|
{"fieldname": "pincode", "label": _("Postal Code"), "fieldtype": "Data", "width": 90},
|
|
|
|
{
|
|
|
|
"fieldname": "country",
|
|
|
|
"label": _("Country"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Country",
|
|
|
|
"width": 100,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
return columns
|
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2020-07-30 00:41:06 +05:30
|
|
|
def get_data(filters):
|
2023-10-01 13:27:44 +05:30
|
|
|
lead = frappe.qb.DocType("Lead")
|
|
|
|
address = frappe.qb.DocType("Address")
|
|
|
|
dynamic_link = frappe.qb.DocType("Dynamic Link")
|
2020-07-27 19:56:07 +05:30
|
|
|
|
2023-10-01 13:27:44 +05:30
|
|
|
query = (
|
|
|
|
frappe.qb.from_(lead)
|
|
|
|
.left_join(dynamic_link)
|
|
|
|
.on((lead.name == dynamic_link.link_name) & (dynamic_link.parenttype == "Address"))
|
|
|
|
.left_join(address)
|
|
|
|
.on(address.name == dynamic_link.parent)
|
|
|
|
.select(
|
|
|
|
lead.name,
|
|
|
|
lead.lead_name,
|
|
|
|
lead.status,
|
|
|
|
lead.lead_owner,
|
|
|
|
lead.territory,
|
|
|
|
lead.source,
|
|
|
|
lead.email_id,
|
|
|
|
lead.mobile_no,
|
|
|
|
lead.phone,
|
|
|
|
lead.owner,
|
|
|
|
lead.company,
|
|
|
|
(Concat_ws(", ", address.address_line1, address.address_line2)).as_("address"),
|
|
|
|
address.state,
|
|
|
|
address.pincode,
|
|
|
|
address.country,
|
|
|
|
)
|
|
|
|
.where(lead.company == filters.company)
|
|
|
|
.where(Date(lead.creation).between(filters.from_date, filters.to_date))
|
|
|
|
)
|
2020-07-27 19:56:07 +05:30
|
|
|
|
|
|
|
if filters.get("territory"):
|
2023-10-01 13:27:44 +05:30
|
|
|
query = query.where(lead.territory == filters.get("territory"))
|
2020-07-27 19:56:07 +05:30
|
|
|
|
|
|
|
if filters.get("status"):
|
2023-10-01 13:27:44 +05:30
|
|
|
query = query.where(lead.status == filters.get("status"))
|
2020-07-27 19:56:07 +05:30
|
|
|
|
2023-10-01 13:27:44 +05:30
|
|
|
return query.run(as_dict=1)
|