mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-17 08:35:00 +00:00
Merge pull request #40735 from rohitwaghchaure/fixed-stock-balance-report
fix: Show Stock Ageing Data filter not working in stock balance report
This commit is contained in:
@@ -415,7 +415,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
let row = locals[cdt][cdn];
|
||||
if (row.barcode) {
|
||||
erpnext.stock.utils.set_item_details_using_barcode(this.frm, row, (r) => {
|
||||
debugger
|
||||
frappe.model.set_value(cdt, cdn, {
|
||||
"item_code": r.message.item_code,
|
||||
"qty": 1,
|
||||
|
||||
@@ -229,8 +229,16 @@ class FIFOSlots:
|
||||
}
|
||||
"""
|
||||
|
||||
from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle import (
|
||||
get_serial_nos_from_bundle,
|
||||
)
|
||||
|
||||
stock_ledger_entries = self.sle
|
||||
|
||||
bundle_wise_serial_nos = frappe._dict({})
|
||||
if stock_ledger_entries is None:
|
||||
bundle_wise_serial_nos = self.__get_bundle_wise_serial_nos()
|
||||
|
||||
with frappe.db.unbuffered_cursor():
|
||||
if stock_ledger_entries is None:
|
||||
stock_ledger_entries = self.__get_stock_ledger_entries()
|
||||
@@ -244,6 +252,11 @@ class FIFOSlots:
|
||||
d.actual_qty = flt(d.qty_after_transaction) - flt(prev_balance_qty)
|
||||
|
||||
serial_nos = get_serial_nos(d.serial_no) if d.serial_no else []
|
||||
if d.serial_and_batch_bundle and d.has_serial_no:
|
||||
if bundle_wise_serial_nos:
|
||||
serial_nos = bundle_wise_serial_nos.get(d.serial_and_batch_bundle) or []
|
||||
else:
|
||||
serial_nos = get_serial_nos_from_bundle(d.serial_and_batch_bundle) or []
|
||||
|
||||
if d.actual_qty > 0:
|
||||
self.__compute_incoming_stock(d, fifo_queue, transferred_item_key, serial_nos)
|
||||
@@ -408,6 +421,7 @@ class FIFOSlots:
|
||||
sle.serial_no,
|
||||
sle.batch_no,
|
||||
sle.qty_after_transaction,
|
||||
sle.serial_and_batch_bundle,
|
||||
sle.warehouse,
|
||||
)
|
||||
.where(
|
||||
@@ -425,6 +439,33 @@ class FIFOSlots:
|
||||
|
||||
return sle_query.run(as_dict=True, as_iterator=True)
|
||||
|
||||
def __get_bundle_wise_serial_nos(self) -> dict:
|
||||
bundle = frappe.qb.DocType("Serial and Batch Bundle")
|
||||
entry = frappe.qb.DocType("Serial and Batch Entry")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(bundle)
|
||||
.join(entry)
|
||||
.on(bundle.name == entry.parent)
|
||||
.select(bundle.name, entry.serial_no)
|
||||
.where(
|
||||
(bundle.docstatus == 1)
|
||||
& (entry.serial_no.isnotnull())
|
||||
& (bundle.company == self.filters.get("company"))
|
||||
& (bundle.posting_date <= self.filters.get("to_date"))
|
||||
)
|
||||
)
|
||||
|
||||
for field in ["item_code", "warehouse"]:
|
||||
if self.filters.get(field):
|
||||
query = query.where(bundle[field] == self.filters.get(field))
|
||||
|
||||
bundle_wise_serial_nos = frappe._dict({})
|
||||
for bundle_name, serial_no in query.run():
|
||||
bundle_wise_serial_nos.setdefault(bundle_name, []).append(serial_no)
|
||||
|
||||
return bundle_wise_serial_nos
|
||||
|
||||
def __get_item_query(self) -> str:
|
||||
item_table = frappe.qb.DocType("Item")
|
||||
|
||||
|
||||
@@ -294,6 +294,8 @@ class StockBalanceReport:
|
||||
sle.stock_value,
|
||||
sle.batch_no,
|
||||
sle.serial_no,
|
||||
sle.serial_and_batch_bundle,
|
||||
sle.has_serial_no,
|
||||
item_table.item_group,
|
||||
item_table.stock_uom,
|
||||
item_table.item_name,
|
||||
|
||||
Reference in New Issue
Block a user