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.3.0 # [15.3.0](https://github.com/frappe/erpnext/compare/v15.2.0...v15.3.0) (2023-11-21) ### Bug Fixes * attributes were mandatory for manufacturers ([00b9c23](https://github.com/frappe/erpnext/commit/00b9c2326cfbabb6dd58c40f9af94043bbbaf788)) * issue occured when creating supplier with contact details ([aaccfeb](https://github.com/frappe/erpnext/commit/aaccfeb918d7427cc110626bc94a2eeb921be6a9)) * overallocation on Payment with PO/SO ([337707b](https://github.com/frappe/erpnext/commit/337707b9cc7e9b13fc1557588beb6f387c6905f3)) * pass check permission in render_address ([a420e13](https://github.com/frappe/erpnext/commit/a420e13765e0a92a62cadfbea07c59f70a6f16c1)) * payment entry rounding error ([384d6b5](https://github.com/frappe/erpnext/commit/384d6b516c152bb7e2f72d28a30752b6bd82eb71)) * set asset's valuation_rate according to asset quantity (backport [#38254](https://github.com/frappe/erpnext/issues/38254)) ([#38256](https://github.com/frappe/erpnext/issues/38256)) ([c60aaa7](https://github.com/frappe/erpnext/commit/c60aaa799acb7eebedc2f8e348d4cdcd9fcb9384)) * set default asset quantity as 1 [dev] (backport [#38223](https://github.com/frappe/erpnext/issues/38223)) ([#38226](https://github.com/frappe/erpnext/issues/38226)) ([99bf63e](https://github.com/frappe/erpnext/commit/99bf63ec0f856e8a74ef6ca915f581eb98583e58)) * Suppier name was not taken when creating address from supplier ([2b94489](https://github.com/frappe/erpnext/commit/2b9448962ff9195bd6ffd535cee0f010876558d3)) * Supplier Quotation fields ([#37963](https://github.com/frappe/erpnext/issues/37963)) ([aef955c](https://github.com/frappe/erpnext/commit/aef955c92040705e11a437419379b7e29633c339)) * test case for rounded total with cash disc ([eab18e6](https://github.com/frappe/erpnext/commit/eab18e6f710637d0eee63d1d41f2b75a4f4e0fa9)) * **Timesheet:** reset billing hours equal to hours if they exceed actual hours (backport [#38134](https://github.com/frappe/erpnext/issues/38134)) ([#38153](https://github.com/frappe/erpnext/issues/38153)) ([5b7b431](https://github.com/frappe/erpnext/commit/5b7b431dc97ef77fd888e8a233269219063428e6)) * **Timesheet:** warn user if billing hours > actual hours instead of resetting (backport [#38239](https://github.com/frappe/erpnext/issues/38239)) ([#38241](https://github.com/frappe/erpnext/issues/38241)) ([1f2f5d8](https://github.com/frappe/erpnext/commit/1f2f5d8cf6e3a1c8245af0fb95e6c0dccdbce2e8)) * TypeError in Subcontracting Receipt (backport [#38200](https://github.com/frappe/erpnext/issues/38200)) ([#38208](https://github.com/frappe/erpnext/issues/38208)) ([3f57a7e](https://github.com/frappe/erpnext/commit/3f57a7e9f06806a833fc9350a21c5d82fa525bac)) * update modified timestamp ([a492e57](https://github.com/frappe/erpnext/commit/a492e574def2661edb2a54cfbde8b231781a231e)) * **ux:** `Task` creation from `Timesheet` (backport [#38207](https://github.com/frappe/erpnext/issues/38207)) ([#38211](https://github.com/frappe/erpnext/issues/38211)) ([e272041](https://github.com/frappe/erpnext/commit/e2720418728da869c6cfc02aeca04b0e54fb0b46)) * valuation rate for FG item for subcontracting receipt (backport [#38244](https://github.com/frappe/erpnext/issues/38244)) ([#38245](https://github.com/frappe/erpnext/issues/38245)) ([ed7b845](https://github.com/frappe/erpnext/commit/ed7b845a5519087ef3aa6c9054451428b3cfa1a3)) * valuation rate in report Item Prices ([#38161](https://github.com/frappe/erpnext/issues/38161)) ([f71234e](https://github.com/frappe/erpnext/commit/f71234e3af77d66a34a6a6305c050ffe685b2bf4)) * wrong round off and rounded total ([70eccf7](https://github.com/frappe/erpnext/commit/70eccf7da0d52c3cfc21f8a5c892993b60de868e)) ### Features * add `Supplier Delivery Note` field in SCR (backport [#38127](https://github.com/frappe/erpnext/issues/38127)) ([#38156](https://github.com/frappe/erpnext/issues/38156)) ([b89a4a7](https://github.com/frappe/erpnext/commit/b89a4a7218338c48026abec660ac23184a9c6eaf)) * Add accounting dimensions to Supplier Quotation ([7d4ac7e](https://github.com/frappe/erpnext/commit/7d4ac7e7ffd92ed874d32e1f635311d245ec7fda))
2023-11-21 18:57:56 +00:00
__version__ = "15.3.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