style: format code with black
diff --git a/erpnext/templates/pages/courses.py b/erpnext/templates/pages/courses.py
index 6051e60..fb1af38 100644
--- a/erpnext/templates/pages/courses.py
+++ b/erpnext/templates/pages/courses.py
@@ -6,13 +6,13 @@
def get_context(context):
- course = frappe.get_doc('Course', frappe.form_dict.course)
+ course = frappe.get_doc("Course", frappe.form_dict.course)
sidebar_title = course.name
context.no_cache = 1
context.show_sidebar = True
- course = frappe.get_doc('Course', frappe.form_dict.course)
- course.has_permission('read')
+ course = frappe.get_doc("Course", frappe.form_dict.course)
+ course.has_permission("read")
context.doc = course
context.sidebar_title = sidebar_title
context.intro = course.course_intro
diff --git a/erpnext/templates/pages/help.py b/erpnext/templates/pages/help.py
index 6a83fc8..19993ee 100644
--- a/erpnext/templates/pages/help.py
+++ b/erpnext/templates/pages/help.py
@@ -25,21 +25,19 @@
else:
context.issues = []
+
def get_forum_posts(s):
- response = requests.get(s.forum_url + '/' + s.get_latest_query)
+ response = requests.get(s.forum_url + "/" + s.get_latest_query)
response.raise_for_status()
response_json = response.json()
- topics_data = {} # it will actually be an array
- key_list = s.response_key_list.split(',')
+ topics_data = {} # it will actually be an array
+ key_list = s.response_key_list.split(",")
for key in key_list:
topics_data = response_json.get(key) if not topics_data else topics_data.get(key)
for topic in topics_data:
- topic["link"] = s.forum_url + '/' + s.post_route_string + '/' + str(topic.get(s.post_route_key))
+ topic["link"] = s.forum_url + "/" + s.post_route_string + "/" + str(topic.get(s.post_route_key))
- post_params = {
- "title": s.post_title_key,
- "description": s.post_description_key
- }
+ post_params = {"title": s.post_title_key, "description": s.post_description_key}
return topics_data, post_params
diff --git a/erpnext/templates/pages/home.py b/erpnext/templates/pages/home.py
index d08e81b..bca3e56 100644
--- a/erpnext/templates/pages/home.py
+++ b/erpnext/templates/pages/home.py
@@ -6,46 +6,51 @@
no_cache = 1
+
def get_context(context):
- homepage = frappe.get_doc('Homepage')
+ homepage = frappe.get_doc("Homepage")
for item in homepage.products:
- route = frappe.db.get_value('Website Item', {"item_code": item.item_code}, 'route')
+ route = frappe.db.get_value("Website Item", {"item_code": item.item_code}, "route")
if route:
- item.route = '/' + route
+ item.route = "/" + route
homepage.title = homepage.title or homepage.company
context.title = homepage.title
context.homepage = homepage
- if homepage.hero_section_based_on == 'Homepage Section' and homepage.hero_section:
- homepage.hero_section_doc = frappe.get_doc('Homepage Section', homepage.hero_section)
+ if homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section:
+ homepage.hero_section_doc = frappe.get_doc("Homepage Section", homepage.hero_section)
if homepage.slideshow:
- doc = frappe.get_doc('Website Slideshow', homepage.slideshow)
+ doc = frappe.get_doc("Website Slideshow", homepage.slideshow)
context.slideshow = homepage.slideshow
context.slideshow_header = doc.header
context.slides = doc.slideshow_items
- context.blogs = frappe.get_all('Blog Post',
- fields=['title', 'blogger', 'blog_intro', 'route'],
- filters={
- 'published': 1
- },
- order_by='modified desc',
- limit=3
+ context.blogs = frappe.get_all(
+ "Blog Post",
+ fields=["title", "blogger", "blog_intro", "route"],
+ filters={"published": 1},
+ order_by="modified desc",
+ limit=3,
)
# filter out homepage section which is used as hero section
- homepage_hero_section = homepage.hero_section_based_on == 'Homepage Section' and homepage.hero_section
- homepage_sections = frappe.get_all('Homepage Section',
- filters=[['name', '!=', homepage_hero_section]] if homepage_hero_section else None,
- order_by='section_order asc'
+ homepage_hero_section = (
+ homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section
)
- context.homepage_sections = [frappe.get_doc('Homepage Section', name) for name in homepage_sections]
+ homepage_sections = frappe.get_all(
+ "Homepage Section",
+ filters=[["name", "!=", homepage_hero_section]] if homepage_hero_section else None,
+ order_by="section_order asc",
+ )
+ context.homepage_sections = [
+ frappe.get_doc("Homepage Section", name) for name in homepage_sections
+ ]
context.metatags = context.metatags or frappe._dict({})
context.metatags.image = homepage.hero_image or None
context.metatags.description = homepage.description or None
- context.explore_link = '/all-products'
+ context.explore_link = "/all-products"
diff --git a/erpnext/templates/pages/integrations/gocardless_checkout.py b/erpnext/templates/pages/integrations/gocardless_checkout.py
index bbdbf1d..280f67f 100644
--- a/erpnext/templates/pages/integrations/gocardless_checkout.py
+++ b/erpnext/templates/pages/integrations/gocardless_checkout.py
@@ -14,8 +14,18 @@
no_cache = 1
-expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'reference_docname',
- 'payer_name', 'payer_email', 'order_id', 'currency')
+expected_keys = (
+ "amount",
+ "title",
+ "description",
+ "reference_doctype",
+ "reference_docname",
+ "payer_name",
+ "payer_email",
+ "order_id",
+ "currency",
+)
+
def get_context(context):
context.no_cache = 1
@@ -25,17 +35,22 @@
for key in expected_keys:
context[key] = frappe.form_dict[key]
- context['amount'] = flt(context['amount'])
+ context["amount"] = flt(context["amount"])
gateway_controller = get_gateway_controller(context.reference_docname)
- context['header_img'] = frappe.db.get_value("GoCardless Settings", gateway_controller, "header_img")
+ context["header_img"] = frappe.db.get_value(
+ "GoCardless Settings", gateway_controller, "header_img"
+ )
else:
- frappe.redirect_to_message(_('Some information is missing'),
- _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.'))
+ frappe.redirect_to_message(
+ _("Some information is missing"),
+ _("Looks like someone sent you to an incomplete URL. Please ask them to look into it."),
+ )
frappe.local.flags.redirect_location = frappe.local.response.location
raise frappe.Redirect
+
@frappe.whitelist(allow_guest=True)
def check_mandate(data, reference_doctype, reference_docname):
data = json.loads(data)
@@ -59,23 +74,27 @@
prefilled_customer.update({"email": frappe.session.user})
else:
- prefilled_customer = {
- "company_name": payer.name,
- "email": frappe.session.user
- }
+ prefilled_customer = {"company_name": payer.name, "email": frappe.session.user}
- success_url = get_url("./integrations/gocardless_confirmation?reference_doctype=" + reference_doctype + "&reference_docname=" + reference_docname)
+ success_url = get_url(
+ "./integrations/gocardless_confirmation?reference_doctype="
+ + reference_doctype
+ + "&reference_docname="
+ + reference_docname
+ )
try:
- redirect_flow = client.redirect_flows.create(params={
- "description": _("Pay {0} {1}").format(data['amount'], data['currency']),
- "session_token": frappe.session.user,
- "success_redirect_url": success_url,
- "prefilled_customer": prefilled_customer
- })
+ redirect_flow = client.redirect_flows.create(
+ params={
+ "description": _("Pay {0} {1}").format(data["amount"], data["currency"]),
+ "session_token": frappe.session.user,
+ "success_redirect_url": success_url,
+ "prefilled_customer": prefilled_customer,
+ }
+ )
return {"redirect_to": redirect_flow.redirect_url}
except Exception as e:
frappe.log_error(e, "GoCardless Payment Error")
- return {"redirect_to": '/integrations/payment-failed'}
+ return {"redirect_to": "/integrations/payment-failed"}
diff --git a/erpnext/templates/pages/integrations/gocardless_confirmation.py b/erpnext/templates/pages/integrations/gocardless_confirmation.py
index a6c3e71..cab532a 100644
--- a/erpnext/templates/pages/integrations/gocardless_confirmation.py
+++ b/erpnext/templates/pages/integrations/gocardless_confirmation.py
@@ -11,7 +11,8 @@
no_cache = 1
-expected_keys = ('redirect_flow_id', 'reference_doctype', 'reference_docname')
+expected_keys = ("redirect_flow_id", "reference_doctype", "reference_docname")
+
def get_context(context):
context.no_cache = 1
@@ -22,11 +23,14 @@
context[key] = frappe.form_dict[key]
else:
- frappe.redirect_to_message(_('Some information is missing'),
- _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.'))
+ frappe.redirect_to_message(
+ _("Some information is missing"),
+ _("Looks like someone sent you to an incomplete URL. Please ask them to look into it."),
+ )
frappe.local.flags.redirect_location = frappe.local.response.location
raise frappe.Redirect
+
@frappe.whitelist(allow_guest=True)
def confirm_payment(redirect_flow_id, reference_doctype, reference_docname):
@@ -34,15 +38,15 @@
try:
redirect_flow = client.redirect_flows.complete(
- redirect_flow_id,
- params={
- "session_token": frappe.session.user
- })
+ redirect_flow_id, params={"session_token": frappe.session.user}
+ )
confirmation_url = redirect_flow.confirmation_url
- gocardless_success_page = frappe.get_hooks('gocardless_success_page')
+ gocardless_success_page = frappe.get_hooks("gocardless_success_page")
if gocardless_success_page:
- confirmation_url = frappe.get_attr(gocardless_success_page[-1])(reference_doctype, reference_docname)
+ confirmation_url = frappe.get_attr(gocardless_success_page[-1])(
+ reference_doctype, reference_docname
+ )
data = {
"mandate": redirect_flow.links.mandate,
@@ -50,7 +54,7 @@
"redirect_to": confirmation_url,
"redirect_message": "Mandate successfully created",
"reference_doctype": reference_doctype,
- "reference_docname": reference_docname
+ "reference_docname": reference_docname,
}
try:
@@ -65,29 +69,38 @@
except Exception as e:
frappe.log_error(e, "GoCardless Payment Error")
- return {"redirect_to": '/integrations/payment-failed'}
+ return {"redirect_to": "/integrations/payment-failed"}
def create_mandate(data):
data = frappe._dict(data)
frappe.logger().debug(data)
- mandate = data.get('mandate')
+ mandate = data.get("mandate")
if frappe.db.exists("GoCardless Mandate", mandate):
return
else:
- reference_doc = frappe.db.get_value(data.get('reference_doctype'), data.get('reference_docname'), ["reference_doctype", "reference_name"], as_dict=1)
- erpnext_customer = frappe.db.get_value(reference_doc.reference_doctype, reference_doc.reference_name, ["customer_name"], as_dict=1)
+ reference_doc = frappe.db.get_value(
+ data.get("reference_doctype"),
+ data.get("reference_docname"),
+ ["reference_doctype", "reference_name"],
+ as_dict=1,
+ )
+ erpnext_customer = frappe.db.get_value(
+ reference_doc.reference_doctype, reference_doc.reference_name, ["customer_name"], as_dict=1
+ )
try:
- frappe.get_doc({
- "doctype": "GoCardless Mandate",
- "mandate": mandate,
- "customer": erpnext_customer.customer_name,
- "gocardless_customer": data.get('customer')
- }).insert(ignore_permissions=True)
+ frappe.get_doc(
+ {
+ "doctype": "GoCardless Mandate",
+ "mandate": mandate,
+ "customer": erpnext_customer.customer_name,
+ "gocardless_customer": data.get("customer"),
+ }
+ ).insert(ignore_permissions=True)
except Exception:
frappe.log_error(frappe.get_traceback())
diff --git a/erpnext/templates/pages/material_request_info.py b/erpnext/templates/pages/material_request_info.py
index 65d4427..301ca01 100644
--- a/erpnext/templates/pages/material_request_info.py
+++ b/erpnext/templates/pages/material_request_info.py
@@ -20,17 +20,23 @@
if not frappe.has_website_permission(context.doc):
frappe.throw(_("Not Permitted"), frappe.PermissionError)
- default_print_format = frappe.db.get_value('Property Setter', dict(property='default_print_format', doc_type=frappe.form_dict.doctype), "value")
+ default_print_format = frappe.db.get_value(
+ "Property Setter",
+ dict(property="default_print_format", doc_type=frappe.form_dict.doctype),
+ "value",
+ )
if default_print_format:
context.print_format = default_print_format
else:
context.print_format = "Standard"
context.doc.items = get_more_items_info(context.doc.items, context.doc.name)
+
def get_more_items_info(items, material_request):
for item in items:
- item.customer_provided = frappe.get_value('Item', item.item_code, 'is_customer_provided_item')
- item.work_orders = frappe.db.sql("""
+ item.customer_provided = frappe.get_value("Item", item.item_code, "is_customer_provided_item")
+ item.work_orders = frappe.db.sql(
+ """
select
wo.name, wo.status, wo_item.consumed_qty
from
@@ -41,9 +47,16 @@
and wo_item.parent=wo.name
and wo.status not in ('Completed', 'Cancelled', 'Stopped')
order by
- wo.name asc""", item.item_code, as_dict=1)
- item.delivered_qty = flt(frappe.db.sql("""select sum(transfer_qty)
+ wo.name asc""",
+ item.item_code,
+ as_dict=1,
+ )
+ item.delivered_qty = flt(
+ frappe.db.sql(
+ """select sum(transfer_qty)
from `tabStock Entry Detail` where material_request = %s
and item_code = %s and docstatus = 1""",
- (material_request, item.item_code))[0][0])
+ (material_request, item.item_code),
+ )[0][0]
+ )
return items
diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py
index 712b141..3e6d57a 100644
--- a/erpnext/templates/pages/order.py
+++ b/erpnext/templates/pages/order.py
@@ -19,12 +19,17 @@
context.parents = frappe.form_dict.parents
context.title = frappe.form_dict.name
- context.payment_ref = frappe.db.get_value("Payment Request",
- {"reference_name": frappe.form_dict.name}, "name")
+ context.payment_ref = frappe.db.get_value(
+ "Payment Request", {"reference_name": frappe.form_dict.name}, "name"
+ )
context.enabled_checkout = frappe.get_doc("E Commerce Settings").enable_checkout
- default_print_format = frappe.db.get_value('Property Setter', dict(property='default_print_format', doc_type=frappe.form_dict.doctype), "value")
+ default_print_format = frappe.db.get_value(
+ "Property Setter",
+ dict(property="default_print_format", doc_type=frappe.form_dict.doctype),
+ "value",
+ )
if default_print_format:
context.print_format = default_print_format
else:
@@ -34,15 +39,23 @@
frappe.throw(_("Not Permitted"), frappe.PermissionError)
# check for the loyalty program of the customer
- customer_loyalty_program = frappe.db.get_value("Customer", context.doc.customer, "loyalty_program")
+ customer_loyalty_program = frappe.db.get_value(
+ "Customer", context.doc.customer, "loyalty_program"
+ )
if customer_loyalty_program:
from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
get_loyalty_program_details_with_points,
)
- loyalty_program_details = get_loyalty_program_details_with_points(context.doc.customer, customer_loyalty_program)
+
+ loyalty_program_details = get_loyalty_program_details_with_points(
+ context.doc.customer, customer_loyalty_program
+ )
context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
+
def get_attachments(dt, dn):
- return frappe.get_all("File",
- fields=["name", "file_name", "file_url", "is_private"],
- filters = {"attached_to_name": dn, "attached_to_doctype": dt, "is_private":0})
+ return frappe.get_all(
+ "File",
+ fields=["name", "file_name", "file_url", "is_private"],
+ filters={"attached_to_name": dn, "attached_to_doctype": dt, "is_private": 0},
+ )
diff --git a/erpnext/templates/pages/partners.py b/erpnext/templates/pages/partners.py
index e4043ea..8a49504 100644
--- a/erpnext/templates/pages/partners.py
+++ b/erpnext/templates/pages/partners.py
@@ -6,11 +6,12 @@
page_title = "Partners"
-def get_context(context):
- partners = frappe.db.sql("""select * from `tabSales Partner`
- where show_in_website=1 order by name asc""", as_dict=True)
- return {
- "partners": partners,
- "title": page_title
- }
+def get_context(context):
+ partners = frappe.db.sql(
+ """select * from `tabSales Partner`
+ where show_in_website=1 order by name asc""",
+ as_dict=True,
+ )
+
+ return {"partners": partners, "title": page_title}
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index 237adf9..77a749e 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -17,9 +17,11 @@
no_cache = 1
+
def get_context(context):
context.show_search = True
+
@frappe.whitelist(allow_guest=True)
def get_product_list(search=None, start=0, limit=12):
data = get_product_data(search, start, limit)
@@ -29,6 +31,7 @@
return [get_item_for_list_in_html(r) for r in data]
+
def get_product_data(search=None, start=0, limit=12):
# limit = 12 because we show 12 items in the grid view
# base query
@@ -53,7 +56,8 @@
# order by
query += """ ORDER BY ranking desc, modified desc limit %s, %s""" % (cint(start), cint(limit))
- return frappe.db.sql(query, {"search": search}, as_dict=1) # nosemgrep
+ return frappe.db.sql(query, {"search": search}, as_dict=1) # nosemgrep
+
@frappe.whitelist(allow_guest=True)
def search(query):
@@ -62,9 +66,10 @@
return {
"product_results": product_results.get("results") or [],
- "category_results": category_results.get("results") or []
+ "category_results": category_results.get("results") or [],
}
+
@frappe.whitelist(allow_guest=True)
def product_search(query, limit=10, fuzzy_search=True):
search_results = {"from_redisearch": True, "results": []}
@@ -84,9 +89,7 @@
ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=red)
client = Client(make_key(WEBSITE_ITEM_INDEX), conn=red)
suggestions = ac.get_suggestions(
- query,
- num=limit,
- fuzzy= fuzzy_search and len(query) > 3 # Fuzzy on length < 3 can be real slow
+ query, num=limit, fuzzy=fuzzy_search and len(query) > 3 # Fuzzy on length < 3 can be real slow
)
# Build a query
@@ -98,17 +101,22 @@
q = Query(query_string)
results = client.search(q)
- search_results['results'] = list(map(convert_to_dict, results.docs))
- search_results['results'] = sorted(search_results['results'], key=lambda k: frappe.utils.cint(k['ranking']), reverse=True)
+ search_results["results"] = list(map(convert_to_dict, results.docs))
+ search_results["results"] = sorted(
+ search_results["results"], key=lambda k: frappe.utils.cint(k["ranking"]), reverse=True
+ )
return search_results
+
def clean_up_query(query):
- return ''.join(c for c in query if c.isalnum() or c.isspace())
+ return "".join(c for c in query if c.isalnum() or c.isspace())
+
def convert_to_dict(redis_search_doc):
return redis_search_doc.__dict__
+
@frappe.whitelist(allow_guest=True)
def get_category_suggestions(query):
search_results = {"results": []}
@@ -117,13 +125,10 @@
# Redisearch module not loaded, query db
categories = frappe.db.get_all(
"Item Group",
- filters={
- "name": ["like", "%{0}%".format(query)],
- "show_in_website": 1
- },
- fields=["name", "route"]
+ filters={"name": ["like", "%{0}%".format(query)], "show_in_website": 1},
+ fields=["name", "route"],
)
- search_results['results'] = categories
+ search_results["results"] = categories
return search_results
if not query:
@@ -132,6 +137,6 @@
ac = AutoCompleter(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE), conn=frappe.cache())
suggestions = ac.get_suggestions(query, num=10)
- search_results['results'] = [s.string for s in suggestions]
+ search_results["results"] = [s.string for s in suggestions]
- return search_results
\ No newline at end of file
+ return search_results
diff --git a/erpnext/templates/pages/projects.py b/erpnext/templates/pages/projects.py
index 16aa439..4b3089b 100644
--- a/erpnext/templates/pages/projects.py
+++ b/erpnext/templates/pages/projects.py
@@ -6,21 +6,28 @@
def get_context(context):
- project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , ["user", "view_attachments"], as_dict= True)
- if frappe.session.user != 'Administrator' and (not project_user or frappe.session.user == 'Guest'):
+ project_user = frappe.db.get_value(
+ "Project User",
+ {"parent": frappe.form_dict.project, "user": frappe.session.user},
+ ["user", "view_attachments"],
+ as_dict=True,
+ )
+ if frappe.session.user != "Administrator" and (
+ not project_user or frappe.session.user == "Guest"
+ ):
raise frappe.PermissionError
context.no_cache = 1
context.show_sidebar = True
- project = frappe.get_doc('Project', frappe.form_dict.project)
+ project = frappe.get_doc("Project", frappe.form_dict.project)
- project.has_permission('read')
+ project.has_permission("read")
- project.tasks = get_tasks(project.name, start=0, item_status='open',
- search=frappe.form_dict.get("search"))
+ project.tasks = get_tasks(
+ project.name, start=0, item_status="open", search=frappe.form_dict.get("search")
+ )
- project.timesheets = get_timesheets(project.name, start=0,
- search=frappe.form_dict.get("search"))
+ project.timesheets = get_timesheets(project.name, start=0, search=frappe.form_dict.get("search"))
if project_user and project_user.view_attachments:
project.attachments = get_attachments(project.name)
@@ -32,9 +39,22 @@
filters = {"project": project}
if search:
filters["subject"] = ("like", "%{0}%".format(search))
- tasks = frappe.get_all("Task", filters=filters,
- fields=["name", "subject", "status", "modified", "_assign", "exp_end_date", "is_group", "parent_task"],
- limit_start=start, limit_page_length=10)
+ tasks = frappe.get_all(
+ "Task",
+ filters=filters,
+ fields=[
+ "name",
+ "subject",
+ "status",
+ "modified",
+ "_assign",
+ "exp_end_date",
+ "is_group",
+ "parent_task",
+ ],
+ limit_start=start,
+ limit_page_length=10,
+ )
task_nest = []
for task in tasks:
if task.is_group:
@@ -44,36 +64,59 @@
task_nest.append(task)
return list(filter(lambda x: not x.parent_task, tasks))
+
@frappe.whitelist()
def get_task_html(project, start=0, item_status=None):
- return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
- {"doc": {
- "name": project,
- "project_name": project,
- "tasks": get_tasks(project, start, item_status=item_status)}
- }, is_path=True)
+ return frappe.render_template(
+ "erpnext/templates/includes/projects/project_tasks.html",
+ {
+ "doc": {
+ "name": project,
+ "project_name": project,
+ "tasks": get_tasks(project, start, item_status=item_status),
+ }
+ },
+ is_path=True,
+ )
+
def get_timesheets(project, start=0, search=None):
filters = {"project": project}
if search:
filters["activity_type"] = ("like", "%{0}%".format(search))
- timesheets = frappe.get_all('Timesheet Detail', filters=filters,
- fields=['project','activity_type','from_time','to_time','parent'],
- limit_start=start, limit_page_length=10)
+ timesheets = frappe.get_all(
+ "Timesheet Detail",
+ filters=filters,
+ fields=["project", "activity_type", "from_time", "to_time", "parent"],
+ limit_start=start,
+ limit_page_length=10,
+ )
for timesheet in timesheets:
- info = frappe.get_all('Timesheet', filters={"name": timesheet.parent},
- fields=['name','status','modified','modified_by'],
- limit_start=start, limit_page_length=10)
+ info = frappe.get_all(
+ "Timesheet",
+ filters={"name": timesheet.parent},
+ fields=["name", "status", "modified", "modified_by"],
+ limit_start=start,
+ limit_page_length=10,
+ )
if len(info):
timesheet.update(info[0])
return timesheets
+
@frappe.whitelist()
def get_timesheet_html(project, start=0):
- return frappe.render_template("erpnext/templates/includes/projects/project_timesheets.html",
- {"doc": {"timesheets": get_timesheets(project, start)}}, is_path=True)
+ return frappe.render_template(
+ "erpnext/templates/includes/projects/project_timesheets.html",
+ {"doc": {"timesheets": get_timesheets(project, start)}},
+ is_path=True,
+ )
+
def get_attachments(project):
- return frappe.get_all('File', filters= {"attached_to_name": project, "attached_to_doctype": 'Project', "is_private":0},
- fields=['file_name','file_url', 'file_size'])
+ return frappe.get_all(
+ "File",
+ filters={"attached_to_name": project, "attached_to_doctype": "Project", "is_private": 0},
+ fields=["file_name", "file_url", "file_size"],
+ )
diff --git a/erpnext/templates/pages/regional/india/update_gstin.py b/erpnext/templates/pages/regional/india/update_gstin.py
index 95b8f72..6939fe4 100644
--- a/erpnext/templates/pages/regional/india/update_gstin.py
+++ b/erpnext/templates/pages/regional/india/update_gstin.py
@@ -11,12 +11,12 @@
except frappe.ValidationError:
context.invalid_gstin = 1
- party_type = 'Customer'
- party_name = frappe.db.get_value('Customer', party)
+ party_type = "Customer"
+ party_name = frappe.db.get_value("Customer", party)
if not party_name:
- party_type = 'Supplier'
- party_name = frappe.db.get_value('Supplier', party)
+ party_type = "Supplier"
+ party_name = frappe.db.get_value("Supplier", party)
if not party_name:
context.not_found = 1
@@ -29,10 +29,10 @@
def update_gstin(context):
dirty = False
for key, value in frappe.form_dict.items():
- if key != 'party':
- address_name = frappe.get_value('Address', key)
+ if key != "party":
+ address_name = frappe.get_value("Address", key)
if address_name:
- address = frappe.get_doc('Address', address_name)
+ address = frappe.get_doc("Address", address_name)
address.gstin = value.upper()
address.save(ignore_permissions=True)
dirty = True
diff --git a/erpnext/templates/pages/rfq.py b/erpnext/templates/pages/rfq.py
index 0afd46c..4b83642 100644
--- a/erpnext/templates/pages/rfq.py
+++ b/erpnext/templates/pages/rfq.py
@@ -20,40 +20,59 @@
update_supplier_details(context)
context["title"] = frappe.form_dict.name
+
def get_supplier():
doctype = frappe.form_dict.doctype
- parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype
+ parties_doctype = (
+ "Request for Quotation Supplier" if doctype == "Request for Quotation" else doctype
+ )
customers, suppliers = get_customers_suppliers(parties_doctype, frappe.session.user)
- return suppliers[0] if suppliers else ''
+ return suppliers[0] if suppliers else ""
+
def check_supplier_has_docname_access(supplier):
status = True
- if frappe.form_dict.name not in frappe.db.sql_list("""select parent from `tabRequest for Quotation Supplier`
- where supplier = %s""", (supplier,)):
+ if frappe.form_dict.name not in frappe.db.sql_list(
+ """select parent from `tabRequest for Quotation Supplier`
+ where supplier = %s""",
+ (supplier,),
+ ):
status = False
return status
+
def unauthorized_user(supplier):
status = check_supplier_has_docname_access(supplier) or False
if status == False:
frappe.throw(_("Not Permitted"), frappe.PermissionError)
+
def update_supplier_details(context):
supplier_doc = frappe.get_doc("Supplier", context.doc.supplier)
- context.doc.currency = supplier_doc.default_currency or frappe.get_cached_value('Company', context.doc.company, "default_currency")
- context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol", cache=True)
- context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format", cache=True)
- context.doc.buying_price_list = supplier_doc.default_price_list or ''
+ context.doc.currency = supplier_doc.default_currency or frappe.get_cached_value(
+ "Company", context.doc.company, "default_currency"
+ )
+ context.doc.currency_symbol = frappe.db.get_value(
+ "Currency", context.doc.currency, "symbol", cache=True
+ )
+ context.doc.number_format = frappe.db.get_value(
+ "Currency", context.doc.currency, "number_format", cache=True
+ )
+ context.doc.buying_price_list = supplier_doc.default_price_list or ""
+
def get_link_quotation(supplier, rfq):
- quotation = frappe.db.sql(""" select distinct `tabSupplier Quotation Item`.parent as name,
+ quotation = frappe.db.sql(
+ """ select distinct `tabSupplier Quotation Item`.parent as name,
`tabSupplier Quotation`.status, `tabSupplier Quotation`.transaction_date from
`tabSupplier Quotation Item`, `tabSupplier Quotation` where `tabSupplier Quotation`.docstatus < 2 and
`tabSupplier Quotation Item`.request_for_quotation =%(name)s and
`tabSupplier Quotation Item`.parent = `tabSupplier Quotation`.name and
`tabSupplier Quotation`.supplier = %(supplier)s order by `tabSupplier Quotation`.creation desc""",
- {'name': rfq, 'supplier': supplier}, as_dict=1)
+ {"name": rfq, "supplier": supplier},
+ as_dict=1,
+ )
for data in quotation:
data.transaction_date = formatdate(data.transaction_date)
diff --git a/erpnext/templates/pages/search_help.py b/erpnext/templates/pages/search_help.py
index 1ef3942..a6877ce 100644
--- a/erpnext/templates/pages/search_help.py
+++ b/erpnext/templates/pages/search_help.py
@@ -11,17 +11,18 @@
context.no_cache = 1
if frappe.form_dict.q:
query = str(utils.escape(sanitize_html(frappe.form_dict.q)))
- context.title = _('Help Results for')
+ context.title = _("Help Results for")
context.query = query
- context.route = '/search_help'
+ context.route = "/search_help"
d = frappe._dict()
d.results_sections = get_help_results_sections(query)
context.update(d)
else:
- context.title = _('Docs Search')
+ context.title = _("Docs Search")
-@frappe.whitelist(allow_guest = True)
+
+@frappe.whitelist(allow_guest=True)
def get_help_results_sections(text):
out = []
settings = frappe.get_doc("Support Settings", "Support Settings")
@@ -40,63 +41,72 @@
if results:
# Add section
- out.append({
- "title": api.source_name,
- "results": results
- })
+ out.append({"title": api.source_name, "results": results})
return out
+
def get_response(api, text):
- response = requests.get(api.base_url + '/' + api.query_route, data={
- api.search_term_param_name: text
- })
+ response = requests.get(
+ api.base_url + "/" + api.query_route, data={api.search_term_param_name: text}
+ )
response.raise_for_status()
return response.json()
+
def get_topics_data(api, response_json):
if not response_json:
response_json = {}
- topics_data = {} # it will actually be an array
- key_list = api.response_result_key_path.split(',')
+ topics_data = {} # it will actually be an array
+ key_list = api.response_result_key_path.split(",")
for key in key_list:
topics_data = response_json.get(key) if not topics_data else topics_data.get(key)
return topics_data or []
+
def prepare_api_results(api, topics_data):
if not topics_data:
topics_data = []
results = []
for topic in topics_data:
- route = api.base_url + '/' + (api.post_route + '/' if api.post_route else "")
- for key in api.post_route_key_list.split(','):
+ route = api.base_url + "/" + (api.post_route + "/" if api.post_route else "")
+ for key in api.post_route_key_list.split(","):
route += str(topic[key])
- results.append(frappe._dict({
- 'title': topic[api.post_title_key],
- 'preview': html2text(topic[api.post_description_key]),
- 'route': route
- }))
+ results.append(
+ frappe._dict(
+ {
+ "title": topic[api.post_title_key],
+ "preview": html2text(topic[api.post_description_key]),
+ "route": route,
+ }
+ )
+ )
return results[:5]
+
def prepare_doctype_results(api, raw):
results = []
for r in raw:
prepared_result = {}
- parts = r["content"].split(' ||| ')
+ parts = r["content"].split(" ||| ")
for part in parts:
- pair = part.split(' : ', 1)
+ pair = part.split(" : ", 1)
prepared_result[pair[0]] = pair[1]
- results.append(frappe._dict({
- 'title': prepared_result[api.result_title_field],
- 'preview': prepared_result[api.result_preview_field],
- 'route': prepared_result[api.result_route_field]
- }))
+ results.append(
+ frappe._dict(
+ {
+ "title": prepared_result[api.result_title_field],
+ "preview": prepared_result[api.result_preview_field],
+ "route": prepared_result[api.result_route_field],
+ }
+ )
+ )
return results
diff --git a/erpnext/templates/pages/task_info.py b/erpnext/templates/pages/task_info.py
index d1a70e1..66b775a 100644
--- a/erpnext/templates/pages/task_info.py
+++ b/erpnext/templates/pages/task_info.py
@@ -4,9 +4,12 @@
def get_context(context):
context.no_cache = 1
- task = frappe.get_doc('Task', frappe.form_dict.task)
+ task = frappe.get_doc("Task", frappe.form_dict.task)
- context.comments = frappe.get_all('Communication', filters={'reference_name': task.name, 'comment_type': 'comment'},
- fields=['subject', 'sender_full_name', 'communication_date'])
+ context.comments = frappe.get_all(
+ "Communication",
+ filters={"reference_name": task.name, "comment_type": "comment"},
+ fields=["subject", "sender_full_name", "communication_date"],
+ )
context.doc = task
diff --git a/erpnext/templates/pages/timelog_info.py b/erpnext/templates/pages/timelog_info.py
index db61e7e..3f0ec37 100644
--- a/erpnext/templates/pages/timelog_info.py
+++ b/erpnext/templates/pages/timelog_info.py
@@ -4,6 +4,6 @@
def get_context(context):
context.no_cache = 1
- timelog = frappe.get_doc('Time Log', frappe.form_dict.timelog)
+ timelog = frappe.get_doc("Time Log", frappe.form_dict.timelog)
context.doc = timelog
diff --git a/erpnext/templates/pages/wishlist.py b/erpnext/templates/pages/wishlist.py
index 72ee34e..d70f27c 100644
--- a/erpnext/templates/pages/wishlist.py
+++ b/erpnext/templates/pages/wishlist.py
@@ -23,31 +23,33 @@
context.settings = settings
context.no_cache = 1
+
def get_stock_availability(item_code, warehouse):
stock_qty = frappe.utils.flt(
- frappe.db.get_value("Bin",
- {
- "item_code": item_code,
- "warehouse": warehouse
- },
- "actual_qty")
+ frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, "actual_qty")
)
return bool(stock_qty)
+
def get_wishlist_items():
if not frappe.db.exists("Wishlist", frappe.session.user):
return []
return frappe.db.get_all(
"Wishlist Item",
- filters={
- "parent": frappe.session.user
- },
+ filters={"parent": frappe.session.user},
fields=[
- "web_item_name", "item_code", "item_name",
- "website_item", "warehouse",
- "image", "item_group", "route"
- ])
+ "web_item_name",
+ "item_code",
+ "item_name",
+ "website_item",
+ "warehouse",
+ "image",
+ "item_group",
+ "route",
+ ],
+ )
+
def set_stock_price_details(items, settings, selling_price_list):
for item in items:
@@ -55,17 +57,15 @@
item.available = get_stock_availability(item.item_code, item.get("warehouse"))
price_details = get_price(
- item.item_code,
- selling_price_list,
- settings.default_customer_group,
- settings.company
+ item.item_code, selling_price_list, settings.default_customer_group, settings.company
)
if price_details:
- item.formatted_price = price_details.get('formatted_price')
- item.formatted_mrp = price_details.get('formatted_mrp')
+ item.formatted_price = price_details.get("formatted_price")
+ item.formatted_mrp = price_details.get("formatted_mrp")
if item.formatted_mrp:
- item.discount = price_details.get('formatted_discount_percent') or \
- price_details.get('formatted_discount_rate')
+ item.discount = price_details.get("formatted_discount_percent") or price_details.get(
+ "formatted_discount_rate"
+ )
- return items
\ No newline at end of file
+ return items