# [15.53.0](https://github.com/frappe/erpnext/compare/v15.52.0...v15.53.0) (2025-02-19) ### Bug Fixes * add accounting dimensions section in sales order item ([b32e4da](b32e4daf2b)) * add is_new in if condition ([fc2ec7c](fc2ec7c495)) * add validate to allow equity account and party_type shareholder ([bb3eb81](bb3eb81170)) * allow scrap item with zero qty ([abe5384](abe5384449)) * auto create asset due to message error (backport [#45934](https://github.com/frappe/erpnext/issues/45934)) ([#45952](https://github.com/frappe/erpnext/issues/45952)) ([830edb8](830edb8f52)) * check if employee is currently working on another workstation ([22eaa14](22eaa14179)) * disable partial payment in pos (backport [#45752](https://github.com/frappe/erpnext/issues/45752)) ([#45945](https://github.com/frappe/erpnext/issues/45945)) ([38edc46](38edc46c46)) * do not reschedule depreciation for fully depreciated asset on scrap ([1e7c5ec](1e7c5ec0cb)) * fetch child account data for selected parent ([#45904](https://github.com/frappe/erpnext/issues/45904)) ([e36b860](e36b860a79)) * handle division by zero error (backport [#45966](https://github.com/frappe/erpnext/issues/45966)) ([#46015](https://github.com/frappe/erpnext/issues/46015)) ([15106b4](15106b49b6)) * include missing payment_gateway parameter in Payment Request URL ([18f9476](18f94765f7)) * letter head for quality inspection ([c289fef](c289fef3b5)) * link correct row item of purchase doc ([87f337b](87f337b605)) * make purchase_receipt_item and purchase_invoice_item fields of data type ([281431e](281431e041)) * millisecond issue for posting datetime ([4292365](42923656ee)) * patch for creating asset depreciation schedule records ([f043b46](f043b46696)) * pos accounting dimension fieldname error (backport [#45899](https://github.com/frappe/erpnext/issues/45899)) ([#45921](https://github.com/frappe/erpnext/issues/45921)) ([e998f06](e998f063a9)) * **pos profile:** check company while validating mandatory accounting dimension ([#45974](https://github.com/frappe/erpnext/issues/45974)) ([6a57743](6a577438aa)) * pos return validation on v15 ([#45951](https://github.com/frappe/erpnext/issues/45951)) ([dd34bbe](dd34bbe570)) * provision to enable naming series for SABB ([8fbfe14](8fbfe14c63)) * **quotation:** fetch exchange rate on currency change ([bd89c19](bd89c19c98)) * remove party type from validate ([0d21151](0d2115197e)) * remove public access to list items (backport [#45838](https://github.com/frappe/erpnext/issues/45838)) ([#46018](https://github.com/frappe/erpnext/issues/46018)) ([eead6d4](eead6d46ff)) * remove unused code ([dd5d144](dd5d144b55)) * **report:** add options to multiselectlist fields ([7e85a12](7e85a123b2)) * reset location only if there is value in row item location field ([a509568](a509568110)) * resolved conflicts ([84647a1](84647a1c73)) * round sum amount in JE auditing PF ([#45961](https://github.com/frappe/erpnext/issues/45961)) ([44e1ca9](44e1ca9d05)) * **send_message:** escape HTML in the text ([cbec989](cbec989a7c)) * serial no status for internal transfer delivery note ([2b80c00](2b80c009b3)) * set default value to 0 as per new logic ([1abe1a1](1abe1a1fd5)) * set sco_qty field of PO to non negative ([567fb8a](567fb8abd1)) * slow query ([8306d6f](8306d6fdb6)) * stock reservation for sales invoice ([1fb5586](1fb5586f56)) * stock reservation not working for sales invoice with update stock ([7d871f6](7d871f6bb5)) * tests ([f63a9db](f63a9dbf9b)) * throw correct exception ([5bccf9f](5bccf9f837)) * validate if no matching item found ([6183b38](6183b38089)) * validate payment request total of partly paid invoice ([c8881a9](c8881a9358)) ### Features * added ability to use custom html format for process statement of accounts (copy [#45746](https://github.com/frappe/erpnext/issues/45746)) ([#46012](https://github.com/frappe/erpnext/issues/46012)) ([1a4297a](1a4297ac35)) * added option to enforce free item qty in pricing rule ([8fb9228](8fb9228871)) * disable auto setting grand total to default mode of payment (backport [#45591](https://github.com/frappe/erpnext/issues/45591)) ([#45917](https://github.com/frappe/erpnext/issues/45917)) ([e271a5c](e271a5cba0))
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.53.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
|