## [15.48.4](https://github.com/frappe/erpnext/compare/v15.48.3...v15.48.4) (2025-01-15) ### Bug Fixes * auto fetch batch and serial no for draft stock transactions ([2f2554e](2f2554e9e5)) * batch number search on pos ([#45209](https://github.com/frappe/erpnext/issues/45209)) ([fe5c458](fe5c458c45)) * change string to be able to translate ([#45090](https://github.com/frappe/erpnext/issues/45090)) ([7a3687c](7a3687ca8e)) * deduct tds on excess amount if checked ([07c3605](07c3605905)) * delivery_document_no column issue ([0df1808](0df18080c7)) * do not add ordered items from Quotation to new Sales Order ([f414fa4](f414fa4981)) * don't create invoice if invoice start date is in future ([3f6d774](3f6d7741d9)) * incorrect label in Item-wise sales register ([36d1fbd](36d1fbd6a3)) * incorrect valuation for sales return with different warhouse ([9ee5651](9ee5651848)) * incorrect valuation rate for PI based revaluation ([f7e3854](f7e3854641)) * linter issue ([af21bca](af21bca231)) * minor update for readability ([abfcfdf](abfcfdfe7e)) * not able to see create Quality Inspection button ([a79cae1](a79cae1fef)) * pass right existing address ([80e6112](80e6112549)) * precision loss causing process loss variance ([d84601b](d84601b2a3)) * Semgrep rules ([1d5a73a](1d5a73a325)) * set billing and shipping address on change of company ([42eb88f](42eb88f5f6)) * Skip WIP Warehouse transfer ([bb0695a](bb0695a883)) * test case ([f5667f5](f5667f56e4)) * test case ([7d66e4e](7d66e4efb0)) * tests ([8ba42cf](8ba42cfbf0)) * timeout error for work order ([122b966](122b966a7b)) * **Timesheet:** ignore permissions when updating Task and Project (backport [#45168](https://github.com/frappe/erpnext/issues/45168)) ([#45170](https://github.com/frappe/erpnext/issues/45170)) ([f7448c6](f7448c6f79)) * typo in manufacturing settings (backport [#45190](https://github.com/frappe/erpnext/issues/45190)) ([#45193](https://github.com/frappe/erpnext/issues/45193)) ([47c6e5a](47c6e5a931)) * update discounting on mixed conditions ([38cb5a9](38cb5a98bf))
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.48.4"
|
|
|
|
|
|
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
|