mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 05:29:18 +00:00
# [15.51.0](https://github.com/frappe/erpnext/compare/v15.50.1...v15.51.0) (2025-02-05) ### Bug Fixes * actual qty showing blank for sub-assembly items ([d0748b1](d0748b1b67)) * added correct options for incoming_rate field of delivery note item ([cfc5007](cfc50073ed)) * allow multiple email ids ([2a25302](2a25302c35)) * attribute 'msgbox' not found in sales invoice.js ([f6b4984](f6b49845e2)) * bind this to function ([c0b32c4](c0b32c446b)) * check billing address ([44d9fb7](44d9fb7a69)) * closing stock balance report not generating ([47d1c3b](47d1c3b5a3)) * conflicts ([4aa072a](4aa072a8eb)) * consider process_loss_qty in work order ([1522d76](1522d76a3b)) * copy correct uom from devliery note when creating packing list ([f9794e5](f9794e5b44)) * correct error message in payment entry ([6ea5307](6ea5307b0e)) * default payment terms template selected while duplicating ([ca4bb96](ca4bb96fb4)) * Do not check for cancelled invoices ([84638f5](84638f58fd)) * Do not check for cancelled invoices ([b612ab5](b612ab5823)) * fetch rate from item price list when document is saved ([b140ce7](b140ce71d7)) * filter the item tax template using the input text ([8ea9a9e](8ea9a9e467)) * Gross Profit Report with Correct Totals and Gross Margin (backport [#45548](https://github.com/frappe/erpnext/issues/45548)) ([#45598](https://github.com/frappe/erpnext/issues/45598)) ([6301b32](6301b321d8)) * handling company in bank reconciliation tool ([#45582](https://github.com/frappe/erpnext/issues/45582)) ([aa27e19](aa27e19a58)) * ignore expired batch for pick list ([786db3d](786db3d0fa)) * loading print receipt only at order complete (backport [#45627](https://github.com/frappe/erpnext/issues/45627)) ([#45628](https://github.com/frappe/erpnext/issues/45628)) ([72868ee](72868eee04)) * logical error failing tests ([6a03f99](6a03f99546)) * not able to make manufacturing entry for alternate items ([eef2f3c](eef2f3c5d4)) * only system manager was able to create customer & prospect ([6149306](6149306b78)) * payment schedule table is empty while duplicating record ([c523625](c52362531c)) * point of sale padding (backport [#45697](https://github.com/frappe/erpnext/issues/45697)) ([#45699](https://github.com/frappe/erpnext/issues/45699)) ([b915e7f](b915e7f637)) * pos payment cash shortcut decimal (backport [#45702](https://github.com/frappe/erpnext/issues/45702)) ([#45705](https://github.com/frappe/erpnext/issues/45705)) ([6113cc1](6113cc1e43)) * pos print receipt on submit (backport [#45632](https://github.com/frappe/erpnext/issues/45632)) ([#45633](https://github.com/frappe/erpnext/issues/45633)) ([676dde5](676dde59c2)) * **pos:** add item in the existing item row when discount is applied ([0b54cb9](0b54cb9a7c)) * posting_date to posting_datetime in stock related queries ([cd5174e](cd5174e423)) * remove tds account in taxes table on change of Tax Withholding Category ([1ad16c3](1ad16c368e)) * removed unused field ([9a27d3c](9a27d3cedc)) * renamed Commments Tab to Notes tab in Lead doctype ([86edcfc](86edcfc1fd)) * reposting issue with s3 backup ([73c1bf9](73c1bf972e)) * resolved conflicts ([223fe62](223fe62638)) * respect user set account if not advance account for getting outstanding invoices in payment entry ([8108d7f](8108d7fdba)) * semgrep ([401fd7f](401fd7fca7)) * set asset value correctly after cancelling value adjustment ([7f7f403](7f7f403f5b)) * show only items with inspection enabled on create QI dialog ([34f8a37](34f8a370d1)) * slow SABB query ([7931c2d](7931c2d182)) * subcontracting valiation precision issue ([5319683](5319683dbf)) * track employee changes ([#45674](https://github.com/frappe/erpnext/issues/45674)) ([cf98ebf](cf98ebf7fe)) * validation message ([4742211](47422111b4)) * validation to prevent submission if the SABB is not linked to a stock transaction ([24a6f61](24a6f611d8)) ### Features * account heads changed along with journal entry type and descrip… ([#42845](https://github.com/frappe/erpnext/issues/42845)) ([bbecd36](bbecd36a5d)) * report to find incorrect SABB ([a948f2e](a948f2e095)) * set bank account of company to default company bank account from masters ([b840271](b840271d2a)) ### Performance Improvements * stock entry with batch (backport [#45486](https://github.com/frappe/erpnext/issues/45486)) ([#45602](https://github.com/frappe/erpnext/issues/45602)) ([8b75401](8b75401db9))
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.51.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("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
|