23011df86b
# [15.15.0](https://github.com/frappe/erpnext/compare/v15.14.7...v15.15.0) (2024-02-28) ### Bug Fixes * add flags for repost to ensure correct accounting from India Compliance App ([7d14ecf
](7d14ecfcb8
)) * amount label according to party type ([d541ba3
](d541ba3e61
)) * Cannot read properties of undefined (backport [#40081](https://github.com/frappe/erpnext/issues/40081)) ([#40083](https://github.com/frappe/erpnext/issues/40083)) ([53d943e
](53d943ec70
)) * capacity planning issue in the job card (backport [#40092](https://github.com/frappe/erpnext/issues/40092)) ([#40101](https://github.com/frappe/erpnext/issues/40101)) ([27703b5
](27703b54bd
)) * change label name ([824df72
](824df72eeb
)) * check for pricing rules on item ([32d9642
](32d9642379
)) * check_credit_limit on_update_after_submit of Sales Order ([83d7111
](83d7111649
)) * communication_date in party dashboards (backport [#40005](https://github.com/frappe/erpnext/issues/40005)) ([#40021](https://github.com/frappe/erpnext/issues/40021)) ([4269ef8
](4269ef8c98
)) * Completed Work Orders report not working ([ca03e9c
](ca03e9cfd3
)) * Cr/Dr notes with POS Payments ([2e07b03
](2e07b03307
)) * currency symbol in landed cost voucher and material request (backport [#40138](https://github.com/frappe/erpnext/issues/40138)) ([#40141](https://github.com/frappe/erpnext/issues/40141)) ([57bb031
](57bb031602
)) * Data too long for column 'serial_no' at row 1 (backport [#40098](https://github.com/frappe/erpnext/issues/40098)) ([#40139](https://github.com/frappe/erpnext/issues/40139)) ([9d19ec4
](9d19ec43c8
)) * default taxable value for item not found in item list ([7e43f6b
](7e43f6b7e0
)) * delete PLE containing invoice in against ([190bd45
](190bd45bd7
)) * do not make MR against raw materials of available sub assemblies (backport [#40085](https://github.com/frappe/erpnext/issues/40085)) ([#40087](https://github.com/frappe/erpnext/issues/40087)) ([cf5fa21
](cf5fa210bb
)) * Fiscal Year exception on demo data setup ([56ee843
](56ee843233
)) * incorrect item name in MR (backport [#40018](https://github.com/frappe/erpnext/issues/40018)) ([#40024](https://github.com/frappe/erpnext/issues/40024)) ([9f8f3db
](9f8f3db953
)) * Issues regarding asset cancellation and deletion ([8eb2f67
](8eb2f67910
)) * negative stock error while making stock reconciliation (backport [#40016](https://github.com/frappe/erpnext/issues/40016)) ([#40026](https://github.com/frappe/erpnext/issues/40026)) ([c964c45
](c964c45f4e
)) * on unreconciliation, update advance paid ([4d1f56c
](4d1f56c4bd
)) * only check for delinked PLEs ([a75a69a
](a75a69a01e
)) * only consider contributed qty towards achieved targets ([194f46b
](194f46be57
)) * parent warehouse checks in the production plan for sub-assemblies (backport [#40150](https://github.com/frappe/erpnext/issues/40150)) ([#40157](https://github.com/frappe/erpnext/issues/40157)) ([4784117
](4784117a8f
)) * remove cancelled payment entry from Payment Period Based On Invoice Date ([72da308
](72da3083e6
)) * remove cancelled payment entry from PPBOID report ([0be5203
](0be520331c
)) * remove config for default bank account in test ([36b442a
](36b442a951
)) * remove microsecond from posting datetime (backport [#40017](https://github.com/frappe/erpnext/issues/40017)) ([#40022](https://github.com/frappe/erpnext/issues/40022)) ([eaa3849
](eaa3849df4
)) * removed unwanted patch ([ee2d108
](ee2d108bef
)) * resolved conflict ([6928674
](692867427c
)) * resolved conflict ([a0c0ab7
](a0c0ab7709
)) * skip max discount validation for rate adjustment ([3b96aae
](3b96aaeead
)) * skip SO & DN validation for debit note ([cd42089
](cd42089e20
)) * Supplier users not able to see RFQ on the Portal (backport [#40161](https://github.com/frappe/erpnext/issues/40161)) ([#40165](https://github.com/frappe/erpnext/issues/40165)) ([6a63a6c
](6a63a6c98a
)) * timesheet per billed state edge case (backport [#40010](https://github.com/frappe/erpnext/issues/40010)) ([#40029](https://github.com/frappe/erpnext/issues/40029)) ([a543bf4
](a543bf47ef
)) * translatable columns in Sales Pipeline Analytics report ([1c5a7e2
](1c5a7e29f2
)) * type error for missing frm obj ([6b5e1cf
](6b5e1cfeb7
)) * unique gl account for plaid bank accounts ([65853da
](65853da505
)) * use correct variable name on hotfix branches ([0694fd1
](0694fd19fd
)) * use frm instead of cur_frm ([341f903
](341f9030f5
)) * use serial batch fields for packed items (backport [#40140](https://github.com/frappe/erpnext/issues/40140)) ([#40142](https://github.com/frappe/erpnext/issues/40142)) ([1860399
](1860399ccb
)) ### Features * show contributed qty in transaction summary ([38abfdb
](38abfdb8ae
)) * update billed amount in PO and PR ([e7e8149
](e7e8149fbe
)) ### Performance Improvements * new column Posting Datetime in SLE to optimize stock ledger related queries (backport [#39800](https://github.com/frappe/erpnext/issues/39800)) ([#40004](https://github.com/frappe/erpnext/issues/40004)) ([b9181e8
](b9181e85dc
))
154 lines
4.2 KiB
Python
154 lines
4.2 KiB
Python
import functools
|
|
import inspect
|
|
|
|
import frappe
|
|
|
|
__version__ = "15.15.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
|