mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-19 18:25:32 +00:00
# [14.37.0](https://github.com/frappe/erpnext/compare/v14.36.0...v14.37.0) (2023-08-30) ### Bug Fixes * added valuation field type (Float/Currency) in the filter (backport [#36866](https://github.com/frappe/erpnext/issues/36866)) ([#36868](https://github.com/frappe/erpnext/issues/36868)) ([22247cf](22247cfa17)) * Allow to make return against sales invoice which has closed sales order ([0f98cc8](0f98cc85e9)) * Asset Category filter is not working in asset depreciation([#36806](https://github.com/frappe/erpnext/issues/36806)) ([bd41cb2](bd41cb221b)) * create entries for only PR items present in LCV ([#36852](https://github.com/frappe/erpnext/issues/36852)) ([d2091cc](d2091cc22c)) * error in report when data is not available to load chart in report (backport [#36842](https://github.com/frappe/erpnext/issues/36842)) ([#36853](https://github.com/frappe/erpnext/issues/36853)) ([9789b7b](9789b7bdef)) * error listindexoutofrange when save a production plan ([#36807](https://github.com/frappe/erpnext/issues/36807)) ([fd41594](fd4159423d)) * fetch JVs in tax withholding report without party values ([bc6bd81](bc6bd81f87)) * fetch rounded total while pulling reference details on SO ([adc87f1](adc87f16a3)) * missing company flag for regional fn ([#36791](https://github.com/frappe/erpnext/issues/36791)) ([c07548a](c07548a612)) * SCR return status (backport [#36793](https://github.com/frappe/erpnext/issues/36793)) ([#36796](https://github.com/frappe/erpnext/issues/36796)) ([6edfcf4](6edfcf4de8)) * Tax withholding reversal on Debit Notes ([e8dc63c](e8dc63c89c)) ### Features * **MR:** Project and Cost Center in Connections (backport [#36794](https://github.com/frappe/erpnext/issues/36794)) ([#36795](https://github.com/frappe/erpnext/issues/36795)) ([4fa0777](4fa07777e9))
154 lines
4.2 KiB
Python
154 lines
4.2 KiB
Python
import functools
|
|
import inspect
|
|
|
|
import frappe
|
|
|
|
__version__ = "14.37.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(user, "company")
|
|
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 not company 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 not company 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 not company 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 not company 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 not party_type 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
|