mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 03:29:16 +00:00
refactor(treewide): formatting and ruff fixes, + manually enabled F401
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
@@ -38,9 +38,7 @@ class Project(Document):
|
||||
cost_center: DF.Link | None
|
||||
customer: DF.Link | None
|
||||
daily_time_to_send: DF.Time | None
|
||||
day_to_send: DF.Literal[
|
||||
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
|
||||
]
|
||||
day_to_send: DF.Literal["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
||||
department: DF.Link | None
|
||||
estimated_costing: DF.Currency
|
||||
expected_end_date: DF.Date | None
|
||||
@@ -107,7 +105,6 @@ class Project(Document):
|
||||
Copy tasks from template
|
||||
"""
|
||||
if self.project_template and not frappe.db.get_all("Task", dict(project=self.name), limit=1):
|
||||
|
||||
# has a template, and no loaded tasks, so lets create
|
||||
if not self.expected_start_date:
|
||||
# project starts today
|
||||
@@ -178,7 +175,9 @@ class Project(Document):
|
||||
for child_task in template_task.get("depends_on"):
|
||||
if project_template_map and project_template_map.get(child_task.task):
|
||||
project_task.reload() # reload, as it might have been updated in the previous iteration
|
||||
project_task.append("depends_on", {"task": project_template_map.get(child_task.task).name})
|
||||
project_task.append(
|
||||
"depends_on", {"task": project_template_map.get(child_task.task).name}
|
||||
)
|
||||
project_task.save()
|
||||
|
||||
def check_for_parent_tasks(self, template_task, project_task, project_tasks):
|
||||
@@ -332,7 +331,7 @@ class Project(Document):
|
||||
frappe.db.set_value("Project", new_name, "copied_from", new_name)
|
||||
|
||||
def send_welcome_email(self):
|
||||
url = get_url("/project/?name={0}".format(self.name))
|
||||
url = get_url(f"/project/?name={self.name}")
|
||||
messages = (
|
||||
_("You have been invited to collaborate on the project: {0}").format(self.name),
|
||||
url,
|
||||
@@ -347,7 +346,9 @@ class Project(Document):
|
||||
for user in self.users:
|
||||
if user.welcome_email_sent == 0:
|
||||
frappe.sendmail(
|
||||
user.user, subject=_("Project Collaboration Invitation"), content=content.format(*messages)
|
||||
user.user,
|
||||
subject=_("Project Collaboration Invitation"),
|
||||
content=content.format(*messages),
|
||||
)
|
||||
user.welcome_email_sent = 1
|
||||
|
||||
@@ -368,9 +369,7 @@ def get_timeline_data(doctype: str, name: str) -> dict[int, int]:
|
||||
)
|
||||
|
||||
|
||||
def get_project_list(
|
||||
doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"
|
||||
):
|
||||
def get_project_list(doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"):
|
||||
customers, suppliers = get_customers_suppliers("Project", frappe.session.user)
|
||||
|
||||
ignore_permissions = False
|
||||
@@ -671,9 +670,7 @@ def update_project_sales_billing():
|
||||
return
|
||||
|
||||
# Else simply fallback to Daily
|
||||
exists_query = (
|
||||
"(SELECT 1 from `tab{doctype}` where docstatus = 1 and project = `tabProject`.name)"
|
||||
)
|
||||
exists_query = "(SELECT 1 from `tab{doctype}` where docstatus = 1 and project = `tabProject`.name)"
|
||||
project_map = {}
|
||||
for project_details in frappe.db.sql(
|
||||
"""
|
||||
@@ -716,7 +713,7 @@ def set_project_status(project, status):
|
||||
"""
|
||||
set status for project and all related tasks
|
||||
"""
|
||||
if not status in ("Completed", "Cancelled"):
|
||||
if status not in ("Completed", "Cancelled"):
|
||||
frappe.throw(_("Status must be Cancelled or Completed"))
|
||||
|
||||
project = frappe.get_doc("Project", project)
|
||||
@@ -736,9 +733,7 @@ def get_holiday_list(company=None):
|
||||
holiday_list = frappe.get_cached_value("Company", company, "default_holiday_list")
|
||||
if not holiday_list:
|
||||
frappe.throw(
|
||||
_("Please set a default Holiday List for Company {0}").format(
|
||||
frappe.bold(get_default_company())
|
||||
)
|
||||
_("Please set a default Holiday List for Company {0}").format(frappe.bold(get_default_company()))
|
||||
)
|
||||
return holiday_list
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ class TestProject(FrappeTestCase):
|
||||
priority="High",
|
||||
)
|
||||
|
||||
template = make_project_template(
|
||||
"Test Project Template - No Parent and Dependend Tasks", [task1]
|
||||
)
|
||||
template = make_project_template("Test Project Template - No Parent and Dependend Tasks", [task1])
|
||||
project = get_project(project_name, template)
|
||||
tasks = frappe.get_all(
|
||||
"Task",
|
||||
@@ -185,9 +183,7 @@ class TestProject(FrappeTestCase):
|
||||
template_parent_task3,
|
||||
template_task3,
|
||||
]
|
||||
project_template = make_project_template(
|
||||
"Project template with common Task Subject", template_tasks
|
||||
)
|
||||
project_template = make_project_template("Project template with common Task Subject", template_tasks)
|
||||
|
||||
# Step - 4: Create Project against the Project Template
|
||||
project = get_project("Project with common Task Subject", project_template)
|
||||
@@ -196,7 +192,7 @@ class TestProject(FrappeTestCase):
|
||||
)
|
||||
|
||||
# Test - 1: No. of Project Tasks should be equal to No. of Template Tasks
|
||||
self.assertEquals(len(project_tasks), len(template_tasks))
|
||||
self.assertEqual(len(project_tasks), len(template_tasks))
|
||||
|
||||
# Test - 2: All child Project Tasks should have Parent Task linked
|
||||
for pt in project_tasks:
|
||||
@@ -205,7 +201,6 @@ class TestProject(FrappeTestCase):
|
||||
|
||||
|
||||
def get_project(name, template):
|
||||
|
||||
project = frappe.get_doc(
|
||||
dict(
|
||||
doctype="Project",
|
||||
|
||||
@@ -12,7 +12,9 @@ class TestProjectTemplate(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
def make_project_template(project_template_name, project_tasks=[]):
|
||||
def make_project_template(project_template_name, project_tasks=None):
|
||||
if project_tasks is None:
|
||||
project_tasks = []
|
||||
if not frappe.db.exists("Project Template", project_template_name):
|
||||
project_tasks = project_tasks or [
|
||||
create_task(subject="_Test Template Task 1", is_template=1, begin=0, duration=3),
|
||||
|
||||
@@ -53,13 +53,8 @@ def daily_reminder():
|
||||
email_sending(project_name, frequency, date_start, date_end, progress, number_of_drafts, update)
|
||||
|
||||
|
||||
def email_sending(
|
||||
project_name, frequency, date_start, date_end, progress, number_of_drafts, update
|
||||
):
|
||||
|
||||
holiday = frappe.db.sql(
|
||||
"""SELECT holiday_date FROM `tabHoliday` where holiday_date = CURRENT_DATE;"""
|
||||
)
|
||||
def email_sending(project_name, frequency, date_start, date_end, progress, number_of_drafts, update):
|
||||
holiday = frappe.db.sql("""SELECT holiday_date FROM `tabHoliday` where holiday_date = CURRENT_DATE;""")
|
||||
msg = (
|
||||
"<p>Project Name: "
|
||||
+ project_name
|
||||
@@ -106,8 +101,6 @@ def email_sending(
|
||||
if len(holiday) == 0:
|
||||
email = frappe.db.sql("""SELECT user from `tabProject User` WHERE parent = %s;""", project_name)
|
||||
for emails in email:
|
||||
frappe.sendmail(
|
||||
recipients=emails, subject=frappe._(project_name + " " + "Summary"), message=msg
|
||||
)
|
||||
frappe.sendmail(recipients=emails, subject=frappe._(project_name + " " + "Summary"), message=msg)
|
||||
else:
|
||||
pass
|
||||
|
||||
@@ -153,14 +153,14 @@ class Task(NestedSet):
|
||||
def validate_parent_template_task(self):
|
||||
if self.parent_task:
|
||||
if not frappe.db.get_value("Task", self.parent_task, "is_template"):
|
||||
parent_task_format = """<a href="#Form/Task/{0}">{0}</a>""".format(self.parent_task)
|
||||
parent_task_format = f"""<a href="#Form/Task/{self.parent_task}">{self.parent_task}</a>"""
|
||||
frappe.throw(_("Parent Task {0} is not a Template Task").format(parent_task_format))
|
||||
|
||||
def validate_depends_on_tasks(self):
|
||||
if self.depends_on:
|
||||
for task in self.depends_on:
|
||||
if not frappe.db.get_value("Task", task.task, "is_template"):
|
||||
dependent_task_format = """<a href="#Form/Task/{0}">{0}</a>""".format(task.task)
|
||||
dependent_task_format = f"""<a href="#Form/Task/{task.task}">{task.task}</a>"""
|
||||
frappe.throw(_("Dependent Task {0} is not a Template Task").format(dependent_task_format))
|
||||
|
||||
def validate_completed_on(self):
|
||||
@@ -219,7 +219,7 @@ class Task(NestedSet):
|
||||
task_list, count = [self.name], 0
|
||||
while len(task_list) > count:
|
||||
tasks = frappe.db.sql(
|
||||
" select %s from `tabTask Depends On` where %s = %s " % (d[0], d[1], "%s"),
|
||||
" select {} from `tabTask Depends On` where {} = {} ".format(d[0], d[1], "%s"),
|
||||
cstr(task_list[count]),
|
||||
)
|
||||
count = count + 1
|
||||
@@ -311,14 +311,12 @@ def get_project(doctype, txt, searchfield, start, page_len, filters):
|
||||
search_cond = " or " + " or ".join(field + " like %(txt)s" for field in searchfields)
|
||||
|
||||
return frappe.db.sql(
|
||||
""" select name {search_columns} from `tabProject`
|
||||
f""" select name {search_columns} from `tabProject`
|
||||
where %(key)s like %(txt)s
|
||||
%(mcond)s
|
||||
{search_condition}
|
||||
{search_cond}
|
||||
order by name
|
||||
limit %(page_len)s offset %(start)s""".format(
|
||||
search_columns=search_columns, search_condition=search_cond
|
||||
),
|
||||
limit %(page_len)s offset %(start)s""",
|
||||
{
|
||||
"key": searchfield,
|
||||
"txt": "%" + txt + "%",
|
||||
@@ -379,7 +377,6 @@ def make_timesheet(source_name, target_doc=None, ignore_permissions=False):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(doctype, parent, task=None, project=None, is_root=False):
|
||||
|
||||
filters = [["docstatus", "<", "2"]]
|
||||
|
||||
if task:
|
||||
|
||||
@@ -131,9 +131,7 @@ def create_task(
|
||||
task.exp_start_date = start or nowdate()
|
||||
task.exp_end_date = end or nowdate()
|
||||
task.project = (
|
||||
project or None
|
||||
if is_template
|
||||
else frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||
project or None if is_template else frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||
)
|
||||
task.is_template = is_template
|
||||
task.start = begin
|
||||
|
||||
@@ -5,7 +5,7 @@ import datetime
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.utils import add_months, add_to_date, now_datetime, nowdate
|
||||
from frappe.utils import add_to_date, now_datetime, nowdate
|
||||
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.projects.doctype.timesheet.timesheet import OverlapError, make_sales_invoice
|
||||
@@ -40,9 +40,7 @@ class TestTimesheet(unittest.TestCase):
|
||||
emp = make_employee("test_employee_6@salary.com")
|
||||
|
||||
timesheet = make_timesheet(emp, simulate=True, is_billable=1)
|
||||
sales_invoice = make_sales_invoice(
|
||||
timesheet.name, "_Test Item", "_Test Customer", currency="INR"
|
||||
)
|
||||
sales_invoice = make_sales_invoice(timesheet.name, "_Test Item", "_Test Customer", currency="INR")
|
||||
sales_invoice.due_date = nowdate()
|
||||
sales_invoice.submit()
|
||||
timesheet = frappe.get_doc("Timesheet", timesheet.name)
|
||||
@@ -211,9 +209,7 @@ def make_timesheet(
|
||||
timesheet_detail.activity_type = activity_type
|
||||
timesheet_detail.from_time = now_datetime()
|
||||
timesheet_detail.hours = 2
|
||||
timesheet_detail.to_time = timesheet_detail.from_time + datetime.timedelta(
|
||||
hours=timesheet_detail.hours
|
||||
)
|
||||
timesheet_detail.to_time = timesheet_detail.from_time + datetime.timedelta(hours=timesheet_detail.hours)
|
||||
timesheet_detail.project = project
|
||||
timesheet_detail.task = task
|
||||
|
||||
|
||||
@@ -299,12 +299,10 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to
|
||||
@frappe.whitelist()
|
||||
def get_timesheet_detail_rate(timelog, currency):
|
||||
timelog_detail = frappe.db.sql(
|
||||
"""SELECT tsd.billing_amount as billing_amount,
|
||||
f"""SELECT tsd.billing_amount as billing_amount,
|
||||
ts.currency as currency FROM `tabTimesheet Detail` tsd
|
||||
INNER JOIN `tabTimesheet` ts ON ts.name=tsd.parent
|
||||
WHERE tsd.name = '{0}'""".format(
|
||||
timelog
|
||||
),
|
||||
WHERE tsd.name = '{timelog}'""",
|
||||
as_dict=1,
|
||||
)[0]
|
||||
|
||||
@@ -326,14 +324,12 @@ def get_timesheet(doctype, txt, searchfield, start, page_len, filters):
|
||||
condition = "and tsd.project = %(project)s"
|
||||
|
||||
return frappe.db.sql(
|
||||
"""select distinct tsd.parent from `tabTimesheet Detail` tsd,
|
||||
f"""select distinct tsd.parent from `tabTimesheet Detail` tsd,
|
||||
`tabTimesheet` ts where
|
||||
ts.status in ('Submitted', 'Payslip') and tsd.parent = ts.name and
|
||||
tsd.docstatus = 1 and ts.total_billable_amount > 0
|
||||
and tsd.parent LIKE %(txt)s {condition}
|
||||
order by tsd.parent limit %(page_len)s offset %(start)s""".format(
|
||||
condition=condition
|
||||
),
|
||||
order by tsd.parent limit %(page_len)s offset %(start)s""",
|
||||
{
|
||||
"txt": "%" + txt + "%",
|
||||
"start": start,
|
||||
@@ -459,18 +455,14 @@ def get_events(start, end, filters=None):
|
||||
where `tabTimesheet Detail`.parent = `tabTimesheet`.name
|
||||
and `tabTimesheet`.docstatus < 2
|
||||
and (from_time <= %(end)s and to_time >= %(start)s) {conditions} {match_cond}
|
||||
""".format(
|
||||
conditions=conditions, match_cond=get_match_cond("Timesheet")
|
||||
),
|
||||
""".format(conditions=conditions, match_cond=get_match_cond("Timesheet")),
|
||||
{"start": start, "end": end},
|
||||
as_dict=True,
|
||||
update={"allDay": 0},
|
||||
)
|
||||
|
||||
|
||||
def get_timesheets_list(
|
||||
doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"
|
||||
):
|
||||
def get_timesheets_list(doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"):
|
||||
user = frappe.session.user
|
||||
# find customer name from contact.
|
||||
customer = ""
|
||||
@@ -489,7 +481,7 @@ def get_timesheets_list(
|
||||
projects = [d.name for d in frappe.get_all("Project", filters={"customer": customer})]
|
||||
# Return timesheet related data to web portal.
|
||||
timesheets = frappe.db.sql(
|
||||
"""
|
||||
f"""
|
||||
SELECT
|
||||
ts.name, tsd.activity_type, ts.status, ts.total_billable_hours,
|
||||
COALESCE(ts.sales_invoice, tsd.sales_invoice) AS sales_invoice, tsd.project
|
||||
@@ -501,10 +493,8 @@ def get_timesheets_list(
|
||||
tsd.project IN %(projects)s
|
||||
)
|
||||
ORDER BY `end_date` ASC
|
||||
LIMIT {1} offset {0}
|
||||
""".format(
|
||||
limit_start, limit_page_length
|
||||
),
|
||||
LIMIT {limit_page_length} offset {limit_start}
|
||||
""",
|
||||
dict(sales_invoices=sales_invoices, projects=projects),
|
||||
as_dict=True,
|
||||
) # nosec
|
||||
|
||||
@@ -50,9 +50,7 @@ def get_data(filters):
|
||||
timesheets = get_timesheets(filters)
|
||||
|
||||
filters.from_date = frappe.utils.get_datetime(filters.from_date)
|
||||
filters.to_date = frappe.utils.add_to_date(
|
||||
frappe.utils.get_datetime(filters.to_date), days=1, seconds=-1
|
||||
)
|
||||
filters.to_date = frappe.utils.add_to_date(frappe.utils.get_datetime(filters.to_date), days=1, seconds=-1)
|
||||
|
||||
timesheet_details = get_timesheet_details(filters, timesheets.keys())
|
||||
|
||||
|
||||
@@ -31,14 +31,14 @@ class TestDelayedTasksSummary(unittest.TestCase):
|
||||
{"subject": "_Test Task 98", "status": "Completed", "priority": "Low", "delay": -1},
|
||||
]
|
||||
report = execute(filters)
|
||||
data = list(filter(lambda x: x.subject == "_Test Task 99", report[1]))[0]
|
||||
data = next(filter(lambda x: x.subject == "_Test Task 99", report[1]))
|
||||
|
||||
for key in ["subject", "status", "priority", "delay"]:
|
||||
self.assertEqual(expected_data[0].get(key), data.get(key))
|
||||
|
||||
filters.status = "Completed"
|
||||
report = execute(filters)
|
||||
data = list(filter(lambda x: x.subject == "_Test Task 98", report[1]))[0]
|
||||
data = next(filter(lambda x: x.subject == "_Test Task 98", report[1]))
|
||||
|
||||
for key in ["subject", "status", "priority", "delay"]:
|
||||
self.assertEqual(expected_data[1].get(key), data.get(key))
|
||||
|
||||
@@ -19,13 +19,14 @@ def query_task(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
return frappe.db.sql(
|
||||
"""select name, subject from `tabTask`
|
||||
where (`%s` like %s or `subject` like %s) %s
|
||||
where (`{}` like {} or `subject` like {}) {}
|
||||
order by
|
||||
case when `subject` like %s then 0 else 1 end,
|
||||
case when `%s` like %s then 0 else 1 end,
|
||||
`%s`,
|
||||
case when `subject` like {} then 0 else 1 end,
|
||||
case when `{}` like {} then 0 else 1 end,
|
||||
`{}`,
|
||||
subject
|
||||
limit %s offset %s"""
|
||||
% (searchfield, "%s", "%s", match_conditions, "%s", searchfield, "%s", searchfield, "%s", "%s"),
|
||||
limit {} offset {}""".format(
|
||||
searchfield, "%s", "%s", match_conditions, "%s", searchfield, "%s", searchfield, "%s", "%s"
|
||||
),
|
||||
(search_string, search_string, order_by_string, order_by_string, page_len, start),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user