mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-30 04:05:43 +00:00
refactor(accounts): add type hints for whitelisted functions
This commit is contained in:
@@ -52,7 +52,7 @@ class ERPNextAddress(Address):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_shipping_address(company, address=None):
|
||||
def get_shipping_address(company: str, address: str | None = None):
|
||||
filters = [
|
||||
["Dynamic Link", "link_doctype", "=", "Company"],
|
||||
["Dynamic Link", "link_name", "=", company],
|
||||
|
||||
@@ -13,15 +13,15 @@ from frappe.utils.nestedset import get_descendants_of
|
||||
@frappe.whitelist()
|
||||
@cache_source
|
||||
def get(
|
||||
chart_name=None,
|
||||
chart=None,
|
||||
no_cache=None,
|
||||
filters=None,
|
||||
from_date=None,
|
||||
to_date=None,
|
||||
timespan=None,
|
||||
time_interval=None,
|
||||
heatmap_year=None,
|
||||
chart_name: str | None = None,
|
||||
chart: str | dict | None = None,
|
||||
no_cache: bool | None = None,
|
||||
filters: str | dict | None = None,
|
||||
from_date: str | None = None,
|
||||
to_date: str | None = None,
|
||||
timespan: str | None = None,
|
||||
time_interval: str | None = None,
|
||||
heatmap_year: str | None = None,
|
||||
):
|
||||
if chart_name:
|
||||
chart = frappe.get_doc("Dashboard Chart", chart_name)
|
||||
|
||||
@@ -471,7 +471,7 @@ class Account(NestedSet):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_parent_account(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
return frappe.db.sql(
|
||||
"""select name from tabAccount
|
||||
where is_group = 1 and docstatus != 2 and company = {}
|
||||
@@ -515,7 +515,9 @@ def get_account_autoname(account_number, account_name, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_account_number(name, account_name, account_number=None, from_descendant=False):
|
||||
def update_account_number(
|
||||
name: str, account_name: str, account_number: str | None = None, from_descendant: bool = False
|
||||
):
|
||||
_ensure_idle_system()
|
||||
account = frappe.get_cached_doc("Account", name)
|
||||
if not account:
|
||||
@@ -577,7 +579,7 @@ def update_account_number(name, account_name, account_number=None, from_descenda
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def merge_account(old, new):
|
||||
def merge_account(old: str, new: str):
|
||||
_ensure_idle_system()
|
||||
# Validate properties before merging
|
||||
new_account = frappe.get_cached_doc("Account", new)
|
||||
@@ -614,7 +616,7 @@ def merge_account(old, new):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_root_company(company):
|
||||
def get_root_company(company: str):
|
||||
# return the topmost company in the hierarchy
|
||||
ancestors = get_ancestors_of("Company", company, "lft asc")
|
||||
return [ancestors[0]] if ancestors else []
|
||||
|
||||
@@ -99,7 +99,7 @@ def identify_is_group(child):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_chart(chart_template, existing_company=None):
|
||||
def get_chart(chart_template: str, existing_company: str | None = None):
|
||||
chart = {}
|
||||
if existing_company:
|
||||
return get_account_tree_from_existing_company(existing_company)
|
||||
@@ -132,7 +132,7 @@ def get_chart(chart_template, existing_company=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_charts_for_country(country, with_standard=False):
|
||||
def get_charts_for_country(country: str, with_standard: bool = False):
|
||||
charts = []
|
||||
|
||||
def _get_chart_name(content):
|
||||
@@ -225,7 +225,7 @@ def build_account_tree(tree, parent, all_accounts):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def validate_bank_account(coa, bank_account):
|
||||
def validate_bank_account(coa: str, bank_account: str):
|
||||
accounts = []
|
||||
chart = get_chart(coa)
|
||||
|
||||
@@ -244,7 +244,9 @@ def validate_bank_account(coa, bank_account):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def build_tree_from_json(chart_template, chart_data=None, from_coa_importer=False):
|
||||
def build_tree_from_json(
|
||||
chart_template: str, chart_data: dict | None = None, from_coa_importer: bool = False
|
||||
):
|
||||
"""get chart template from its folder and parse the json to be rendered as tree"""
|
||||
chart = chart_data or get_chart(chart_template)
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ def delete_accounting_dimension(doc):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def disable_dimension(doc):
|
||||
def disable_dimension(doc: str):
|
||||
if frappe.in_test:
|
||||
toggle_disabling(doc=doc)
|
||||
else:
|
||||
@@ -286,7 +286,7 @@ def get_dimension_with_children(doctype, dimensions):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_dimensions(with_cost_center_and_project=False):
|
||||
def get_dimensions(with_cost_center_and_project: str | bool = False):
|
||||
c = frappe.qb.DocType("Accounting Dimension Detail")
|
||||
p = frappe.qb.DocType("Accounting Dimension")
|
||||
dimension_filters = (
|
||||
|
||||
@@ -115,7 +115,7 @@ def get_default_company_bank_account(company, party_type, party):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_bank_account_details(bank_account):
|
||||
def get_bank_account_details(bank_account: str):
|
||||
return frappe.get_cached_value(
|
||||
"Bank Account", bank_account, ["account", "bank", "bank_account_no"], as_dict=1
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ class BankReconciliationTool(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_bank_transactions(bank_account, from_date=None, to_date=None):
|
||||
def get_bank_transactions(bank_account: str, from_date: str | None = None, to_date: str | None = None):
|
||||
# returns bank transactions for a bank account
|
||||
filters = []
|
||||
filters.append(["bank_account", "=", bank_account])
|
||||
@@ -80,7 +80,7 @@ def get_bank_transactions(bank_account, from_date=None, to_date=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_account_balance(bank_account, till_date, company):
|
||||
def get_account_balance(bank_account: str, till_date: str, company: str):
|
||||
# returns account balance till the specified date
|
||||
account = frappe.db.get_value("Bank Account", bank_account, "account")
|
||||
filters = frappe._dict(
|
||||
@@ -106,7 +106,9 @@ def get_account_balance(bank_account, till_date, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_bank_transaction(bank_transaction_name, reference_number, party_type=None, party=None):
|
||||
def update_bank_transaction(
|
||||
bank_transaction_name: str, reference_number: str, party_type: str | None = None, party: str | None = None
|
||||
):
|
||||
# updates bank transaction based on the new parameters provided by the user from Vouchers
|
||||
bank_transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||
bank_transaction.reference_number = reference_number
|
||||
@@ -135,16 +137,16 @@ def update_bank_transaction(bank_transaction_name, reference_number, party_type=
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_journal_entry_bts(
|
||||
bank_transaction_name,
|
||||
reference_number=None,
|
||||
reference_date=None,
|
||||
posting_date=None,
|
||||
entry_type=None,
|
||||
second_account=None,
|
||||
mode_of_payment=None,
|
||||
party_type=None,
|
||||
party=None,
|
||||
allow_edit=None,
|
||||
bank_transaction_name: str,
|
||||
reference_number: str | None = None,
|
||||
reference_date: str | None = None,
|
||||
posting_date: str | None = None,
|
||||
entry_type: str | None = None,
|
||||
second_account: str | None = None,
|
||||
mode_of_payment: str | None = None,
|
||||
party_type: str | None = None,
|
||||
party: str | None = None,
|
||||
allow_edit: bool | None = None,
|
||||
):
|
||||
# Create a new journal entry based on the bank transaction
|
||||
bank_transaction = frappe.db.get_values(
|
||||
@@ -294,17 +296,17 @@ def create_journal_entry_bts(
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_payment_entry_bts(
|
||||
bank_transaction_name,
|
||||
reference_number=None,
|
||||
reference_date=None,
|
||||
party_type=None,
|
||||
party=None,
|
||||
posting_date=None,
|
||||
mode_of_payment=None,
|
||||
project=None,
|
||||
cost_center=None,
|
||||
allow_edit=None,
|
||||
company_bank_account=None,
|
||||
bank_transaction_name: str,
|
||||
reference_number: str | None = None,
|
||||
reference_date: str | None = None,
|
||||
party_type: str | None = None,
|
||||
party: str | None = None,
|
||||
posting_date: str | None = None,
|
||||
mode_of_payment: str | None = None,
|
||||
project: str | None = None,
|
||||
cost_center: str | None = None,
|
||||
allow_edit: bool | None = None,
|
||||
company_bank_account: str | None = None,
|
||||
):
|
||||
# Create a new payment entry based on the bank transaction
|
||||
bank_transaction = frappe.db.get_values(
|
||||
@@ -371,12 +373,12 @@ def create_payment_entry_bts(
|
||||
|
||||
@frappe.whitelist()
|
||||
def auto_reconcile_vouchers(
|
||||
bank_account,
|
||||
from_date=None,
|
||||
to_date=None,
|
||||
filter_by_reference_date=None,
|
||||
from_reference_date=None,
|
||||
to_reference_date=None,
|
||||
bank_account: str,
|
||||
from_date: str | None = None,
|
||||
to_date: str | None = None,
|
||||
filter_by_reference_date: str | None = None,
|
||||
from_reference_date: str | None = None,
|
||||
to_reference_date: str | None = None,
|
||||
):
|
||||
bank_transactions = get_bank_transactions(bank_account)
|
||||
|
||||
@@ -471,7 +473,7 @@ def get_auto_reconcile_message(partially_reconciled, reconciled):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def reconcile_vouchers(bank_transaction_name, vouchers):
|
||||
def reconcile_vouchers(bank_transaction_name: str, vouchers: str):
|
||||
# updated clear date of all the vouchers based on the bank transaction
|
||||
vouchers = json.loads(vouchers)
|
||||
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||
@@ -487,13 +489,13 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_linked_payments(
|
||||
bank_transaction_name,
|
||||
document_types=None,
|
||||
from_date=None,
|
||||
to_date=None,
|
||||
filter_by_reference_date=None,
|
||||
from_reference_date=None,
|
||||
to_reference_date=None,
|
||||
bank_transaction_name: str,
|
||||
document_types: list[str] | None = None,
|
||||
from_date: str | None = None,
|
||||
to_date: str | None = None,
|
||||
filter_by_reference_date: str | None = None,
|
||||
from_reference_date: str | None = None,
|
||||
to_reference_date: str | None = None,
|
||||
):
|
||||
# get all matching payments for a bank transaction
|
||||
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||
|
||||
@@ -143,7 +143,7 @@ def preprocess_mt940_content(content: str) -> str:
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def convert_mt940_to_csv(data_import, mt940_file_path):
|
||||
def convert_mt940_to_csv(data_import: str, mt940_file_path: str):
|
||||
doc = frappe.get_doc("Bank Statement Import", data_import)
|
||||
|
||||
_file_doc, content = get_file(mt940_file_path)
|
||||
@@ -208,26 +208,28 @@ def convert_mt940_to_csv(data_import, mt940_file_path):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_preview_from_template(data_import, import_file=None, google_sheets_url=None):
|
||||
def get_preview_from_template(
|
||||
data_import: str, import_file: str | None = None, google_sheets_url: str | None = None
|
||||
):
|
||||
return frappe.get_doc("Bank Statement Import", data_import).get_preview_from_template(
|
||||
import_file, google_sheets_url
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def form_start_import(data_import):
|
||||
def form_start_import(data_import: str):
|
||||
job_id = frappe.get_doc("Bank Statement Import", data_import).start_import()
|
||||
return job_id is not None
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_errored_template(data_import_name):
|
||||
def download_errored_template(data_import_name: str):
|
||||
data_import = frappe.get_doc("Bank Statement Import", data_import_name)
|
||||
data_import.export_errored_rows()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_import_log(data_import_name):
|
||||
def download_import_log(data_import_name: str):
|
||||
return frappe.get_doc("Bank Statement Import", data_import_name).download_import_log()
|
||||
|
||||
|
||||
@@ -363,7 +365,7 @@ def write_xlsx(data, sheet_name, wb=None, column_widths=None, file_path=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_import_status(docname):
|
||||
def get_import_status(docname: str):
|
||||
import_status = {}
|
||||
|
||||
data_import = frappe.get_doc("Bank Statement Import", docname)
|
||||
|
||||
@@ -35,7 +35,7 @@ def upload_bank_statement():
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_bank_entries(columns, data, bank_account):
|
||||
def create_bank_entries(columns: str, data: str, bank_account: str):
|
||||
header_map = get_header_mapping(columns, bank_account)
|
||||
|
||||
success = 0
|
||||
|
||||
@@ -845,7 +845,7 @@ def get_fiscal_year_date_range(from_fiscal_year, to_fiscal_year):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def revise_budget(budget_name):
|
||||
def revise_budget(budget_name: str):
|
||||
old_budget = frappe.get_doc("Budget", budget_name)
|
||||
|
||||
if old_budget.docstatus == 1:
|
||||
|
||||
@@ -57,7 +57,7 @@ def validate_columns(data):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def validate_company(company):
|
||||
def validate_company(company: str):
|
||||
parent_company, allow_account_creation_against_child_company = frappe.get_cached_value(
|
||||
"Company", company, ["parent_company", "allow_account_creation_against_child_company"]
|
||||
)
|
||||
@@ -74,7 +74,7 @@ def validate_company(company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def import_coa(file_name, company):
|
||||
def import_coa(file_name: str, company: str):
|
||||
# delete existing data for accounts
|
||||
unset_existing_data(company)
|
||||
|
||||
@@ -159,7 +159,9 @@ def generate_data_from_excel(file_doc, extension, as_dict=False):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_coa(doctype, parent, is_root=False, file_name=None, for_validate=0):
|
||||
def get_coa(
|
||||
doctype: str, parent: str, is_root: bool = False, file_name: str | None = None, for_validate: int = 0
|
||||
):
|
||||
"""called by tree view (to fetch node's children)"""
|
||||
|
||||
file_doc, extension = get_file(file_name)
|
||||
@@ -307,7 +309,7 @@ def build_response_as_excel(writer):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_template(file_type, template_type, company):
|
||||
def download_template(file_type: str, template_type: str, company: str):
|
||||
writer = get_template(template_type, company)
|
||||
|
||||
if file_type == "CSV":
|
||||
@@ -361,7 +363,7 @@ def get_sample_template(writer, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def validate_accounts(file_doc, extension):
|
||||
def validate_accounts(file_doc: Document, extension: str):
|
||||
if extension == "csv":
|
||||
accounts = generate_data_from_csv(file_doc, as_dict=True)
|
||||
else:
|
||||
|
||||
@@ -47,7 +47,7 @@ class ChequePrintTemplate(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_or_update_cheque_print_format(template_name):
|
||||
def create_or_update_cheque_print_format(template_name: str):
|
||||
if not frappe.db.exists("Print Format", template_name):
|
||||
cheque_print = frappe.new_doc("Print Format")
|
||||
cheque_print.update(
|
||||
|
||||
@@ -614,7 +614,12 @@ def calculate_exchange_rate_using_last_gle(company, account, party_type, party):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_account_details(
|
||||
company, posting_date, account, party_type=None, party=None, rounding_loss_allowance: float | None = None
|
||||
company: str,
|
||||
posting_date: str,
|
||||
account: str,
|
||||
party_type: str | None = None,
|
||||
party: str | None = None,
|
||||
rounding_loss_allowance: float = 0.0,
|
||||
):
|
||||
if not (company and posting_date):
|
||||
frappe.throw(_("Company and Posting Date is mandatory"))
|
||||
|
||||
@@ -317,7 +317,7 @@ class InvoiceDiscounting(AccountsController):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_invoices(filters):
|
||||
def get_invoices(filters: str):
|
||||
filters = frappe._dict(json.loads(filters))
|
||||
cond = []
|
||||
if filters.customer:
|
||||
|
||||
@@ -7,6 +7,7 @@ import json
|
||||
import frappe
|
||||
from frappe import _, msgprint, scrub
|
||||
from frappe.core.doctype.submission_queue.submission_queue import queue_submission
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import comma_and, cstr, flt, fmt_money, formatdate, get_link_to_form, nowdate
|
||||
|
||||
import erpnext
|
||||
@@ -1215,7 +1216,7 @@ class JournalEntry(AccountsController):
|
||||
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_balance(self, difference_account=None):
|
||||
def get_balance(self, difference_account: str | None = None):
|
||||
if not self.get("accounts"):
|
||||
msgprint(_("'Entries' cannot be empty"), raise_exception=True)
|
||||
else:
|
||||
@@ -1321,7 +1322,12 @@ class JournalEntry(AccountsController):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_default_bank_cash_account(
|
||||
company, account_type=None, mode_of_payment=None, account=None, *, fetch_balance=True
|
||||
company: str,
|
||||
account_type: str | None = None,
|
||||
mode_of_payment: str | None = None,
|
||||
account: str | None = None,
|
||||
*,
|
||||
fetch_balance: bool = True,
|
||||
):
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
|
||||
|
||||
@@ -1370,7 +1376,12 @@ def get_default_bank_cash_account(
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_entry_against_order(
|
||||
dt, dn, amount=None, debit_in_account_currency=None, journal_entry=False, bank_account=None
|
||||
dt: str,
|
||||
dn: str,
|
||||
amount: float | None = None,
|
||||
debit_in_account_currency: str | None = None,
|
||||
journal_entry: bool = False,
|
||||
bank_account: str | None = None,
|
||||
):
|
||||
ref_doc = frappe.get_doc(dt, dn)
|
||||
|
||||
@@ -1415,7 +1426,12 @@ def get_payment_entry_against_order(
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_entry_against_invoice(
|
||||
dt, dn, amount=None, debit_in_account_currency=None, journal_entry=False, bank_account=None
|
||||
dt: str,
|
||||
dn: str,
|
||||
amount: float | None = None,
|
||||
debit_in_account_currency: str | None = None,
|
||||
journal_entry: bool = False,
|
||||
bank_account: str | None = None,
|
||||
):
|
||||
ref_doc = frappe.get_doc(dt, dn)
|
||||
if dt == "Sales Invoice":
|
||||
@@ -1528,7 +1544,7 @@ def get_payment_entry(ref_doc, args):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_against_jv(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_against_jv(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
if not frappe.db.has_column("Journal Entry", searchfield):
|
||||
return []
|
||||
|
||||
@@ -1559,7 +1575,7 @@ def get_against_jv(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_outstanding(args):
|
||||
def get_outstanding(args: str | dict):
|
||||
if not frappe.has_permission("Account"):
|
||||
frappe.msgprint(_("No Permission"), raise_exception=1)
|
||||
|
||||
@@ -1619,7 +1635,7 @@ def get_outstanding(args):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_account_and_currency(company, party_type, party):
|
||||
def get_party_account_and_currency(company: str, party_type: str, party: str):
|
||||
if not frappe.has_permission("Account"):
|
||||
frappe.msgprint(_("No Permission"), raise_exception=1)
|
||||
|
||||
@@ -1632,7 +1648,14 @@ def get_party_account_and_currency(company, party_type, party):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_account_details_and_party_type(account, date, company, debit=None, credit=None, exchange_rate=None):
|
||||
def get_account_details_and_party_type(
|
||||
account: str,
|
||||
date: str,
|
||||
company: str,
|
||||
debit: str | None = None,
|
||||
credit: str | None = None,
|
||||
exchange_rate: str | None = None,
|
||||
):
|
||||
"""Returns dict of account details and party type to be set in Journal Entry on selection of account."""
|
||||
if not frappe.has_permission("Account"):
|
||||
frappe.msgprint(_("No Permission"), raise_exception=1)
|
||||
@@ -1681,15 +1704,15 @@ def get_account_details_and_party_type(account, date, company, debit=None, credi
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_exchange_rate(
|
||||
posting_date,
|
||||
account=None,
|
||||
account_currency=None,
|
||||
company=None,
|
||||
reference_type=None,
|
||||
reference_name=None,
|
||||
debit=None,
|
||||
credit=None,
|
||||
exchange_rate=None,
|
||||
posting_date: str,
|
||||
account: str | None = None,
|
||||
account_currency: str | None = None,
|
||||
company: str | None = None,
|
||||
reference_type: str | None = None,
|
||||
reference_name: str | None = None,
|
||||
debit: float | str | None = None,
|
||||
credit: float | str | None = None,
|
||||
exchange_rate: str | None = None,
|
||||
):
|
||||
# Ensure exchange_rate is always numeric to avoid calculation errors
|
||||
if isinstance(exchange_rate, str):
|
||||
@@ -1726,7 +1749,7 @@ def get_exchange_rate(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_average_exchange_rate(account):
|
||||
def get_average_exchange_rate(account: str):
|
||||
exchange_rate = 0
|
||||
bank_balance_in_account_currency = get_balance_on(account)
|
||||
if bank_balance_in_account_currency:
|
||||
@@ -1737,7 +1760,7 @@ def get_average_exchange_rate(account):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_inter_company_journal_entry(name, voucher_type, company):
|
||||
def make_inter_company_journal_entry(name: str, voucher_type: str, company: str):
|
||||
journal_entry = frappe.new_doc("Journal Entry")
|
||||
journal_entry.voucher_type = voucher_type
|
||||
journal_entry.company = company
|
||||
@@ -1747,7 +1770,7 @@ def make_inter_company_journal_entry(name, voucher_type, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_reverse_journal_entry(source_name, target_doc=None):
|
||||
def make_reverse_journal_entry(source_name: str, target_doc: str | Document | None = None):
|
||||
existing_reverse = frappe.db.exists("Journal Entry", {"reversal_of": source_name, "docstatus": 1})
|
||||
if existing_reverse:
|
||||
frappe.throw(
|
||||
|
||||
@@ -55,7 +55,7 @@ class LedgerMerge(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def form_start_merge(docname):
|
||||
def form_start_merge(docname: str):
|
||||
return frappe.get_doc("Ledger Merge", docname).start_merge()
|
||||
|
||||
|
||||
|
||||
@@ -88,13 +88,13 @@ def get_loyalty_details(
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_loyalty_program_details_with_points(
|
||||
customer,
|
||||
loyalty_program=None,
|
||||
expiry_date=None,
|
||||
company=None,
|
||||
silent=False,
|
||||
include_expired_entry=False,
|
||||
current_transaction_amount=0,
|
||||
customer: str,
|
||||
loyalty_program: str | None = None,
|
||||
expiry_date: str | None = None,
|
||||
company: str | None = None,
|
||||
silent: bool = False,
|
||||
include_expired_entry: bool = False,
|
||||
current_transaction_amount: int | float = 0,
|
||||
):
|
||||
lp_details = get_loyalty_program_details(customer, loyalty_program, company=company, silent=silent)
|
||||
loyalty_program = frappe.get_doc("Loyalty Program", loyalty_program)
|
||||
@@ -119,12 +119,12 @@ def get_loyalty_program_details_with_points(
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_loyalty_program_details(
|
||||
customer,
|
||||
loyalty_program=None,
|
||||
expiry_date=None,
|
||||
company=None,
|
||||
silent=False,
|
||||
include_expired_entry=False,
|
||||
customer: str,
|
||||
loyalty_program: str | None = None,
|
||||
expiry_date: str | None = None,
|
||||
company: str | None = None,
|
||||
silent: bool = False,
|
||||
include_expired_entry: bool = False,
|
||||
):
|
||||
lp_details = frappe._dict()
|
||||
|
||||
@@ -146,7 +146,7 @@ def get_loyalty_program_details(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_redeemption_factor(loyalty_program=None, customer=None):
|
||||
def get_redeemption_factor(loyalty_program: str | None = None, customer: str | None = None):
|
||||
customer_loyalty_program = None
|
||||
if not loyalty_program:
|
||||
customer_loyalty_program = frappe.db.get_value("Customer", customer, "loyalty_program")
|
||||
|
||||
@@ -293,7 +293,7 @@ def publish(index, total, doctype):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_temporary_opening_account(company=None):
|
||||
def get_temporary_opening_account(company: str | None = None):
|
||||
if not company:
|
||||
return
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class PartyLink(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_party_link(primary_role, primary_party, secondary_party):
|
||||
def create_party_link(primary_role: str, primary_party: str, secondary_party: str):
|
||||
party_link = frappe.new_doc("Party Link")
|
||||
party_link.primary_role = primary_role
|
||||
party_link.primary_party = primary_party
|
||||
|
||||
@@ -1867,7 +1867,9 @@ class PaymentEntry(AccountsController):
|
||||
frappe.response["matched_payment_requests"] = matched_payment_requests
|
||||
|
||||
@frappe.whitelist()
|
||||
def allocate_amount_to_references(self, paid_amount, paid_amount_change, allocate_payment_amount):
|
||||
def allocate_amount_to_references(
|
||||
self, paid_amount: float, paid_amount_change: bool, allocate_payment_amount: bool
|
||||
):
|
||||
"""
|
||||
Allocate `Allocated Amount` and `Payment Request` against `Reference` based on `Paid Amount` and `Outstanding Amount`.\n
|
||||
:param paid_amount: Paid Amount / Received Amount.
|
||||
@@ -2039,7 +2041,7 @@ class PaymentEntry(AccountsController):
|
||||
)
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_matched_payment_requests(self, matched_payment_requests):
|
||||
def set_matched_payment_requests(self, matched_payment_requests: str | list | None):
|
||||
"""
|
||||
Set `Payment Request` against `Reference` based on `matched_payment_requests`.\n
|
||||
:param matched_payment_requests: List of tuple of matched Payment Requests.
|
||||
@@ -2255,7 +2257,7 @@ def validate_inclusive_tax(tax, doc):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_outstanding_reference_documents(args, validate=False):
|
||||
def get_outstanding_reference_documents(args: str | dict, validate: bool = False):
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
@@ -2670,7 +2672,7 @@ def get_negative_outstanding_invoices(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_details(company, party_type, party, date, cost_center=None):
|
||||
def get_party_details(company: str, party_type: str, party: str, date: str, cost_center: str | None = None):
|
||||
bank_account = ""
|
||||
party_bank_account = ""
|
||||
|
||||
@@ -2696,7 +2698,7 @@ def get_party_details(company, party_type, party, date, cost_center=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_account_details(account, date, cost_center=None):
|
||||
def get_account_details(account: str, date: str, cost_center: str | None = None):
|
||||
frappe.has_permission("Payment Entry", throw=True)
|
||||
|
||||
# to check if the passed account is accessible under reference doctype Payment Entry
|
||||
@@ -2716,7 +2718,7 @@ def get_account_details(account, date, cost_center=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_company_defaults(company):
|
||||
def get_company_defaults(company: str):
|
||||
fields = ["write_off_account", "exchange_gain_loss_account", "cost_center"]
|
||||
return frappe.get_cached_value("Company", company, fields, as_dict=1)
|
||||
|
||||
@@ -2755,7 +2757,11 @@ def get_outstanding_on_journal_entry(voucher_no, party_type, party):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_reference_details(
|
||||
reference_doctype, reference_name, party_account_currency, party_type=None, party=None
|
||||
reference_doctype: str,
|
||||
reference_name: str,
|
||||
party_account_currency: str,
|
||||
party_type: str | None = None,
|
||||
party: str | None = None,
|
||||
):
|
||||
total_amount = outstanding_amount = exchange_rate = account = None
|
||||
|
||||
@@ -2846,15 +2852,15 @@ def get_reference_details(
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_entry(
|
||||
dt,
|
||||
dn,
|
||||
party_amount=None,
|
||||
bank_account=None,
|
||||
bank_amount=None,
|
||||
party_type=None,
|
||||
payment_type=None,
|
||||
reference_date=None,
|
||||
created_from_payment_request=False,
|
||||
dt: str,
|
||||
dn: str,
|
||||
party_amount: str | None = None,
|
||||
bank_account: str | None = None,
|
||||
bank_amount: float | None = None,
|
||||
party_type: str | None = None,
|
||||
payment_type: str | None = None,
|
||||
reference_date: str | None = None,
|
||||
created_from_payment_request: str | None = None,
|
||||
):
|
||||
doc = frappe.get_doc(dt, dn)
|
||||
over_billing_allowance = frappe.get_single_value("Accounts Settings", "over_billing_allowance")
|
||||
@@ -3520,7 +3526,7 @@ def get_paid_amount(dt, dn, party_type, party, account, due_date):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_payment_order(source_name, target_doc=None):
|
||||
def make_payment_order(source_name: str, target_doc: str | None = None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
|
||||
@@ -59,7 +59,7 @@ class PaymentOrder(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_mop_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_mop_query(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
return frappe.db.sql(
|
||||
""" select mode_of_payment from `tabPayment Order Reference`
|
||||
where parent = %(parent)s and mode_of_payment like %(txt)s
|
||||
@@ -70,7 +70,7 @@ def get_mop_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_supplier_query(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
return frappe.db.sql(
|
||||
""" select supplier from `tabPayment Order Reference`
|
||||
where parent = %(parent)s and supplier like %(txt)s and
|
||||
@@ -81,7 +81,7 @@ def get_supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_payment_records(name, supplier, mode_of_payment=None):
|
||||
def make_payment_records(name: str, supplier: str, mode_of_payment: str | None = None):
|
||||
doc = frappe.get_doc("Payment Order", name)
|
||||
make_journal_entry(doc, supplier, mode_of_payment)
|
||||
|
||||
|
||||
@@ -433,7 +433,9 @@ class PaymentReconciliation(Document):
|
||||
return frappe.get_single_value("Accounts Settings", "auto_reconcile_payments")
|
||||
|
||||
@frappe.whitelist()
|
||||
def calculate_difference_on_allocation_change(self, payment_entry, invoice, allocated_amount):
|
||||
def calculate_difference_on_allocation_change(
|
||||
self, payment_entry: list, invoice: list, allocated_amount: float
|
||||
):
|
||||
invoice_exchange_map = self.get_invoice_exchange_map(invoice, payment_entry)
|
||||
invoice[0]["exchange_rate"] = invoice_exchange_map.get(invoice[0].get("invoice_number"))
|
||||
if payment_entry[0].get("reference_type") in ["Sales Invoice", "Purchase Invoice"]:
|
||||
@@ -445,7 +447,7 @@ class PaymentReconciliation(Document):
|
||||
return new_difference_amount
|
||||
|
||||
@frappe.whitelist()
|
||||
def allocate_entries(self, args):
|
||||
def allocate_entries(self, args: dict):
|
||||
self.validate_entries()
|
||||
|
||||
exc_gain_loss_posting_date = frappe.db.get_single_value(
|
||||
|
||||
@@ -812,7 +812,7 @@ def get_payment_gateway_account(filter):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_print_format_list(ref_doctype):
|
||||
def get_print_format_list(ref_doctype: str):
|
||||
print_format_list = ["Standard"]
|
||||
|
||||
print_format_list.extend(
|
||||
@@ -823,12 +823,12 @@ def get_print_format_list(ref_doctype):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def resend_payment_email(docname):
|
||||
def resend_payment_email(docname: str):
|
||||
return frappe.get_doc("Payment Request", docname).send_email()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_payment_entry(docname):
|
||||
def make_payment_entry(docname: str):
|
||||
doc = frappe.get_doc("Payment Request", docname)
|
||||
return doc.create_payment_entry(submit=False).as_dict()
|
||||
|
||||
@@ -921,7 +921,7 @@ def get_dummy_message(doc):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_subscription_details(reference_doctype, reference_name):
|
||||
def get_subscription_details(reference_doctype: str, reference_name: str):
|
||||
if reference_doctype == "Sales Invoice":
|
||||
subscriptions = frappe.db.sql(
|
||||
"""SELECT parent as sub_name FROM `tabSubscription Invoice` WHERE invoice=%s""",
|
||||
@@ -937,7 +937,7 @@ def get_subscription_details(reference_doctype, reference_name):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_payment_order(source_name, target_doc=None):
|
||||
def make_payment_order(source_name: str, target_doc: str | Document | None = None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
@@ -985,7 +985,9 @@ def validate_payment(doc, method=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_open_payment_requests_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_open_payment_requests_query(
|
||||
doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict
|
||||
):
|
||||
# permission checks in `get_list()`
|
||||
filters = frappe._dict(filters)
|
||||
|
||||
|
||||
@@ -515,7 +515,7 @@ def delete_closing_entries(voucher_no):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_period_start_end_date(fiscal_year, company):
|
||||
def get_period_start_end_date(fiscal_year: str, company: str):
|
||||
fy_start_date, fy_end_date = frappe.db.get_value(
|
||||
"Fiscal Year", fiscal_year, ["year_start_date", "year_end_date"]
|
||||
)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.query_builder import DocType
|
||||
@@ -252,13 +254,13 @@ class POSClosingEntry(StatusUpdater):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_cashiers(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_cashiers(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
cashiers_list = frappe.get_all("POS Profile User", filters=filters, fields=["user"], as_list=1)
|
||||
return [c for c in cashiers_list]
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_invoices(start, end, pos_profile, user):
|
||||
def get_invoices(start: str | datetime, end: str | datetime, pos_profile: str, user: str):
|
||||
invoice_doctype = frappe.db.get_single_value("POS Settings", "invoice_type")
|
||||
|
||||
sales_inv_query = build_invoice_query("Sales Invoice", user, pos_profile, start, end)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _, bold
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import map_child_doc, map_doc
|
||||
from frappe.query_builder.functions import IfNull, Sum
|
||||
from frappe.utils import cint, flt, get_link_to_form, getdate, nowdate
|
||||
@@ -753,7 +754,7 @@ class POSInvoice(SalesInvoice):
|
||||
return profile
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_missing_values(self, for_validate=False):
|
||||
def set_missing_values(self, for_validate: bool = False):
|
||||
profile = self.set_pos_fields(for_validate)
|
||||
|
||||
if not self.debit_to:
|
||||
@@ -854,7 +855,7 @@ class POSInvoice(SalesInvoice):
|
||||
return frappe.get_doc("Payment Request", pr)
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_payments(self, payments):
|
||||
def update_payments(self, payments: list):
|
||||
if self.status == "Consolidated":
|
||||
frappe.throw(_("Create Payment Entry for Consolidated POS Invoices."))
|
||||
|
||||
@@ -897,7 +898,7 @@ class POSInvoice(SalesInvoice):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_stock_availability(item_code, warehouse):
|
||||
def get_stock_availability(item_code: str, warehouse: str):
|
||||
if frappe.db.get_value("Item", item_code, "is_stock_item"):
|
||||
is_stock_item = True
|
||||
bin_qty = get_bin_qty(item_code, warehouse)
|
||||
@@ -1020,14 +1021,14 @@ def get_pos_reserved_qty_from_table(child_table, item_code, warehouse):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_sales_return(source_name, target_doc=None):
|
||||
def make_sales_return(source_name: str, target_doc: Document | None = None):
|
||||
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
||||
|
||||
return make_return_doc("POS Invoice", source_name, target_doc)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_merge_log(invoices):
|
||||
def make_merge_log(invoices: str | list):
|
||||
import json
|
||||
|
||||
if isinstance(invoices, str):
|
||||
@@ -1077,7 +1078,15 @@ def add_return_modes(doc, pos_profile):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
||||
def item_query(
|
||||
doctype: str,
|
||||
txt: str,
|
||||
searchfield: str,
|
||||
start: int,
|
||||
page_len: int,
|
||||
filters: str | dict,
|
||||
as_dict: bool = False,
|
||||
):
|
||||
if pos_profile := filters.get("pos_profile")[1]:
|
||||
pos_profile = frappe.get_cached_doc("POS Profile", pos_profile)
|
||||
if item_groups := get_item_group(pos_profile):
|
||||
|
||||
@@ -275,7 +275,7 @@ def get_child_nodes(group_type, root):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def pos_profile_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
def pos_profile_query(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
user = frappe.session["user"]
|
||||
company = filters.get("company") or frappe.defaults.get_user_default("company")
|
||||
|
||||
@@ -319,7 +319,7 @@ def pos_profile_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_default_profile(pos_profile, company):
|
||||
def set_default_profile(pos_profile: str, company: str):
|
||||
modified = now()
|
||||
user = frappe.session.user
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ class PricingRule(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def apply_pricing_rule(args, doc=None):
|
||||
def apply_pricing_rule(args: str | dict, doc: str | None = None):
|
||||
"""
|
||||
args = {
|
||||
"items": [{"doctype": "", "name": "", "item_code": "", "brand": "", "item_group": ""}, ...],
|
||||
@@ -618,7 +618,12 @@ def apply_price_discount_rule(pricing_rule, item_details, args):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, rate=None):
|
||||
def remove_pricing_rule_for_item(
|
||||
pricing_rules: str | None,
|
||||
item_details: str | frappe._dict,
|
||||
item_code: str | None = None,
|
||||
rate: float | None = None,
|
||||
):
|
||||
from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||
get_applied_pricing_rules,
|
||||
get_pricing_rule_items,
|
||||
@@ -666,7 +671,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, ra
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def remove_pricing_rules(item_list):
|
||||
def remove_pricing_rules(item_list: str | list):
|
||||
if isinstance(item_list, str):
|
||||
item_list = json.loads(item_list)
|
||||
|
||||
@@ -704,7 +709,7 @@ def set_transaction_type(args):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_item_uoms(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_item_uoms(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||
items = [filters.get("value")]
|
||||
if filters.get("apply_on") != "Item Code":
|
||||
field = frappe.scrub(filters.get("apply_on"))
|
||||
|
||||
@@ -420,7 +420,7 @@ def get_context(customer, doc):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def fetch_customers(customer_collection, collection_name, primary_mandatory):
|
||||
def fetch_customers(customer_collection: str, collection_name: str, primary_mandatory: str | int):
|
||||
customer_list = []
|
||||
customers = []
|
||||
|
||||
@@ -460,7 +460,7 @@ def fetch_customers(customer_collection, collection_name, primary_mandatory):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_customer_emails(customer_name, primary_mandatory, billing_and_primary=True):
|
||||
def get_customer_emails(customer_name: str, primary_mandatory: str | int, billing_and_primary: bool = True):
|
||||
"""Returns first email from Contact Email table as a Billing email
|
||||
when Is Billing Contact checked
|
||||
and Primary email- email with Is Primary checked"""
|
||||
@@ -506,7 +506,7 @@ def get_customer_emails(customer_name, primary_mandatory, billing_and_primary=Tr
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_statements(document_name):
|
||||
def download_statements(document_name: str):
|
||||
doc = frappe.get_doc("Process Statement Of Accounts", document_name)
|
||||
report = get_report_pdf(doc)
|
||||
if report:
|
||||
@@ -516,7 +516,7 @@ def download_statements(document_name):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def send_emails(document_name, from_scheduler=False, posting_date=None):
|
||||
def send_emails(document_name: str, from_scheduler: bool = False, posting_date: str | None = None):
|
||||
doc = frappe.get_doc("Process Statement Of Accounts", document_name)
|
||||
report = get_report_pdf(doc, consolidated=False)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import json
|
||||
|
||||
import frappe
|
||||
from frappe import _, qb, throw
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.query_builder.functions import Sum
|
||||
from frappe.utils import cint, cstr, flt, formatdate, get_link_to_form, getdate, nowdate
|
||||
@@ -1941,14 +1942,14 @@ def make_regional_gl_entries(gl_entries, doc):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_debit_note(source_name, target_doc=None):
|
||||
def make_debit_note(source_name: str, target_doc: Document | None = None):
|
||||
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
||||
|
||||
return make_return_doc("Purchase Invoice", source_name, target_doc)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_stock_entry(source_name, target_doc=None):
|
||||
def make_stock_entry(source_name: str, target_doc: str | Document | None = None):
|
||||
doc = get_mapped_doc(
|
||||
"Purchase Invoice",
|
||||
source_name,
|
||||
@@ -1966,35 +1967,37 @@ def make_stock_entry(source_name, target_doc=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def change_release_date(name, release_date=None):
|
||||
def change_release_date(name: str, release_date: str | None = None):
|
||||
if frappe.db.exists("Purchase Invoice", name):
|
||||
pi = frappe.get_lazy_doc("Purchase Invoice", name)
|
||||
pi.db_set("release_date", release_date)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def unblock_invoice(name):
|
||||
def unblock_invoice(name: str):
|
||||
if frappe.db.exists("Purchase Invoice", name):
|
||||
pi = frappe.get_lazy_doc("Purchase Invoice", name)
|
||||
pi.unblock_invoice()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def block_invoice(name, release_date, hold_comment=None):
|
||||
def block_invoice(name: str, release_date: str, hold_comment: str | None = None):
|
||||
if frappe.db.exists("Purchase Invoice", name):
|
||||
pi = frappe.get_lazy_doc("Purchase Invoice", name)
|
||||
pi.block_invoice(hold_comment, release_date)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_inter_company_sales_invoice(source_name, target_doc=None):
|
||||
def make_inter_company_sales_invoice(source_name: str, target_doc: Document | None = None):
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_company_transaction
|
||||
|
||||
return make_inter_company_transaction("Purchase Invoice", source_name, target_doc)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_receipt(source_name, target_doc=None, args=None):
|
||||
def make_purchase_receipt(
|
||||
source_name: str, target_doc: str | Document | None = None, args: str | dict | None = None
|
||||
):
|
||||
if args is None:
|
||||
args = {}
|
||||
if isinstance(args, str):
|
||||
|
||||
@@ -152,7 +152,7 @@ class RepostAccountingLedger(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def start_repost(account_repost_doc=str) -> None:
|
||||
def start_repost(account_repost_doc: str | None = None) -> None:
|
||||
from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
||||
|
||||
frappe.flags.through_repost_accounting_ledger = True
|
||||
@@ -286,7 +286,9 @@ def validate_docs_for_voucher_types(doc_voucher_types):
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_repost_allowed_types(doctype, txt, searchfield, start, page_len, filters):
|
||||
def get_repost_allowed_types(
|
||||
doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict
|
||||
):
|
||||
filters = {"allowed": True}
|
||||
|
||||
if txt:
|
||||
|
||||
@@ -21,7 +21,7 @@ def repost_ple_for_voucher(voucher_type, voucher_no, gle_map=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def start_payment_ledger_repost(docname=None):
|
||||
def start_payment_ledger_repost(docname: str | None = None):
|
||||
"""
|
||||
Repost Payment Ledger Entries for Vouchers through Background Job
|
||||
"""
|
||||
@@ -119,7 +119,7 @@ class RepostPaymentLedger(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def execute_repost_payment_ledger(docname):
|
||||
def execute_repost_payment_ledger(docname: str):
|
||||
"""Repost Payment Ledger Entries by background job."""
|
||||
|
||||
job_name = "payment_ledger_repost_" + docname
|
||||
|
||||
@@ -6,6 +6,7 @@ import frappe
|
||||
import frappe.utils
|
||||
from frappe import _, msgprint, throw
|
||||
from frappe.contacts.doctype.address.address import get_address_display
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.model.utils import get_fetch_values
|
||||
from frappe.query_builder import Case
|
||||
@@ -741,7 +742,7 @@ class SalesInvoice(SellingController):
|
||||
pos_invoice_doc.cancel()
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_missing_values(self, for_validate=False):
|
||||
def set_missing_values(self, for_validate: bool = False):
|
||||
pos = self.set_pos_fields(for_validate)
|
||||
|
||||
if not self.debit_to:
|
||||
@@ -2409,7 +2410,7 @@ def get_list_context(context=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_bank_cash_account(mode_of_payment, company):
|
||||
def get_bank_cash_account(mode_of_payment: str, company: str):
|
||||
account = frappe.db.get_value(
|
||||
"Mode of Payment Account", {"parent": mode_of_payment, "company": company}, "default_account"
|
||||
)
|
||||
@@ -2424,7 +2425,7 @@ def get_bank_cash_account(mode_of_payment, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_maintenance_schedule(source_name, target_doc=None):
|
||||
def make_maintenance_schedule(source_name: str, target_doc: str | Document | None = None):
|
||||
doclist = get_mapped_doc(
|
||||
"Sales Invoice",
|
||||
source_name,
|
||||
@@ -2441,7 +2442,7 @@ def make_maintenance_schedule(source_name, target_doc=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_delivery_note(source_name, target_doc=None):
|
||||
def make_delivery_note(source_name: str, target_doc: Document | None = None):
|
||||
def set_missing_values(source, target):
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("set_po_nos")
|
||||
@@ -2490,7 +2491,7 @@ def make_delivery_note(source_name, target_doc=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_sales_return(source_name, target_doc=None):
|
||||
def make_sales_return(source_name: str, target_doc: Document | None = None):
|
||||
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
||||
|
||||
return make_return_doc("Sales Invoice", source_name, target_doc)
|
||||
@@ -2584,7 +2585,7 @@ def validate_inter_company_transaction(doc, doctype):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_inter_company_purchase_invoice(source_name, target_doc=None):
|
||||
def make_inter_company_purchase_invoice(source_name: str, target_doc: Document | None = None):
|
||||
return make_inter_company_transaction("Sales Invoice", source_name, target_doc)
|
||||
|
||||
|
||||
@@ -2962,7 +2963,7 @@ def update_address(doc, address_field, address_display_field, address_name):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_loyalty_programs(customer):
|
||||
def get_loyalty_programs(customer: str):
|
||||
"""sets applicable loyalty program to the customer or returns a list of applicable programs"""
|
||||
from erpnext.selling.doctype.customer.customer import get_loyalty_programs
|
||||
|
||||
@@ -2980,7 +2981,7 @@ def get_loyalty_programs(customer):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_invoice_discounting(source_name, target_doc=None):
|
||||
def create_invoice_discounting(source_name: str, target_doc: str | Document | None = None):
|
||||
invoice = frappe.get_doc("Sales Invoice", source_name)
|
||||
invoice_discounting = frappe.new_doc("Invoice Discounting")
|
||||
invoice_discounting.company = invoice.company
|
||||
@@ -3072,7 +3073,9 @@ def get_mode_of_payment_info(mode_of_payment, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_dunning(source_name, target_doc=None, ignore_permissions=False):
|
||||
def create_dunning(
|
||||
source_name: str, target_doc: str | Document | None = None, ignore_permissions: bool = False
|
||||
):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def postprocess_dunning(source, target):
|
||||
|
||||
@@ -342,14 +342,14 @@ class ShareTransfer(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_jv_entry(
|
||||
company,
|
||||
account,
|
||||
amount,
|
||||
payment_account,
|
||||
credit_applicant_type,
|
||||
credit_applicant,
|
||||
debit_applicant_type,
|
||||
debit_applicant,
|
||||
company: str,
|
||||
account: str,
|
||||
amount: float,
|
||||
payment_account: str,
|
||||
credit_applicant_type: str,
|
||||
credit_applicant: str,
|
||||
debit_applicant_type: str,
|
||||
debit_applicant: str,
|
||||
):
|
||||
journal_entry = frappe.new_doc("Journal Entry")
|
||||
journal_entry.voucher_type = "Journal Entry"
|
||||
|
||||
@@ -43,7 +43,13 @@ class SubscriptionPlan(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_plan_rate(
|
||||
plan, quantity=1, customer=None, start_date=None, end_date=None, prorate_factor=1, party=None
|
||||
plan: str,
|
||||
quantity: int = 1,
|
||||
customer: str | None = None,
|
||||
start_date: str | None = None,
|
||||
end_date: str | None = None,
|
||||
prorate_factor: float = 1,
|
||||
party: str | None = None,
|
||||
):
|
||||
plan = frappe.get_doc("Subscription Plan", plan)
|
||||
if plan.price_determination == "Fixed Rate":
|
||||
|
||||
@@ -135,7 +135,7 @@ class TaxRule(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_details(party, party_type, args=None):
|
||||
def get_party_details(party: str, party_type: str, args: dict | None = None):
|
||||
out = {}
|
||||
billing_address, shipping_address = None, None
|
||||
if args:
|
||||
|
||||
@@ -194,7 +194,7 @@ def get_linked_advances(company, docname):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_unreconcile_doc_for_selection(selections=None):
|
||||
def create_unreconcile_doc_for_selection(selections: str | None = None):
|
||||
if selections:
|
||||
selections = json.loads(selections)
|
||||
# assuming each row is a unique voucher
|
||||
|
||||
@@ -55,22 +55,22 @@ class DuplicatePartyAccountError(frappe.ValidationError):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_details(
|
||||
party=None,
|
||||
account=None,
|
||||
party_type="Customer",
|
||||
company=None,
|
||||
posting_date=None,
|
||||
bill_date=None,
|
||||
price_list=None,
|
||||
currency=None,
|
||||
doctype=None,
|
||||
ignore_permissions=False,
|
||||
fetch_payment_terms_template=True,
|
||||
party_address=None,
|
||||
company_address=None,
|
||||
shipping_address=None,
|
||||
dispatch_address=None,
|
||||
pos_profile=None,
|
||||
party: str | None = None,
|
||||
account: str | None = None,
|
||||
party_type: str = "Customer",
|
||||
company: str | None = None,
|
||||
posting_date: str | None = None,
|
||||
bill_date: str | None = None,
|
||||
price_list: str | None = None,
|
||||
currency: str | None = None,
|
||||
doctype: str | None = None,
|
||||
ignore_permissions: bool = False,
|
||||
fetch_payment_terms_template: bool = True,
|
||||
party_address: str | None = None,
|
||||
company_address: str | None = None,
|
||||
shipping_address: str | None = None,
|
||||
dispatch_address: str | None = None,
|
||||
pos_profile: str | None = None,
|
||||
):
|
||||
if not party:
|
||||
return frappe._dict()
|
||||
@@ -416,7 +416,9 @@ def set_account_and_due_date(party, account, party_type, company, posting_date,
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_account(party_type, party=None, company=None, include_advance=False):
|
||||
def get_party_account(
|
||||
party_type: str, party: str | None = None, company: str | None = None, include_advance: bool = False
|
||||
):
|
||||
"""Returns the account for the given `party`.
|
||||
Will first search in party (Customer / Supplier) record, if not found,
|
||||
will search in group (Customer Group / Supplier Group),
|
||||
@@ -501,7 +503,7 @@ def get_party_advance_account(party_type, party, company):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_bank_account(party_type, party):
|
||||
def get_party_bank_account(party_type: str, party: str):
|
||||
return frappe.db.get_value("Bank Account", {"party_type": party_type, "party": party, "is_default": 1})
|
||||
|
||||
|
||||
@@ -619,7 +621,14 @@ def validate_party_accounts(doc):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_due_date(posting_date, party_type, party, company=None, bill_date=None, template_name=None):
|
||||
def get_due_date(
|
||||
posting_date: str,
|
||||
party_type: str,
|
||||
party: str,
|
||||
company: str | None = None,
|
||||
bill_date: str | None = None,
|
||||
template_name: str | None = None,
|
||||
):
|
||||
"""Get due date from `Payment Terms Template`"""
|
||||
due_date = None
|
||||
if (bill_date or posting_date) and party:
|
||||
@@ -701,7 +710,9 @@ def validate_due_date_with_template(posting_date, due_date, bill_date, template_
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_address_tax_category(tax_category=None, billing_address=None, shipping_address=None):
|
||||
def get_address_tax_category(
|
||||
tax_category: str | None = None, billing_address: str | None = None, shipping_address: str | None = None
|
||||
):
|
||||
addr_tax_category_from = frappe.get_single_value(
|
||||
"Accounts Settings", "determine_address_tax_category_from"
|
||||
)
|
||||
@@ -717,16 +728,16 @@ def get_address_tax_category(tax_category=None, billing_address=None, shipping_a
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_taxes(
|
||||
party,
|
||||
party_type,
|
||||
posting_date,
|
||||
company,
|
||||
customer_group=None,
|
||||
supplier_group=None,
|
||||
tax_category=None,
|
||||
billing_address=None,
|
||||
shipping_address=None,
|
||||
use_for_shopping_cart=None,
|
||||
party: str,
|
||||
party_type: str,
|
||||
posting_date: str | None,
|
||||
company: str,
|
||||
customer_group: str | None = None,
|
||||
supplier_group: str | None = None,
|
||||
tax_category: str | None = None,
|
||||
billing_address: str | None = None,
|
||||
shipping_address: str | None = None,
|
||||
use_for_shopping_cart: int | None = None,
|
||||
):
|
||||
from erpnext.accounts.doctype.tax_rule.tax_rule import get_party_details, get_tax_template
|
||||
|
||||
@@ -766,7 +777,7 @@ def set_taxes(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_terms_template(party_name, party_type, company=None):
|
||||
def get_payment_terms_template(party_name: str, party_type: str, company: str | None = None):
|
||||
if party_type not in ("Customer", "Supplier"):
|
||||
return
|
||||
template = None
|
||||
|
||||
@@ -147,7 +147,12 @@ def get_appropriate_company(filters):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_invoiced_item_gross_margin(sales_invoice=None, item_code=None, company=None, with_item_data=False):
|
||||
def get_invoiced_item_gross_margin(
|
||||
sales_invoice: str | None = None,
|
||||
item_code: str | None = None,
|
||||
company: str | None = None,
|
||||
with_item_data: bool = False,
|
||||
):
|
||||
from erpnext.accounts.report.gross_profit.gross_profit import GrossProfitGenerator
|
||||
|
||||
sales_invoice = sales_invoice or frappe.form_dict.get("sales_invoice")
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
from collections import defaultdict
|
||||
from datetime import date
|
||||
from json import loads
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
@@ -60,15 +61,15 @@ OUTSTANDING_DOCTYPES = frozenset(["Sales Invoice", "Purchase Invoice", "Fees"])
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_fiscal_year(
|
||||
date=None,
|
||||
fiscal_year=None,
|
||||
label="Date",
|
||||
verbose=1,
|
||||
company=None,
|
||||
as_dict=False,
|
||||
boolean=None,
|
||||
raise_on_missing=True,
|
||||
truncate=False,
|
||||
date: str | date | None = None,
|
||||
fiscal_year: str | None = None,
|
||||
label: str = "Date",
|
||||
verbose: int = 1,
|
||||
company: str | None = None,
|
||||
as_dict: bool = False,
|
||||
boolean: str | None = None,
|
||||
raise_on_missing: bool = True,
|
||||
truncate: bool = False,
|
||||
):
|
||||
if isinstance(raise_on_missing, str):
|
||||
raise_on_missing = loads(raise_on_missing)
|
||||
@@ -93,14 +94,14 @@ def get_fiscal_year(
|
||||
|
||||
|
||||
def get_fiscal_years(
|
||||
transaction_date=None,
|
||||
fiscal_year=None,
|
||||
label="Date",
|
||||
verbose=1,
|
||||
company=None,
|
||||
as_dict=False,
|
||||
boolean=None,
|
||||
raise_on_missing=True,
|
||||
transaction_date: str | None = None,
|
||||
fiscal_year: str | None = None,
|
||||
label: str = "Date",
|
||||
verbose: int = 1,
|
||||
company: str | None = None,
|
||||
as_dict: bool = False,
|
||||
boolean: str | None = None,
|
||||
raise_on_missing: bool = True,
|
||||
):
|
||||
if transaction_date:
|
||||
transaction_date = getdate(transaction_date)
|
||||
@@ -171,7 +172,7 @@ def _get_fiscal_years(company=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_fiscal_year_filter_field(company=None):
|
||||
def get_fiscal_year_filter_field(company: str | None = None):
|
||||
field = {"fieldtype": "Select", "options": [], "operator": "Between", "query_value": True}
|
||||
fiscal_years = get_fiscal_years(company=company)
|
||||
for fiscal_year in fiscal_years:
|
||||
@@ -199,18 +200,18 @@ def validate_fiscal_year(date, fiscal_year, company, label="Date", doc=None):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_balance_on(
|
||||
account=None,
|
||||
date=None,
|
||||
party_type=None,
|
||||
party=None,
|
||||
company=None,
|
||||
in_account_currency=True,
|
||||
cost_center=None,
|
||||
ignore_account_permission=False,
|
||||
account_type=None,
|
||||
start_date=None,
|
||||
finance_book=None,
|
||||
include_default_fb_balances=False,
|
||||
account: str | None = None,
|
||||
date: str | None = None,
|
||||
party_type: str | None = None,
|
||||
party: str | None = None,
|
||||
company: str | None = None,
|
||||
in_account_currency: bool = True,
|
||||
cost_center: str | None = None,
|
||||
ignore_account_permission: bool = False,
|
||||
account_type: str | None = None,
|
||||
start_date: str | None = None,
|
||||
finance_book: str | None = None,
|
||||
include_default_fb_balances: bool = False,
|
||||
):
|
||||
if not account and frappe.form_dict.get("account"):
|
||||
account = frappe.form_dict.get("account")
|
||||
@@ -437,7 +438,7 @@ def get_count_on(account, fieldname, date):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def add_ac(args=None):
|
||||
def add_ac(args: frappe._dict | None = None):
|
||||
from frappe.desk.treeview import make_tree_args
|
||||
|
||||
if not args:
|
||||
@@ -469,7 +470,7 @@ def add_ac(args=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def add_cc(args=None):
|
||||
def add_cc(args: frappe._dict | None = None):
|
||||
from frappe.desk.treeview import make_tree_args
|
||||
|
||||
if not args:
|
||||
@@ -1153,7 +1154,7 @@ def remove_ref_doc_link_from_pe(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_company_default(company, fieldname, ignore_validation=False):
|
||||
def get_company_default(company: str, fieldname: str, ignore_validation: bool = False):
|
||||
value = frappe.get_cached_value("Company", company, fieldname)
|
||||
|
||||
if not ignore_validation and not value:
|
||||
@@ -1338,7 +1339,9 @@ def get_companies():
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(doctype, parent, company, is_root=False, include_disabled=False):
|
||||
def get_children(
|
||||
doctype: str, parent: str, company: str, is_root: bool = False, include_disabled: bool = False
|
||||
):
|
||||
if isinstance(include_disabled, str):
|
||||
include_disabled = loads(include_disabled)
|
||||
from erpnext.accounts.report.financial_statements import sort_accounts
|
||||
@@ -1371,7 +1374,12 @@ def get_children(doctype, parent, company, is_root=False, include_disabled=False
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_account_balances(accounts, company, finance_book=None, include_default_fb_balances=False):
|
||||
def get_account_balances(
|
||||
accounts: str | list,
|
||||
company: str,
|
||||
finance_book: str | None = None,
|
||||
include_default_fb_balances: bool = False,
|
||||
):
|
||||
if isinstance(accounts, str):
|
||||
accounts = loads(accounts)
|
||||
|
||||
@@ -1464,7 +1472,9 @@ def create_payment_gateway_account(gateway, payment_channel="Email", company=Non
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_cost_center(docname, cost_center_name, cost_center_number, company, merge):
|
||||
def update_cost_center(
|
||||
docname: str, cost_center_name: str, cost_center_number: str, company: str, merge: bool
|
||||
):
|
||||
"""
|
||||
Renames the document by adding the number as a prefix to the current name and updates
|
||||
all transaction where it was present.
|
||||
@@ -1544,7 +1554,7 @@ def parse_naming_series_variable(doc, variable):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_coa(doctype, parent, is_root=None, chart=None):
|
||||
def get_coa(doctype: str, parent: str, is_root: bool | None = None, chart: str | None = None):
|
||||
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import (
|
||||
build_tree_from_json,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user