mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-23 20:16:40 +00:00
# [16.24.0](https://github.com/frappe/erpnext/compare/v16.23.1...v16.24.0) (2026-06-23) ### Bug Fixes * add customer type in the list view ([c788106](c788106011)) * add partially transferred status and fix button visibility for partial material transfer on job card ([570ef45](570ef45e46)) * add validation and tests for set_status ([bcd72a7](bcd72a7fec)) * address product bundle review comments ([c066880](c066880978)) * apply docstatus filter to exclude cancelled Work Orders in Serial No ([58d5f39](58d5f39e0a)) * **budget:** ambiguous error message for budget assignment validation (backport [#56390](https://github.com/frappe/erpnext/issues/56390)) ([#56392](https://github.com/frappe/erpnext/issues/56392)) ([2b6f2c2](2b6f2c2f9c)) * clear stale payment rows on non-POS returns so they don't surface in bank reconciliation (backport [#55903](https://github.com/frappe/erpnext/issues/55903)) ([#56171](https://github.com/frappe/erpnext/issues/56171)) ([d363186](d3631860db)) * **coa_importer:** allow importing COA through `import_coa` only for `Accounts Manager` (backport [#56132](https://github.com/frappe/erpnext/issues/56132)) ([#56140](https://github.com/frappe/erpnext/issues/56140)) ([e6e5591](e6e5591088)) * company default handling in purchase transactions made from project ([29323cb](29323cb0b1)) * customer master form cleanup ([8b56b7b](8b56b7ba0e)) * disable is_debit_note while creating credit note ([c7dbedb](c7dbedbfdc)) * disarding stock entry fix ([5372254](537225494c)) * **err:** add missing permission check on `get_account_details` ([88ce356](88ce356d62)) * escape user image url on various templates (backport [#56269](https://github.com/frappe/erpnext/issues/56269)) ([#56271](https://github.com/frappe/erpnext/issues/56271)) ([3b734f4](3b734f4d5d)) * fetch party types based on account type in journal entry and refactor SQL to query builder ([bbb3181](bbb3181c6e)) * honor account freezing date when cancelling vouchers ([f4b827c](f4b827cb3d)) * **journal entry:** validate opening entry against pcv on save ([f8aa4c7](f8aa4c730c)) * lock budget distribution table and guard against null distribution rows ([2b28b7e](2b28b7e694)) * **manufacturing:** make item_code mandatory in Job Card Item ([d40c36a](d40c36a4b1)) * party specific item doesnt work if there are 2 suppliers with same item ([3df7a28](3df7a28476)) * **payment_entry:** recompute base amount when exchange rate changes (backport [#56136](https://github.com/frappe/erpnext/issues/56136)) ([#56398](https://github.com/frappe/erpnext/issues/56398)) ([1d0edf1](1d0edf1b9a)) * placement of fields ([#56257](https://github.com/frappe/erpnext/issues/56257)) ([3f53af8](3f53af8b1f)) * **pos:** remove redundant opening balance dialog onchange handler (backport [#54591](https://github.com/frappe/erpnext/issues/54591)) ([#56403](https://github.com/frappe/erpnext/issues/56403)) ([4555c32](4555c323af)) * preserve stock ageing on non-serial reconciliation ([846e0a9](846e0a9f06)) * removing the document naming series dialog and moving to framework ([97279c7](97279c7e26)) * **report_utils:** remove unnecessary whitelist decorator on `get_invoiced_item_gross_margin` ([bf58393](bf58393fda)) * resolve backport merge conflicts in customer.json ([77121f2](77121f2a41)) * resolve backport merge conflicts in supplier.json ([a80de9b](a80de9bd01)) * **stock:** allow partial raw material picking/transfer from work order ([8e3fbab](8e3fbab94a)) * **stock:** apply precision to the additional cost amount in stock entry ([6ac699d](6ac699d3bb)) * **stock:** define qi exception classes in exceptions file ([42c121a](42c121a750)) * **stock:** enable quality inspection for all Stock Entry purposes ([a631035](a6310351fd)) * **stock:** propagate renamed attribute values to variant items ([dbc831e](dbc831e008)) * **stock:** update transfer status for mixed transfer flows ([84a1a51](84a1a51023)) * **stock:** update variant attributes on value rename ([3110ab1](3110ab1c57)) * **stock:** update voucher valuaion rate in sle (backport [#55960](https://github.com/frappe/erpnext/issues/55960)) ([#56263](https://github.com/frappe/erpnext/issues/56263)) ([82e1221](82e1221dc9)) * submittable product bundle issues ([7a1def0](7a1def07e9)) * supplier master form cleanup ([e5c9e7a](e5c9e7abdc)) * supplier status in list view ([2035fac](2035fac494)) * tax.base_tax_amount as none when payment entry created using API ([43b355e](43b355eaf6)) * type def in get_linked_payments ([#56100](https://github.com/frappe/erpnext/issues/56100)) ([8e21af0](8e21af0a63)) * update reference doctype mapping and field visibility in bank guarantee ([dc9ae20](dc9ae20db8)) * update round off account functions to accept document context for regional overrides (backport [#55758](https://github.com/frappe/erpnext/issues/55758)) ([#55771](https://github.com/frappe/erpnext/issues/55771)) ([f5d05b9](f5d05b969b)) * update weighted average rate calculation to consider returned and consumed quantities ([35e0604](35e06045bd)) ### Features * add batch-level option to allow negative stock for batch ([1f075d4](1f075d4bbf)) * allocate full actual charge to stock items only (e.g. Freight) (backport [#56102](https://github.com/frappe/erpnext/issues/56102)) ([#56222](https://github.com/frappe/erpnext/issues/56222)) ([9469889](9469889bd5)) * **opening invoice creation tool:** add project to opening invoice child row (backport [#54662](https://github.com/frappe/erpnext/issues/54662)) ([#56401](https://github.com/frappe/erpnext/issues/56401)) ([d54938f](d54938fa64)) * party aliases ([768425e](768425ebf1)) ### Performance Improvements * composite index on (serial_no, warehouse, posting_datetime) for Serial and Batch Entry (backport [#56032](https://github.com/frappe/erpnext/issues/56032)) ([#56166](https://github.com/frappe/erpnext/issues/56166)) ([c0dab55](c0dab55fcc))
196 lines
5.3 KiB
Python
196 lines
5.3 KiB
Python
import functools
|
|
import inspect
|
|
from typing import TypeVar
|
|
|
|
import frappe
|
|
from frappe.model.document import Document
|
|
from frappe.utils.user import is_website_user
|
|
|
|
__version__ = "16.24.0"
|
|
|
|
|
|
def get_default_company(user=None):
|
|
"""Get default company for user"""
|
|
from frappe.defaults import get_user_default_as_list
|
|
|
|
if not user:
|
|
user = frappe.session.user
|
|
|
|
companies = get_user_default_as_list("company", user)
|
|
if companies:
|
|
default_company = companies[0]
|
|
else:
|
|
default_company = frappe.db.get_single_value("Global Defaults", "default_company")
|
|
|
|
return default_company
|
|
|
|
|
|
def get_default_currency():
|
|
"""Returns the currency of the default company"""
|
|
company = get_default_company()
|
|
if company:
|
|
return frappe.get_cached_value("Company", company, "default_currency")
|
|
|
|
|
|
def get_default_cost_center(company):
|
|
"""Returns the default cost center of the company"""
|
|
if not company:
|
|
return None
|
|
|
|
if not frappe.flags.company_cost_center:
|
|
frappe.flags.company_cost_center = {}
|
|
if company not in frappe.flags.company_cost_center:
|
|
frappe.flags.company_cost_center[company] = frappe.get_cached_value("Company", company, "cost_center")
|
|
return frappe.flags.company_cost_center[company]
|
|
|
|
|
|
def get_company_currency(company):
|
|
"""Returns the default company currency"""
|
|
if not frappe.flags.company_currency:
|
|
frappe.flags.company_currency = {}
|
|
if company not in frappe.flags.company_currency:
|
|
frappe.flags.company_currency[company] = frappe.db.get_value(
|
|
"Company", company, "default_currency", cache=True
|
|
)
|
|
return frappe.flags.company_currency[company]
|
|
|
|
|
|
def set_perpetual_inventory(enable=1, company=None):
|
|
if not company:
|
|
company = "_Test Company" if frappe.in_test else get_default_company()
|
|
|
|
company = frappe.get_doc("Company", company)
|
|
company.enable_perpetual_inventory = enable
|
|
company.save()
|
|
|
|
|
|
def encode_company_abbr(name, company=None, abbr=None):
|
|
"""Returns name encoded with company abbreviation"""
|
|
company_abbr = abbr or frappe.get_cached_value("Company", company, "abbr")
|
|
parts = name.rsplit(" - ", 1)
|
|
|
|
if parts[-1].lower() != company_abbr.lower():
|
|
parts.append(company_abbr)
|
|
|
|
return " - ".join(parts)
|
|
|
|
|
|
def is_perpetual_inventory_enabled(company):
|
|
if not company:
|
|
company = "_Test Company" if frappe.in_test else get_default_company()
|
|
|
|
if not hasattr(frappe.local, "enable_perpetual_inventory"):
|
|
frappe.local.enable_perpetual_inventory = {}
|
|
|
|
if company not in frappe.local.enable_perpetual_inventory:
|
|
frappe.local.enable_perpetual_inventory[company] = (
|
|
frappe.get_cached_value("Company", company, "enable_perpetual_inventory") or 0
|
|
)
|
|
|
|
return frappe.local.enable_perpetual_inventory[company]
|
|
|
|
|
|
def get_default_finance_book(company=None):
|
|
if not company:
|
|
company = get_default_company()
|
|
|
|
if not hasattr(frappe.local, "default_finance_book"):
|
|
frappe.local.default_finance_book = {}
|
|
|
|
if company not in frappe.local.default_finance_book:
|
|
frappe.local.default_finance_book[company] = frappe.get_cached_value(
|
|
"Company", company, "default_finance_book"
|
|
)
|
|
|
|
return frappe.local.default_finance_book[company]
|
|
|
|
|
|
def get_party_account_type(party_type):
|
|
if not hasattr(frappe.local, "party_account_types"):
|
|
frappe.local.party_account_types = {}
|
|
|
|
if party_type not in frappe.local.party_account_types:
|
|
frappe.local.party_account_types[party_type] = (
|
|
frappe.db.get_value("Party Type", party_type, "account_type") or ""
|
|
)
|
|
|
|
return frappe.local.party_account_types[party_type]
|
|
|
|
|
|
def get_region(company=None):
|
|
"""Return the default country based on flag, company or global settings
|
|
|
|
You can also set global company flag in `frappe.flags.company`
|
|
"""
|
|
|
|
if not company:
|
|
company = frappe.local.flags.company
|
|
|
|
if company:
|
|
return frappe.get_cached_value("Company", company, "country")
|
|
|
|
return frappe.flags.country or frappe.get_system_settings("country")
|
|
|
|
|
|
def allow_regional(fn):
|
|
"""Decorator to make a function regionally overridable
|
|
|
|
Example:
|
|
@erpnext.allow_regional
|
|
def myfunction():
|
|
pass"""
|
|
|
|
@functools.wraps(fn)
|
|
def caller(*args, **kwargs):
|
|
overrides = frappe.get_hooks("regional_overrides", {}).get(get_region())
|
|
function_path = f"{inspect.getmodule(fn).__name__}.{fn.__name__}"
|
|
|
|
if not overrides or function_path not in overrides:
|
|
return fn(*args, **kwargs)
|
|
|
|
# Priority given to last installed app
|
|
return frappe.get_attr(overrides[function_path][-1])(*args, **kwargs)
|
|
|
|
return caller
|
|
|
|
|
|
def check_app_permission():
|
|
if frappe.session.user == "Administrator":
|
|
return True
|
|
|
|
if is_website_user():
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
def normalize_ctx_input(T: type) -> callable:
|
|
"""
|
|
Normalizes the first argument (ctx) of the decorated function by:
|
|
- Converting Document objects to dictionaries
|
|
- Parsing JSON strings
|
|
- Casting the result to the specified type T
|
|
"""
|
|
|
|
def decorator(func: callable):
|
|
# conserve annotations for frappe.utils.typing_validations
|
|
@functools.wraps(func, assigned=(a for a in functools.WRAPPER_ASSIGNMENTS if a != "__annotations__"))
|
|
def wrapper(ctx: T | Document | dict | str, *args, **kwargs):
|
|
if isinstance(ctx, Document):
|
|
ctx = T(**ctx.as_dict())
|
|
elif isinstance(ctx, dict):
|
|
ctx = T(**ctx)
|
|
else:
|
|
ctx = T(**frappe.parse_json(ctx))
|
|
|
|
return func(ctx, *args, **kwargs)
|
|
|
|
# set annotations from function
|
|
wrapper.__annotations__.update({k: v for k, v in func.__annotations__.items() if k != "ctx"})
|
|
return wrapper
|
|
|
|
return decorator
|