fix: Show Stock Ageing Data filter not working in stock balance report

(cherry picked from commit 621421bda2)

# Conflicts:
#	erpnext/stock/report/stock_ageing/stock_ageing.py
This commit is contained in:
Rohit Waghchaure
2024-03-28 12:24:09 +05:30
committed by Mergify
parent d12f89cdb2
commit 2185a29555
3 changed files with 65 additions and 1 deletions

View File

@@ -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,

View File

@@ -234,6 +234,7 @@ class FIFOSlots:
if self.sle is None:
self.sle = self.__get_stock_ledger_entries()
<<<<<<< HEAD
for d in self.sle:
key, fifo_queue, transferred_item_key = self.__init_key_stores(d)
@@ -241,6 +242,21 @@ class FIFOSlots:
# get difference in qty shift as actual qty
prev_balance_qty = self.item_details[key].get("qty_after_transaction", 0)
d.actual_qty = flt(d.qty_after_transaction) - flt(prev_balance_qty)
=======
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()
>>>>>>> 621421bda2 (fix: Show Stock Ageing Data filter not working in stock balance report)
serial_nos = get_serial_nos(d.serial_no) if d.serial_no else []
@@ -249,7 +265,26 @@ class FIFOSlots:
else:
self.__compute_outgoing_stock(d, fifo_queue, transferred_item_key, serial_nos)
<<<<<<< HEAD
self.__update_balances(d, key)
=======
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)
else:
self.__compute_outgoing_stock(d, fifo_queue, transferred_item_key, serial_nos)
self.__update_balances(d, key)
# Note that stock_ledger_entries is an iterator, you can not reuse it like a list
del stock_ledger_entries
>>>>>>> 621421bda2 (fix: Show Stock Ageing Data filter not working in stock balance report)
if not self.filters.get("show_warehouse_wise_stock"):
# (Item 1, WH 1), (Item 1, WH 2) => (Item 1)
@@ -403,6 +438,7 @@ class FIFOSlots:
sle.serial_no,
sle.batch_no,
sle.qty_after_transaction,
sle.serial_and_batch_bundle,
sle.warehouse,
)
.where(
@@ -420,6 +456,33 @@ class FIFOSlots:
return sle_query.run(as_dict=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")

View File

@@ -295,6 +295,8 @@ class StockBalanceReport(object):
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,