Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilshanavs committed Dec 15, 2023
1 parent 39b958e commit 5c4213f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
13 changes: 6 additions & 7 deletions erpnext/stock/report/stock_ledger/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def execute(filters=None):

data = []
conversion_factors = []
type_conversion_factors = []
transaction_cf = []
if opening_row:
data.append(opening_row)
conversion_factors.append(0)
transaction_cf.append(0)

actual_qty = stock_value = 0
if opening_row:
Expand Down Expand Up @@ -77,13 +78,11 @@ def execute(filters=None):

if include_uom:
conversion_factors.append(item_detail.conversion_factor)
if filters.get("select_uom") in ["Sales UOM", "Purchase UOM"]:
conversion_factors.append(item_detail.conversion_factor)
type_conversion_factors.append(
(conversion_factors, item_detail.conversion_factor, item_detail.uom, filters.get("select_uom"))
)
else:
transaction_cf.append(item_detail.conversion_factor)

update_included_uom_in_report(
columns, data, include_uom, conversion_factors, type_conversion_factors
columns, data, include_uom, conversion_factors, transaction_cf, filters.get("select_uom")
)
return columns, data

Expand Down
29 changes: 15 additions & 14 deletions erpnext/stock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,13 @@ def validate_disabled_warehouse(warehouse):


def update_included_uom_in_report(
columns, result, include_uom, conversion_factors, type_conversion_factors
columns, result, include_uom, conversion_factors, transaction_cf=None, transaction_uom="Stock UOM"
):
if not include_uom and not conversion_factors and not type_conversion_factors:
if (not include_uom and not conversion_factors) and (
not transaction_cf or transaction_uom == "Stock UOM"
):
return

is_dict_obj = False
if isinstance(result[0], dict):
is_dict_obj = True
Expand All @@ -434,14 +437,12 @@ def update_included_uom_in_report(
"fieldtype": "Currency" if d.get("convertible") == "rate" else "Float",
},
)
elif type_conversion_factors:
elif transaction_cf:
columns.insert(
idx + 1,
{
"label": "{0} ({1})".format(d.get("label"), type_conversion_factors[0][3]),
"fieldname": "{0}_{1}_qty".format(
d.get("fieldname"), frappe.scrub(type_conversion_factors[0][3])
),
"label": "{0} ({1})".format(d.get("label"), transaction_uom),
"fieldname": "{0}_{1}_qty".format(d.get("fieldname"), frappe.scrub(transaction_uom)),
"fieldtype": "Currency" if d.get("convertible") == "rate" else "Float",
"width": 120,
},
Expand All @@ -460,26 +461,26 @@ def update_included_uom_in_report(
if key not in convertible_columns:
continue
# If no conversion factor for the UOM, defaults to 1
if conversion_factors:
if include_uom and conversion_factors:
if not conversion_factors[row_idx]:
conversion_factors[row_idx] = 1

if convertible_columns.get(key) == "rate":
new_value = flt(value) * conversion_factors[row_idx]
else:
new_value = flt(value) / conversion_factors[row_idx]
if type_conversion_factors:
new_value = flt(value) / (
type_conversion_factors[0][0][row_idx] if type_conversion_factors[0][0][row_idx] else 1
)
else:
new_value = flt(value) / (transaction_cf[row_idx] if transaction_cf[row_idx] else 1)

if not is_dict_obj:
row.insert(key + 1, new_value)
elif include_uom:
new_key = "{0}_{1}".format(key, frappe.scrub(include_uom))
update_dict_values.append([row, new_key, new_value])
else:
new_key1 = "{0}_{1}_qty".format(key, frappe.scrub(type_conversion_factors[0][3]))
elif transaction_uom:
new_key1 = "{0}_{1}_qty".format(key, frappe.scrub(transaction_uom))
type_update_dict_values.append([row, new_key1, new_value])

if include_uom:
for data in update_dict_values:
row, key, value = data
Expand Down

0 comments on commit 5c4213f

Please sign in to comment.