refactor(treewide): formatting and ruff fixes, + manually enabled F401

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang
2024-03-27 11:37:26 +05:30
parent c28d19cf7f
commit 4d34b1ead7
618 changed files with 4188 additions and 6384 deletions

View File

@@ -33,13 +33,11 @@ def get_lead_data(filters, based_on):
conditions = get_filter_conditions(filters)
lead_details = frappe.db.sql(
"""
f"""
select {based_on_field}, name
from `tabLead`
where {based_on_field} is not null and {based_on_field} != '' {conditions}
""".format(
based_on_field=based_on_field, conditions=conditions
),
""",
filters,
as_dict=1,
)
@@ -82,9 +80,7 @@ def get_lead_quotation_count(leads):
where quotation_to = 'Lead' and party_name in (%s)"""
% ", ".join(["%s"] * len(leads)),
tuple(leads),
)[0][
0
] # nosec
)[0][0] # nosec
def get_lead_opp_count(leads):

View File

@@ -67,7 +67,7 @@ def get_columns():
def get_data(filters):
return frappe.db.sql(
"""
f"""
SELECT
`tabOpportunity`.name,
`tabOpportunity`.opportunity_from,
@@ -79,17 +79,15 @@ def get_data(filters):
`tabOpportunity`.territory
FROM
`tabOpportunity`
{join}
{get_join(filters)}
WHERE
`tabOpportunity`.status = 'Lost' and `tabOpportunity`.company = %(company)s
AND DATE(`tabOpportunity`.modified) BETWEEN %(from_date)s AND %(to_date)s
{conditions}
{get_conditions(filters)}
GROUP BY
`tabOpportunity`.name
ORDER BY
`tabOpportunity`.creation asc """.format(
conditions=get_conditions(filters), join=get_join(filters)
),
`tabOpportunity`.creation asc """,
filters,
as_dict=1,
)
@@ -119,9 +117,7 @@ def get_join(filters):
join = """JOIN `tabOpportunity Lost Reason Detail`
ON `tabOpportunity Lost Reason Detail`.parenttype = 'Opportunity' and
`tabOpportunity Lost Reason Detail`.parent = `tabOpportunity`.name and
`tabOpportunity Lost Reason Detail`.lost_reason = '{0}'
""".format(
filters.get("lost_reason")
)
`tabOpportunity Lost Reason Detail`.lost_reason = '{}'
""".format(filters.get("lost_reason"))
return join

View File

@@ -14,7 +14,7 @@ def execute(filters=None):
return OpportunitySummaryBySalesStage(filters).run()
class OpportunitySummaryBySalesStage(object):
class OpportunitySummaryBySalesStage:
def __init__(self, filters=None):
self.filters = frappe._dict(filters or {})
@@ -199,7 +199,6 @@ class OpportunitySummaryBySalesStage(object):
return filters
def get_chart_data(self):
labels = []
datasets = []
values = [0] * len(self.sales_stage_list)

View File

@@ -62,9 +62,7 @@ def get_data(filters):
lead_details = []
lead_filters = get_lead_filters(filters)
for lead in frappe.get_all(
"Lead", fields=["name", "lead_name", "company_name"], filters=lead_filters
):
for lead in frappe.get_all("Lead", fields=["name", "lead_name", "company_name"], filters=lead_filters):
data = frappe.db.sql(
"""
select
@@ -90,7 +88,7 @@ def get_data(filters):
)
for lead_info in data:
lead_data = [lead.name, lead.lead_name, lead.company_name] + list(lead_info)
lead_data = [lead.name, lead.lead_name, lead.company_name, *list(lead_info)]
lead_details.append(lead_data)
return lead_details

View File

@@ -17,7 +17,7 @@ def execute(filters=None):
return SalesPipelineAnalytics(filters).run()
class SalesPipelineAnalytics(object):
class SalesPipelineAnalytics:
def __init__(self, filters=None):
self.filters = frappe._dict(filters or {})
@@ -98,7 +98,7 @@ class SalesPipelineAnalytics(object):
"Opportunity",
filters=self.get_conditions(),
fields=[self.based_on, self.data_based_on, self.duration],
group_by="{},{}".format(self.group_by_based_on, self.group_by_period),
group_by=f"{self.group_by_based_on},{self.group_by_period}",
order_by=self.group_by_period,
)
@@ -230,7 +230,7 @@ class SalesPipelineAnalytics(object):
current_date = date.today()
month_number = date.today().month
for month in range(month_number, 13):
for _month in range(month_number, 13):
month_list.append(current_date.strftime("%B"))
current_date = current_date + relativedelta(months=1)