Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilshanavs committed Oct 16, 2023
1 parent ef08feb commit ad0a4dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
34 changes: 12 additions & 22 deletions erpnext/stock/report/stock_ledger/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
def execute(filters=None):
is_reposting_item_valuation_in_progress()
if filters.get("include_uom") and filters.get("type") != "Default UOM":
frappe.throw(str("Cannot select filters <b> Include UOM </b> and <b>Select UOM</b> together!"))
frappe.throw(
_(
f"Cannot select filters {frappe.bold ('Include UOM')} and {frappe.bold('Select UOM')} together!"
)
)
include_uom = filters.get("include_uom")
if filters.get("type") == "Purchase UOM":
type = "Purchase UOM"
elif filters.get("type") == "Sales UOM":
type = "Sales UOM"
else:
type = ""
columns = get_columns(filters)
items = get_items(filters)
sl_entries = get_stock_ledger_entries(filters, items)
item_details = get_item_details(items, sl_entries, include_uom, type)
item_details = get_item_details(items, sl_entries, include_uom, filters)
opening_row = get_opening_balance(filters, columns, sl_entries)
precision = cint(frappe.db.get_single_value("System Settings", "float_precision"))

Expand Down Expand Up @@ -361,7 +359,7 @@ def get_items(filters):
return items


def get_item_details(items, sl_entries, include_uom, type):
def get_item_details(items, sl_entries, include_uom, filters):
item_details = {}
if not items:
items = list(set(d.item_code for d in sl_entries))
Expand All @@ -370,34 +368,26 @@ def get_item_details(items, sl_entries, include_uom, type):
return item_details

item = frappe.qb.DocType("Item")
ucd = frappe.qb.DocType("UOM Conversion Detail")
query = (
frappe.qb.from_(item)
.select(item.name, item.item_name, item.description, item.item_group, item.brand, item.stock_uom)
.select(ucd.conversion_factor)
.where(item.name.isin(items))
)

ucd = frappe.qb.DocType("UOM Conversion Detail")
if include_uom:
query = (
query.left_join(ucd)
.on((ucd.parent == item.name) & (ucd.uom == include_uom))
.select(ucd.conversion_factor)
)
if type == "Sales UOM":
query = query.left_join(ucd).on((ucd.parent == item.name) & (ucd.uom == include_uom))
if filters.get("type") == "Sales UOM":
query = (
query.left_join(ucd)
.on((ucd.parent == item.name) & (ucd.uom == item.sales_uom))
.select(ucd.conversion_factor)
.as_("sales_uom_con")
.select(ucd.uom)
.as_("sales_uom")
)
elif type == "Purchase UOM":
elif filters.get("type") == "Purchase UOM":
query = (
query.left_join(ucd)
.on((ucd.parent == item.name) & (ucd.uom == item.purchase_uom))
.select(ucd.conversion_factor)
.as_("purchase_uom_con")
.select(ucd.uom)
.as_("purchase_uom")
)
Expand Down
4 changes: 3 additions & 1 deletion erpnext/stock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ def update_included_uom_in_report(
else:
new_value = flt(value) / conversion_factors[row_idx]
if type_conversion_factors:
new_value = flt(value) / (type_conversion_factors[0][0] if type_conversion_factors[0][0] else 1)
new_value = flt(value) / (
type_conversion_factors[0][0] if type_conversion_factors[0][0] else 1
)
if not is_dict_obj:
row.insert(key + 1, new_value)
elif include_uom:
Expand Down

0 comments on commit ad0a4dc

Please sign in to comment.