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 9eeedd8515
commit 960ef14b7a
575 changed files with 4086 additions and 6211 deletions

View File

@@ -198,7 +198,9 @@ class Appointment(Document):
"starts_on": self.scheduled_time,
"status": "Open",
"type": "Public",
"send_reminder": frappe.db.get_single_value("Appointment Booking Settings", "email_reminders"),
"send_reminder": frappe.db.get_single_value(
"Appointment Booking Settings", "email_reminders"
),
"event_participants": [
dict(reference_doctype=self.appointment_with, reference_docname=self.party)
],
@@ -251,9 +253,7 @@ def _get_agent_list_as_strings():
def _check_agent_availability(agent_email, scheduled_time):
appointemnts_at_scheduled_time = frappe.get_all(
"Appointment", filters={"scheduled_time": scheduled_time}
)
appointemnts_at_scheduled_time = frappe.get_all("Appointment", filters={"scheduled_time": scheduled_time})
for appointment in appointemnts_at_scheduled_time:
if appointment._assign == agent_email:
return False

View File

@@ -45,13 +45,13 @@ class AppointmentBookingSettings(Document):
def save(self):
self.number_of_agents = len(self.agent_list)
super(AppointmentBookingSettings, self).save()
super().save()
def validate_availability_of_slots(self):
for record in self.availability_of_slots:
from_time = datetime.datetime.strptime(self.min_date + record.from_time, self.format_string)
to_time = datetime.datetime.strptime(self.min_date + record.to_time, self.format_string)
timedelta = to_time - from_time
to_time - from_time
self.validate_from_and_to_time(from_time, to_time, record)
self.duration_is_divisible(from_time, to_time)
@@ -65,6 +65,4 @@ class AppointmentBookingSettings(Document):
def duration_is_divisible(self, from_time, to_time):
timedelta = to_time - from_time
if timedelta.total_seconds() % (self.appointment_duration * 60):
frappe.throw(
_("The difference between from time and To Time must be a multiple of Appointment")
)
frappe.throw(_("The difference between from time and To Time must be a multiple of Appointment"))

View File

@@ -15,9 +15,7 @@ class AppointmentBookingSlots(Document):
if TYPE_CHECKING:
from frappe.types import DF
day_of_week: DF.Literal[
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
]
day_of_week: DF.Literal["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
from_time: DF.Time
parent: DF.Data
parentfield: DF.Data

View File

@@ -15,9 +15,7 @@ class AvailabilityOfSlots(Document):
if TYPE_CHECKING:
from frappe.types import DF
day_of_week: DF.Literal[
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
]
day_of_week: DF.Literal["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
from_time: DF.Time
parent: DF.Data
parentfield: DF.Data

View File

@@ -49,12 +49,12 @@ class Contract(Document):
name = self.party_name
if self.contract_template:
name += " - {} Agreement".format(self.contract_template)
name += f" - {self.contract_template} Agreement"
# If identical, append contract name with the next number in the iteration
if frappe.db.exists("Contract", name):
count = len(frappe.get_all("Contract", filters={"name": ["like", "%{}%".format(name)]}))
name = "{} - {}".format(name, count)
count = len(frappe.get_all("Contract", filters={"name": ["like", f"%{name}%"]}))
name = f"{name} - {count}"
self.name = _(name)

View File

@@ -59,9 +59,7 @@ class Lead(SellingController, CRMNote):
qualification_status: DF.Literal["Unqualified", "In Process", "Qualified"]
qualified_by: DF.Link | None
qualified_on: DF.Date | None
request_type: DF.Literal[
"", "Product Enquiry", "Request for Information", "Suggestions", "Other"
]
request_type: DF.Literal["", "Product Enquiry", "Request for Information", "Suggestions", "Other"]
salutation: DF.Link | None
source: DF.Link | None
state: DF.Data | None
@@ -185,9 +183,7 @@ class Lead(SellingController, CRMNote):
self.contact_doc.save()
def update_prospect(self):
lead_row_name = frappe.db.get_value(
"Prospect Lead", filters={"lead": self.name}, fieldname="name"
)
lead_row_name = frappe.db.get_value("Prospect Lead", filters={"lead": self.name}, fieldname="name")
if lead_row_name:
lead_row = frappe.get_doc("Prospect Lead", lead_row_name)
lead_row.update(
@@ -237,9 +233,7 @@ class Lead(SellingController, CRMNote):
)
def has_lost_quotation(self):
return frappe.db.get_value(
"Quotation", {"party_name": self.name, "docstatus": 1, "status": "Lost"}
)
return frappe.db.get_value("Quotation", {"party_name": self.name, "docstatus": 1, "status": "Lost"})
@frappe.whitelist()
def create_prospect_and_contact(self, data):
@@ -511,9 +505,9 @@ def get_lead_with_phone_number(number):
leads = frappe.get_all(
"Lead",
or_filters={
"phone": ["like", "%{}".format(number)],
"whatsapp_no": ["like", "%{}".format(number)],
"mobile_no": ["like", "%{}".format(number)],
"phone": ["like", f"%{number}"],
"whatsapp_no": ["like", f"%{number}"],
"mobile_no": ["like", f"%{number}"],
},
limit=1,
order_by="creation DESC",
@@ -540,9 +534,7 @@ def add_lead_to_prospect(lead, prospect):
link_open_events("Lead", lead, prospect)
frappe.msgprint(
_("Lead {0} has been added to prospect {1}.").format(
frappe.bold(lead), frappe.bold(prospect.name)
),
_("Lead {0} has been added to prospect {1}.").format(frappe.bold(lead), frappe.bold(prospect.name)),
title=_("Lead -> Prospect"),
indicator="green",
)

View File

@@ -134,9 +134,7 @@ class TestLead(unittest.TestCase):
self.assertEqual(event.event_participants[1].reference_docname, opportunity.name)
self.assertTrue(
frappe.db.get_value(
"ToDo", {"reference_type": "Opportunity", "reference_name": opportunity.name}
)
frappe.db.get_value("ToDo", {"reference_type": "Opportunity", "reference_name": opportunity.name})
)
def test_copy_events_from_lead_to_prospect(self):
@@ -194,7 +192,7 @@ def make_lead(**args):
"doctype": "Lead",
"first_name": args.first_name or "_Test",
"last_name": args.last_name or "Lead",
"email_id": args.email_id or "new_lead_{}@example.com".format(random_string(5)),
"email_id": args.email_id or f"new_lead_{random_string(5)}@example.com",
"company_name": args.company_name or "_Test Company",
}
).insert()

View File

@@ -370,9 +370,7 @@ def make_quotation(source_name, target_doc=None):
quotation.conversion_rate = exchange_rate
# get default taxes
taxes = get_default_taxes_and_charges(
"Sales Taxes and Charges Template", company=quotation.company
)
taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", company=quotation.company)
if taxes.get("taxes"):
quotation.update(taxes)
@@ -478,9 +476,7 @@ def set_multiple_status(names, status):
def auto_close_opportunity():
"""auto close the `Replied` Opportunities after 7 days"""
auto_close_after_days = (
frappe.db.get_single_value("CRM Settings", "close_opportunity_after_days") or 15
)
auto_close_after_days = frappe.db.get_single_value("CRM Settings", "close_opportunity_after_days") or 15
table = frappe.qb.DocType("Opportunity")
opportunities = (

View File

@@ -4,7 +4,7 @@
import unittest
import frappe
from frappe.utils import add_days, now_datetime, random_string, today
from frappe.utils import now_datetime, random_string, today
from erpnext.crm.doctype.lead.lead import make_customer
from erpnext.crm.doctype.lead.test_lead import make_lead
@@ -32,9 +32,7 @@ class TestOpportunity(unittest.TestCase):
self.assertTrue(opp_doc.party_name)
self.assertEqual(opp_doc.opportunity_from, "Lead")
self.assertEqual(
frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), opp_doc.contact_email
)
self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), opp_doc.contact_email)
# create new customer and create new contact against 'new.opportunity@example.com'
customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True)
@@ -64,9 +62,7 @@ class TestOpportunity(unittest.TestCase):
opportunity_comment_count = frappe.db.count(
"Comment", {"reference_doctype": opp_doc.doctype, "reference_name": opp_doc.name}
)
opportunity_communication_count = len(
get_linked_communication_list(opp_doc.doctype, opp_doc.name)
)
opportunity_communication_count = len(get_linked_communication_list(opp_doc.doctype, opp_doc.name))
self.assertEqual(opportunity_comment_count, 2)
self.assertEqual(opportunity_communication_count, 2)
@@ -77,7 +73,7 @@ class TestOpportunity(unittest.TestCase):
def make_opportunity_from_lead():
new_lead_email_id = "new{}@example.com".format(random_string(5))
new_lead_email_id = f"new{random_string(5)}@example.com"
args = {
"doctype": "Opportunity",
"contact_email": new_lead_email_id,
@@ -126,9 +122,7 @@ def make_opportunity(**args):
return opp_doc
def create_communication(
reference_doctype, reference_name, sender, sent_or_received=None, creation=None
):
def create_communication(reference_doctype, reference_name, sender, sent_or_received=None, creation=None):
communication = frappe.get_doc(
{
"doctype": "Communication",

View File

@@ -34,7 +34,7 @@ def make_prospect(**args):
prospect_doc = frappe.get_doc(
{
"doctype": "Prospect",
"company_name": args.company_name or "_Test Company {}".format(random_string(3)),
"company_name": args.company_name or f"_Test Company {random_string(3)}",
}
).insert()

View File

@@ -3,7 +3,6 @@ import frappe
@frappe.whitelist()
def get_last_interaction(contact=None, lead=None):
if not contact and not lead:
return
@@ -23,16 +22,14 @@ def get_last_interaction(contact=None, lead=None):
# remove extra appended 'OR'
query_condition = query_condition[:-2]
last_communication = frappe.db.sql(
"""
f"""
SELECT `name`, `content`
FROM `tabCommunication`
WHERE `sent_or_received`='Received'
AND ({})
AND ({query_condition})
ORDER BY `modified`
LIMIT 1
""".format(
query_condition
),
""",
values,
as_dict=1,
) # nosec