mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-23 13:12:22 +01:00
refactor(setup): type annotataions for whitelisted methods
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
import json
|
||||
from typing import Literal
|
||||
|
||||
import frappe
|
||||
import frappe.defaults
|
||||
@@ -938,7 +939,7 @@ def cache_companies_monthly_sales_history():
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(doctype, parent=None, company=None, is_root=False):
|
||||
def get_children(doctype: str, parent: str | None = None, company: str | None = None, is_root: bool = False):
|
||||
if parent is None or parent == "All Companies":
|
||||
parent = ""
|
||||
|
||||
@@ -1045,10 +1046,11 @@ def get_timeline_data(doctype, name):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_default_company_address(name, sort_key="is_primary_address", existing_address=None):
|
||||
if sort_key not in ["is_shipping_address", "is_primary_address"]:
|
||||
return None
|
||||
|
||||
def get_default_company_address(
|
||||
name: str,
|
||||
sort_key: Literal["is_shipping_address", "is_primary_address"] = "is_primary_address",
|
||||
existing_address: str | None = None,
|
||||
):
|
||||
out = frappe.db.sql(
|
||||
""" SELECT
|
||||
addr.name, addr.{}
|
||||
@@ -1072,7 +1074,9 @@ def get_default_company_address(name, sort_key="is_primary_address", existing_ad
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_billing_shipping_address(name, billing_address=None, shipping_address=None):
|
||||
def get_billing_shipping_address(
|
||||
name: str, billing_address: str | None = None, shipping_address: str | None = None
|
||||
):
|
||||
primary_address = get_default_company_address(name, "is_primary_address", billing_address)
|
||||
shipping_address = get_default_company_address(name, "is_shipping_address", shipping_address)
|
||||
|
||||
@@ -1080,7 +1084,7 @@ def get_billing_shipping_address(name, billing_address=None, shipping_address=No
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_transaction_deletion_request(company):
|
||||
def create_transaction_deletion_request(company: str):
|
||||
frappe.only_for("System Manager")
|
||||
|
||||
from erpnext.setup.doctype.transaction_deletion_record.transaction_deletion_record import (
|
||||
|
||||
@@ -70,7 +70,13 @@ def get_abbreviated_name(name, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(doctype, parent=None, company=None, is_root=False, include_disabled=False):
|
||||
def get_children(
|
||||
doctype: str,
|
||||
parent: str | None = None,
|
||||
company: str | None = None,
|
||||
is_root: bool = False,
|
||||
include_disabled: str | dict | None = None,
|
||||
):
|
||||
if isinstance(include_disabled, str):
|
||||
include_disabled = json.loads(include_disabled)
|
||||
fields = ["name as value", "is_group as expandable"]
|
||||
|
||||
@@ -900,7 +900,7 @@ def send():
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_digest_msg(name):
|
||||
def get_digest_msg(name: str):
|
||||
return frappe.get_doc("Email Digest", name).get_msg_html()
|
||||
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ def is_holiday(employee, date=None, raise_exception=True, only_non_weekly=False,
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def deactivate_sales_person(status=None, employee=None):
|
||||
def deactivate_sales_person(status: str | None = None, employee: str | None = None):
|
||||
if status == "Left":
|
||||
sales_person = frappe.db.get_value("Sales Person", {"Employee": employee})
|
||||
if sales_person:
|
||||
@@ -312,7 +312,7 @@ def deactivate_sales_person(status=None, employee=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_user(employee, user=None, email=None):
|
||||
def create_user(employee: str, email: str | None = None):
|
||||
emp = frappe.get_doc("Employee", employee)
|
||||
|
||||
employee_name = emp.employee_name.split(" ")
|
||||
@@ -384,7 +384,13 @@ def get_employee_emails(employee_list):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(doctype, parent=None, company=None, is_root=False, is_tree=False):
|
||||
def get_children(
|
||||
doctype: str,
|
||||
parent: str | None = None,
|
||||
company: str | None = None,
|
||||
is_root: bool = False,
|
||||
is_tree: bool = False,
|
||||
):
|
||||
filters = [["status", "=", "Active"]]
|
||||
if company and company != "All Companies":
|
||||
filters.append(["company", "=", company])
|
||||
|
||||
@@ -8,7 +8,7 @@ from datetime import date
|
||||
import frappe
|
||||
from frappe import _, throw
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import formatdate, getdate, today
|
||||
from frappe.utils import DateTimeLikeObject, formatdate, getdate, today
|
||||
|
||||
|
||||
class OverlapError(frappe.ValidationError):
|
||||
@@ -168,7 +168,7 @@ class HolidayList(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_events(start, end, filters=None):
|
||||
def get_events(start: DateTimeLikeObject, end: DateTimeLikeObject, filters: str | dict | None = None):
|
||||
"""Returns events for Gantt / Calendar view rendering.
|
||||
|
||||
:param start: Start date-time.
|
||||
|
||||
@@ -24,7 +24,7 @@ class PartyType(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_party_type(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_party_type(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
cond = ""
|
||||
account_type = None
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class TermsandConditions(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_terms_and_conditions(template_name, doc):
|
||||
def get_terms_and_conditions(template_name: str, doc: str | dict):
|
||||
if isinstance(doc, str):
|
||||
doc = json.loads(doc)
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ def get_protected_doctypes():
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_company_link_fields(doctype_name):
|
||||
def get_company_link_fields(doctype_name: str):
|
||||
"""Get all Company Link field names for a DocType (whitelisted for frontend autocomplete)
|
||||
|
||||
Args:
|
||||
@@ -428,7 +428,9 @@ class TransactionDeletionRecord(Document):
|
||||
return {"count": len(self.doctypes_to_delete)}
|
||||
|
||||
@frappe.whitelist()
|
||||
def populate_doctype_details(self, doctype_name, company=None, company_field=None):
|
||||
def populate_doctype_details(
|
||||
self, doctype_name: str, company: str | None = None, company_field: str | None = None
|
||||
):
|
||||
"""Get child DocTypes and document count for specified DocType
|
||||
|
||||
Args:
|
||||
@@ -1035,7 +1037,7 @@ def get_doctypes_to_be_ignored():
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def export_to_delete_template(name):
|
||||
def export_to_delete_template(name: str):
|
||||
"""Export To Delete list as CSV via URL access"""
|
||||
frappe.only_for("System Manager")
|
||||
doc = frappe.get_doc("Transaction Deletion Record", name)
|
||||
@@ -1044,7 +1046,7 @@ def export_to_delete_template(name):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def process_import_template(transaction_deletion_record_name, file_url):
|
||||
def process_import_template(transaction_deletion_record_name: str, file_url: str):
|
||||
"""Import CSV template and populate To Delete list"""
|
||||
import os
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import add_days, flt, get_datetime_str, nowdate
|
||||
from frappe.utils.data import now_datetime
|
||||
from frappe.utils.data import DateTimeLikeObject, now_datetime
|
||||
from frappe.utils.nestedset import get_root_of
|
||||
|
||||
from erpnext import get_default_company
|
||||
@@ -92,7 +92,12 @@ def get_pegged_rate(pegged_map, from_currency, to_currency, transaction_date=Non
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=None):
|
||||
def get_exchange_rate(
|
||||
from_currency: str,
|
||||
to_currency: str,
|
||||
transaction_date: DateTimeLikeObject | None = None,
|
||||
args: str | None = None,
|
||||
):
|
||||
if not (from_currency and to_currency):
|
||||
# manqala 19/09/2016: Should this be an empty return or should it throw and exception?
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user