mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-23 08:38:30 +00:00
# [16.1.0](https://github.com/frappe/erpnext/compare/v16.0.1...v16.1.0) (2026-01-20) ### Bug Fixes * **accounts_controller:** make return message translatable ([621243c](621243c1d3)) * **accounts:** add missing accounting dimensions in advance taxes and charges ([673635e](673635e2c3)) * add below-0 column in ar/ap report (backport [#51673](https://github.com/frappe/erpnext/issues/51673)) ([#51780](https://github.com/frappe/erpnext/issues/51780)) ([5c93bf5](5c93bf5798)) * add company filters for warehouse ([ccab91b](ccab91b9ed)) * add other charges in total ([68c8dfb](68c8dfb24c)) * add uom js error ([a660ed0](a660ed061b)) * add validation for amount and hours ([ce421bb](ce421bb1d4)) * add validation for direct return ([bfd6375](bfd6375508)) * add validation for duplication ([84a749e](84a749e3d0)) * add validation for return against ([6dade11](6dade11d8f)) * allow creation of DN in SI for items not having DN reference ([fef6df7](fef6df709d)) * allow disassemble stock entry without work order (backport [#51761](https://github.com/frappe/erpnext/issues/51761)) ([#51836](https://github.com/frappe/erpnext/issues/51836)) ([c830bf6](c830bf6fc7)) * **bank_account:** validation for is_company_account ([5d5d208](5d5d208a49)) * **bom:** pass company warehouse filter ([3c533d0](3c533d04f5)) * **budget variance report:** check budget dimensions ([a3d860e](a3d860eabf)) * bugs ([accce1f](accce1fe59)) * calculate net profit amount from root node accounts ([89b44c4](89b44c41a2)) * change docfield type to render html format (backport [#51795](https://github.com/frappe/erpnext/issues/51795)) ([#51804](https://github.com/frappe/erpnext/issues/51804)) ([fcea760](fcea7603a8)) * common_party_path ([#51826](https://github.com/frappe/erpnext/issues/51826)) ([aeb2b60](aeb2b60450)) * continuous raw material consumption with bom validation (backport [#51914](https://github.com/frappe/erpnext/issues/51914)) ([#51919](https://github.com/frappe/erpnext/issues/51919)) ([c9d7c6c](c9d7c6cd42)) * docs_path ([86d5939](86d5939d91)) * dont show certain fields based on permissions ([d3dfed9](d3dfed909e)) * handle return cancellation ([65a1c70](65a1c7086b)) * include total hours validation in depends on ([cbfc137](cbfc13728b)) * **manufacturing:** consider process loss qty while validating the work order ([7b3f746](7b3f74609a)) * no attribute error on LCV ([fe59ace](fe59ace285)) * no attribute error on subcontracting receipt ([2131c7a](2131c7aadb)) * overproduction % not considered when making WO from SO ([fb669eb](fb669eb6f4)) * **pos:** reapply set warehouse during cart update ([6869115](686911546f)) * **postgres:** compute current month sales without DATE_FORMAT ([49760e4](49760e4542)) * prevent UOM from updating incorrectly while scanning barcode ([9d5a0e5](9d5a0e56a0)) * qty with serial no count ([ae6b3af](ae6b3af013)) * remove already transferred batch ([f1e41f4](f1e41f4a4f)) * setting process loss qty causes fg item qty to be incorrect ([cb2d455](cb2d4550af)) * Show non-SLE vouchers with GL entries in Stock vs Account Value Comparison report ([e64ae9a](e64ae9a8a9)) * **stock:** resolve quantity issue when adding items via barcode scan ([ab482ca](ab482caac9)) * **transaction.js:** use flt instead of cint for plc_conversion_rate ([8ba4701](8ba470160d)) * validation message in stock reco row idx ([176096b](176096bc5b)) * valuation rate for non batchwise valuation ([768c131](768c131073)) ### Features * add list_view status for partial billing ([9b88275](9b88275312)) * add new 2025 Charts of Accounts for France ([9cc9fa5](9cc9fa59be)) * Adding Item name in update item dialog box ([1da8ed2](1da8ed202b)) * modify field properties ([e49add2](e49add20b7)) * remove old French chart of accounts with code as nex 2025 is provided ([3bdaab1](3bdaab149b)) * support for serial item ([c4c2d35](c4c2d35565)) * **timesheet:** handle partial billing in sales invoice ([332673f](332673f260)) ### Performance Improvements * prevent duplicate reposting for the same item ([3ac431b](3ac431bd50))
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.1.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
|