Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

154 lines
4.2 KiB
Python
Raw Normal View History

import functools
import inspect
import frappe
chore(release): Bumped to Version 15.4.0 # [15.4.0](https://github.com/frappe/erpnext/compare/v15.3.0...v15.4.0) (2023-11-28) ### Bug Fixes * allow on submit for child table fields ([ac7615a](https://github.com/frappe/erpnext/commit/ac7615ac0191bbd8b9c7fd9bae9ac6d3b37d11af)) * annual income and expenses in digest ([ca2ad17](https://github.com/frappe/erpnext/commit/ca2ad175d3ccd62289c0a9af26ba78debfbb170a)) * check reposting settings before allowing editable si ([25bf475](https://github.com/frappe/erpnext/commit/25bf475d5a9feb8b41aafef9e4459aae4832c8c1)) * condition in other bundle utils ([e4d9ef1](https://github.com/frappe/erpnext/commit/e4d9ef12938c8470df317ffce6b99fd34a3b6549)) * create contact if existing customer doesn't have contact ([b1b065d](https://github.com/frappe/erpnext/commit/b1b065daf1f79eb83834aaa033ecf89403e75877)) * display all item rate stop messages (backport [#38289](https://github.com/frappe/erpnext/issues/38289)) ([#38307](https://github.com/frappe/erpnext/issues/38307)) ([99c1fbf](https://github.com/frappe/erpnext/commit/99c1fbf9fc6cce11aad16a055d23a16c62925fed)) * do not set repost flag without validating voucher ([6a3c3b4](https://github.com/frappe/erpnext/commit/6a3c3b4cac984ee24208e8a6ff80c4425a88a395)) * don't depreciate assets with no schedule on scrapping (backport [#38276](https://github.com/frappe/erpnext/issues/38276)) ([#38293](https://github.com/frappe/erpnext/issues/38293)) ([18613c5](https://github.com/frappe/erpnext/commit/18613c595f32371997f17b24249f5d7fc13a8240)) * filter bundle items based on disabled check ([fb517e8](https://github.com/frappe/erpnext/commit/fb517e823f66ee43e471bc74bca5bd6b959a4f53)) * fiscal year using future date ([b9a1fac](https://github.com/frappe/erpnext/commit/b9a1fac7d8454399dad3f59093e88cec1f0c90dc)) * has_product_bundle util to only check for enabled bundles ([5c12872](https://github.com/frappe/erpnext/commit/5c12872f706d51b8e5b14da7db6564577e95ae70)) * job card overlap validation (backport [#38345](https://github.com/frappe/erpnext/issues/38345)) ([#38348](https://github.com/frappe/erpnext/issues/38348)) ([d6fe7eb](https://github.com/frappe/erpnext/commit/d6fe7eb10c9136ba4166f9f7ade032c2c7a645f5)) * make parameters of `create_subscription_process` optional (and other minor fixes) ([#38360](https://github.com/frappe/erpnext/issues/38360)) ([721b429](https://github.com/frappe/erpnext/commit/721b429d9316e2901ac34f20bc9c6d71e8c00acc)) * Negative Qty and Rates in SO/PO (backport [#38252](https://github.com/frappe/erpnext/issues/38252)) ([#38357](https://github.com/frappe/erpnext/issues/38357)) ([14174df](https://github.com/frappe/erpnext/commit/14174df86277ab3d6dee25f17156f637645ce89c)) * no fstring in translation (backport [#38381](https://github.com/frappe/erpnext/issues/38381)) ([#38387](https://github.com/frappe/erpnext/issues/38387)) ([c101855](https://github.com/frappe/erpnext/commit/c1018555a0c8600a988b10483419dc0a92f2c415)) * patch - Duplicate entry quality inspection parameter (backport [#38262](https://github.com/frappe/erpnext/issues/38262)) ([#38264](https://github.com/frappe/erpnext/issues/38264)) ([4c9890a](https://github.com/frappe/erpnext/commit/4c9890a24e656bee30b1de74e192f8e82b2b57d9)) * Payment Reco Issue and chart of account importer ([4699887](https://github.com/frappe/erpnext/commit/4699887f1c8b6b93de9971f4b810da95ea0afc9f)) * serial no status (backport [#38391](https://github.com/frappe/erpnext/issues/38391)) ([#38397](https://github.com/frappe/erpnext/issues/38397)) ([b65c225](https://github.com/frappe/erpnext/commit/b65c22579d61973d0bc8cab25f8ee1c3b2cbdb8a)) * Server Error while creating Product Bundle (backport [#38377](https://github.com/frappe/erpnext/issues/38377)) ([#38380](https://github.com/frappe/erpnext/issues/38380)) ([922aef6](https://github.com/frappe/erpnext/commit/922aef665b25ef4c5642de46fbd817d14402e23e)) * skip disabled bundles for non-report utils ([3d46b32](https://github.com/frappe/erpnext/commit/3d46b323b324c62f42a37e423eb5ce2a63c26b88)) * skip fixed assets in parent ([314a91a](https://github.com/frappe/erpnext/commit/314a91ac4d82d5487f74868dc12c808491544723)) * Supplier `Primary Contact` (backport [#38268](https://github.com/frappe/erpnext/issues/38268)) ([#38286](https://github.com/frappe/erpnext/issues/38286)) ([37d1f1a](https://github.com/frappe/erpnext/commit/37d1f1ac67e9b2b62b51e0527637b9690e99234c)) * **ux:** Sales Order Stock Reservation Dialog (backport [#38261](https://github.com/frappe/erpnext/issues/38261)) ([#38344](https://github.com/frappe/erpnext/issues/38344)) ([3cbe599](https://github.com/frappe/erpnext/commit/3cbe59902aab249199297bc110ca2bbfc0e517ca)) * validation for existing bundles ([c0de9c0](https://github.com/frappe/erpnext/commit/c0de9c0cef860ce10b1da13f8f4e0288af09ceb6)) ### Features * add Bank Transaction to connections in Journal and Payment Entry (backport [#38297](https://github.com/frappe/erpnext/issues/38297)) ([#38301](https://github.com/frappe/erpnext/issues/38301)) ([72647b8](https://github.com/frappe/erpnext/commit/72647b862469f8a6d5900f92a605088da4b8b131)) * add disabled field in product bundle ([fcd53be](https://github.com/frappe/erpnext/commit/fcd53be1881554b16797689ea05ba248221fd07c)) * new Report "Lost Quotations" ([#38309](https://github.com/frappe/erpnext/issues/38309)) ([ea2c348](https://github.com/frappe/erpnext/commit/ea2c3487a3c33b86de3cb7532ffe9cecb174e897)) ### Performance Improvements * optimize total_purchase_cost update ([deed9f5](https://github.com/frappe/erpnext/commit/deed9f5840dea5485febcd18e29fcf1d9291fcf4))
2023-11-28 16:24:28 +00:00
__version__ = "15.4.0"
2022-04-08 17:24:10 +05:30
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:
2018-08-08 16:37:31 +05:30
return frappe.get_cached_value("Company", company, "default_currency")
2022-03-28 18:52:46 +05:30
2017-01-16 16:57:53 +05:30
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:
2018-08-08 16:37:31 +05:30
frappe.flags.company_cost_center[company] = frappe.get_cached_value(
"Company", company, "cost_center"
)
return frappe.flags.company_cost_center[company]
2022-03-28 18:52:46 +05:30
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:
2018-08-09 11:50:34 +05:30
frappe.flags.company_currency[company] = frappe.db.get_value(
"Company", company, "default_currency", cache=True
)
return frappe.flags.company_currency[company]
2022-03-28 18:52:46 +05:30
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()
2022-03-28 18:52:46 +05:30
def encode_company_abbr(name, company=None, abbr=None):
2017-01-16 16:57:53 +05:30
"""Returns name encoded with company abbreviation"""
company_abbr = abbr or frappe.get_cached_value("Company", company, "abbr")
2017-01-16 16:57:53 +05:30
parts = name.rsplit(" - ", 1)
if parts[-1].lower() != company_abbr.lower():
parts.append(company_abbr)
return " - ".join(parts)
2022-03-28 18:52:46 +05:30
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"):
2017-06-20 12:14:32 +05:30
frappe.local.enable_perpetual_inventory = {}
2017-06-20 12:14:32 +05:30
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
2018-08-08 16:37:31 +05:30
)
2017-06-20 12:14:32 +05:30
return frappe.local.enable_perpetual_inventory[company]
2022-03-28 18:52:46 +05:30
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(
2018-08-08 16:37:31 +05:30
"Company", company, "default_finance_book"
)
return frappe.local.default_finance_book[company]
2022-03-28 18:52:46 +05:30
2018-05-16 11:02:26 +05:30
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]
2022-03-28 18:52:46 +05:30
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`
2022-03-28 18:52:46 +05:30
"""
2023-04-04 17:50:31 +05:30
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")
2022-03-28 18:52:46 +05:30
2017-07-13 15:49:37 +05:30
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