Skip to content

Commit

Permalink
fix: get default stock uom (#45384)
Browse files Browse the repository at this point in the history
Co-authored-by: Sagar Vora <[email protected]>
  • Loading branch information
barredterra and sagarvora authored Jan 23, 2025
1 parent d1329c2 commit d92f933
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_accounting_dimensions,
)
from erpnext.stock.utils import get_default_stock_uom


class OpeningInvoiceCreationTool(Document):
Expand Down Expand Up @@ -172,7 +173,7 @@ def get_item_dict():
income_expense_account_field = (
"income_account" if row.party_type == "Customer" else "expense_account"
)
default_uom = frappe.db.get_single_value("Stock Settings", "stock_uom") or "Nos"
default_uom = get_default_stock_uom()
rate = flt(row.outstanding_amount) / flt(row.qty)

item_dict = frappe._dict(
Expand Down
3 changes: 2 additions & 1 deletion erpnext/regional/italy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from erpnext.controllers.taxes_and_totals import ItemWiseTaxDetail, get_itemised_tax
from erpnext.regional.italy import state_codes
from erpnext.stock.utils import get_default_stock_uom


def update_itemised_tax_data(doc):
Expand Down Expand Up @@ -159,7 +160,7 @@ def get_invoice_summary(items, taxes):
rate=reference_row.tax_amount,
qty=1.0,
amount=reference_row.tax_amount,
stock_uom=frappe.db.get_single_value("Stock Settings", "stock_uom") or "Nos",
stock_uom=get_default_stock_uom(),
tax_rate=tax.rate,
tax_amount=(reference_row.tax_amount * tax.rate) / 100,
net_amount=reference_row.tax_amount,
Expand Down
23 changes: 23 additions & 0 deletions erpnext/stock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,26 @@ def get_combine_datetime(posting_date, posting_time):
posting_time = (datetime.datetime.min + posting_time).time()

return datetime.datetime.combine(posting_date, posting_time).replace(microsecond=0)


@frappe.request_cache
def get_default_stock_uom() -> str | None:
if default_uom := frappe.get_cached_value("Stock Settings", None, "stock_uom"):
return default_uom

acceptable_default_uoms = dict.fromkeys(
(
"Nos",
# In the past, we used to create translated UOMs during initial setup.
# These could either be in the system language...
_("Nos", frappe.get_system_settings("language")),
# or the current user's language
_("Nos"),
)
)

available_default_uoms = frappe.db.get_values(
"UOM", {"name": ("in", tuple(acceptable_default_uoms))}, pluck="name"
)

return next((uom for uom in acceptable_default_uoms if uom in available_default_uoms), None)

0 comments on commit d92f933

Please sign in to comment.