mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-20 10:45:29 +00:00
# [15.89.0](https://github.com/frappe/erpnext/compare/v15.88.1...v15.89.0) (2025-11-19) ### Bug Fixes * add cancelled option in status field ([623a0a9](623a0a932e)) * add condition for allow negative stock in pos (backport [#50369](https://github.com/frappe/erpnext/issues/50369)) ([#50600](https://github.com/frappe/erpnext/issues/50600)) ([2d6640a](2d6640ac61)) * add doctype parameter to lead details for correct company details ([f0eac47](f0eac47037)) * **asset repair:** validate pi status ([2db91ee](2db91ee67e)) * back calcalute total amount from rate and tax_amount in tax withholding details report ([5728299](57282999ad)) * construct batch_nos and serial_nos to avoid NoneType error ([0a0177c](0a0177cb9e)) * correct profit after tax calculation by reducing expenses from income ([627b34a](627b34a120)) * current qty in stock reco ([b4b8459](b4b8459f2c)) * enable allow_negative_stock settings ([2a5c9b4](2a5c9b469c)) * **financial reports:** set fiscal year associated with the default company ([ac40b59](ac40b59665)) * first and last name in supplier quick entry (backport [#50510](https://github.com/frappe/erpnext/issues/50510)) ([#50514](https://github.com/frappe/erpnext/issues/50514)) ([3b636d5](3b636d5db7)) * **general_ledger:** add translation for accounting dimension ([799119a](799119ad3e)) * handle NoneType object error for product bundle ([2b7abfb](2b7abfb34b)) * improve precision in tax amount calculations in tax withholding details report ([c150e57](c150e5795e)) * on changes of paid from/to account fetch company bank account ([3d8a344](3d8a344173)) * **period closing voucher:** add title to error log ([#50498](https://github.com/frappe/erpnext/issues/50498)) ([33962ac](33962ac995)) * prevent pos opening entry creation for disabled pos profile ([68747b5](68747b5818)) * **stock-entry:** prevent default warehouse from overriding parent warehouse ([a5ec0e4](a5ec0e4f50)) * unintended backported depends_on expression ([#50529](https://github.com/frappe/erpnext/issues/50529)) ([81a1628](81a16286a1)) * use dynamic account type to get average ratio balance ([a2c82b4](a2c82b4dc3)) ### Features * Add first and last name fields to quick entry customer creation (backport [#46281](https://github.com/frappe/erpnext/issues/46281)) ([#50522](https://github.com/frappe/erpnext/issues/50522)) ([8c98f16](8c98f1692a)) * **Company:** allow setting default sales contact, fetch into sales transaction (backport [#50159](https://github.com/frappe/erpnext/issues/50159)) ([#50599](https://github.com/frappe/erpnext/issues/50599)) ([f8294f1](f8294f1754)) * **Item Price:** validate UOM ([376da8d](376da8df0a)) * **pos:** prevent disabling POS Profile when open POS sessions exist ([87e8305](87e8305753))
163 lines
4.4 KiB
Python
163 lines
4.4 KiB
Python
import functools
|
|
import inspect
|
|
|
|
import frappe
|
|
from frappe.utils.user import is_website_user
|
|
|
|
__version__ = "15.89.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.flags.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.flags.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
|