Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: serial no filter in the Serial No Ledger report #38669

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions erpnext/stock/report/serial_no_ledger/serial_no_ledger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

import copy

import frappe
from frappe import _

from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos as get_serial_nos_from_sle
from erpnext.stock.stock_ledger import get_stock_ledger_entries


Expand All @@ -15,8 +18,8 @@ def execute(filters=None):

def get_columns(filters):
columns = [
{"label": _("Posting Date"), "fieldtype": "Date", "fieldname": "posting_date"},
{"label": _("Posting Time"), "fieldtype": "Time", "fieldname": "posting_time"},
{"label": _("Posting Date"), "fieldtype": "Date", "fieldname": "posting_date", "width": 120},
{"label": _("Posting Time"), "fieldtype": "Time", "fieldname": "posting_time", "width": 90},
{
"label": _("Voucher Type"),
"fieldtype": "Link",
Expand All @@ -29,7 +32,7 @@ def get_columns(filters):
"fieldtype": "Dynamic Link",
"fieldname": "voucher_no",
"options": "voucher_type",
"width": 180,
"width": 230,
},
{
"label": _("Company"),
Expand All @@ -49,7 +52,7 @@ def get_columns(filters):
"label": _("Status"),
"fieldtype": "Data",
"fieldname": "status",
"width": 120,
"width": 90,
},
{
"label": _("Serial No"),
Expand All @@ -62,7 +65,7 @@ def get_columns(filters):
"label": _("Valuation Rate"),
"fieldtype": "Float",
"fieldname": "valuation_rate",
"width": 150,
"width": 130,
},
{
"label": _("Qty"),
Expand Down Expand Up @@ -102,15 +105,29 @@ def get_data(filters):
}
)

serial_nos = [{"serial_no": row.serial_no, "valuation_rate": row.valuation_rate}]
serial_nos = []
if row.serial_no:
parsed_serial_nos = get_serial_nos_from_sle(row.serial_no)
for serial_no in parsed_serial_nos:
if filters.get("serial_no") and filters.get("serial_no") != serial_no:
continue

serial_nos.append(
{
"serial_no": serial_no,
"valuation_rate": abs(row.stock_value_difference / row.actual_qty),
}
)

if row.serial_and_batch_bundle:
serial_nos = bundle_wise_serial_nos.get(row.serial_and_batch_bundle, [])
serial_nos.extend(bundle_wise_serial_nos.get(row.serial_and_batch_bundle, []))

for index, bundle_data in enumerate(serial_nos):
if index == 0:
args.serial_no = bundle_data.get("serial_no")
args.valuation_rate = bundle_data.get("valuation_rate")
data.append(args)
new_args = copy.deepcopy(args)
new_args.serial_no = bundle_data.get("serial_no")
new_args.valuation_rate = bundle_data.get("valuation_rate")
data.append(new_args)
else:
data.append(
{
Expand Down