fix: stock ledger report not showing data if the UOM filter has selected (#19179)
This commit is contained in:
parent
147af15268
commit
ed1cc18ab5
@ -107,7 +107,7 @@ def get_item_details(items, sl_entries, include_uom):
|
||||
if include_uom:
|
||||
cf_field = ", ucd.conversion_factor"
|
||||
cf_join = "left join `tabUOM Conversion Detail` ucd on ucd.parent=item.name and ucd.uom='%s'" \
|
||||
% frappe.db.escape(include_uom)
|
||||
% (include_uom)
|
||||
|
||||
res = frappe.db.sql("""
|
||||
select
|
||||
|
@ -253,31 +253,40 @@ def update_included_uom_in_report(columns, result, include_uom, conversion_facto
|
||||
return
|
||||
|
||||
convertible_cols = {}
|
||||
for col_idx in reversed(range(0, len(columns))):
|
||||
col = columns[col_idx]
|
||||
if isinstance(col, dict) and col.get("convertible") in ['rate', 'qty']:
|
||||
convertible_cols[col_idx] = col['convertible']
|
||||
columns.insert(col_idx+1, col.copy())
|
||||
columns[col_idx+1]['fieldname'] += "_alt"
|
||||
if convertible_cols[col_idx] == 'rate':
|
||||
columns[col_idx+1]['label'] += " (per {})".format(include_uom)
|
||||
else:
|
||||
columns[col_idx+1]['label'] += " ({})".format(include_uom)
|
||||
|
||||
is_dict_obj = False
|
||||
if isinstance(result[0], dict):
|
||||
is_dict_obj = True
|
||||
|
||||
convertible_columns = {}
|
||||
for idx, d in enumerate(columns):
|
||||
key = d.get("fieldname") if is_dict_obj else idx
|
||||
if d.get("convertible"):
|
||||
convertible_columns.setdefault(key, d.get("convertible"))
|
||||
|
||||
# Add new column to show qty/rate as per the selected UOM
|
||||
columns.insert(idx+1, {
|
||||
'label': "{0} (per {1})".format(d.get("label"), include_uom),
|
||||
'fieldname': "{0}_{1}".format(d.get("fieldname"), frappe.scrub(include_uom)),
|
||||
'fieldtype': 'Currency' if d.get("convertible") == 'rate' else 'Float'
|
||||
})
|
||||
|
||||
for row_idx, row in enumerate(result):
|
||||
new_row = []
|
||||
for col_idx, d in enumerate(row):
|
||||
new_row.append(d)
|
||||
if col_idx in convertible_cols:
|
||||
if conversion_factors[row_idx]:
|
||||
if convertible_cols[col_idx] == 'rate':
|
||||
new_row.append(flt(d) * conversion_factors[row_idx])
|
||||
else:
|
||||
new_row.append(flt(d) / conversion_factors[row_idx])
|
||||
else:
|
||||
new_row.append(None)
|
||||
data = row.items() if is_dict_obj else enumerate(row)
|
||||
for key, value in data:
|
||||
if not key in convertible_columns or not conversion_factors[row_idx]:
|
||||
continue
|
||||
|
||||
result[row_idx] = new_row
|
||||
if convertible_columns.get(key) == 'rate':
|
||||
new_value = flt(value) * conversion_factors[row_idx]
|
||||
else:
|
||||
new_value = flt(value) / conversion_factors[row_idx]
|
||||
|
||||
if not is_dict_obj:
|
||||
row.insert(key+1, new_value)
|
||||
else:
|
||||
new_key = "{0}_{1}".format(key, frappe.scrub(include_uom))
|
||||
row[new_key] = new_value
|
||||
|
||||
def get_available_serial_nos(item_code, warehouse):
|
||||
return frappe.get_all("Serial No", filters = {'item_code': item_code,
|
||||
|
Loading…
Reference in New Issue
Block a user