mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-13 11:55:11 +00:00
fix: old stock reco entries causing issue in the stock balance report
(cherry picked from commit 0874cbc268)
This commit is contained in:
committed by
Mergify
parent
41ff3191f5
commit
ea5ad3179c
@@ -8,7 +8,7 @@ from typing import Any, TypedDict
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.query_builder.functions import Coalesce
|
from frappe.query_builder.functions import Coalesce, Count
|
||||||
from frappe.utils import add_days, cint, date_diff, flt, getdate
|
from frappe.utils import add_days, cint, date_diff, flt, getdate
|
||||||
from frappe.utils.nestedset import get_descendants_of
|
from frappe.utils.nestedset import get_descendants_of
|
||||||
|
|
||||||
@@ -165,6 +165,7 @@ class StockBalanceReport:
|
|||||||
sle.serial_no,
|
sle.serial_no,
|
||||||
sle.serial_and_batch_bundle,
|
sle.serial_and_batch_bundle,
|
||||||
sle.has_serial_no,
|
sle.has_serial_no,
|
||||||
|
sle.voucher_detail_no,
|
||||||
item_table.item_group,
|
item_table.item_group,
|
||||||
item_table.stock_uom,
|
item_table.stock_uom,
|
||||||
item_table.item_name,
|
item_table.item_name,
|
||||||
@@ -190,6 +191,8 @@ class StockBalanceReport:
|
|||||||
if self.filters.get("show_stock_ageing_data"):
|
if self.filters.get("show_stock_ageing_data"):
|
||||||
self.sle_entries = self.sle_query.run(as_dict=True)
|
self.sle_entries = self.sle_query.run(as_dict=True)
|
||||||
|
|
||||||
|
self.prepare_stock_reco_voucher_wise_count()
|
||||||
|
|
||||||
# HACK: This is required to avoid causing db query in flt
|
# HACK: This is required to avoid causing db query in flt
|
||||||
_system_settings = frappe.get_cached_doc("System Settings")
|
_system_settings = frappe.get_cached_doc("System Settings")
|
||||||
with frappe.db.unbuffered_cursor():
|
with frappe.db.unbuffered_cursor():
|
||||||
@@ -207,6 +210,30 @@ class StockBalanceReport:
|
|||||||
self.item_warehouse_map, self.float_precision, self.inventory_dimensions
|
self.item_warehouse_map, self.float_precision, self.inventory_dimensions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def prepare_stock_reco_voucher_wise_count(self):
|
||||||
|
self.stock_reco_voucher_wise_count = frappe._dict()
|
||||||
|
|
||||||
|
doctype = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
|
item = frappe.qb.DocType("Item")
|
||||||
|
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(doctype)
|
||||||
|
.inner_join(item)
|
||||||
|
.on(doctype.item_code == item.name)
|
||||||
|
.select(doctype.voucher_detail_no, Count(doctype.name).as_("count"))
|
||||||
|
.where(
|
||||||
|
(doctype.voucher_type == "Stock Reconciliation")
|
||||||
|
& (doctype.docstatus < 2)
|
||||||
|
& (doctype.is_cancelled == 0)
|
||||||
|
& (item.has_serial_no == 1)
|
||||||
|
)
|
||||||
|
.groupby(doctype.voucher_detail_no)
|
||||||
|
)
|
||||||
|
|
||||||
|
data = query.run(as_list=True)
|
||||||
|
if data:
|
||||||
|
self.stock_reco_voucher_wise_count = frappe._dict(data)
|
||||||
|
|
||||||
def prepare_new_data(self):
|
def prepare_new_data(self):
|
||||||
if self.filters.get("show_stock_ageing_data"):
|
if self.filters.get("show_stock_ageing_data"):
|
||||||
self.filters["show_warehouse_wise_stock"] = True
|
self.filters["show_warehouse_wise_stock"] = True
|
||||||
@@ -283,9 +310,13 @@ class StockBalanceReport:
|
|||||||
qty_dict[field] = entry.get(field)
|
qty_dict[field] = entry.get(field)
|
||||||
|
|
||||||
if entry.voucher_type == "Stock Reconciliation" and (
|
if entry.voucher_type == "Stock Reconciliation" and (
|
||||||
not entry.batch_no and not entry.serial_no and not entry.serial_and_batch_bundle
|
not entry.batch_no or entry.serial_no or entry.serial_and_batch_bundle
|
||||||
):
|
):
|
||||||
qty_diff = flt(entry.qty_after_transaction) - flt(qty_dict.bal_qty)
|
if entry.serial_no and self.stock_reco_voucher_wise_count.get(entry.voucher_detail_no, 0) == 1:
|
||||||
|
qty_dict.bal_qty = 0.0
|
||||||
|
qty_diff = flt(entry.actual_qty)
|
||||||
|
else:
|
||||||
|
qty_diff = flt(entry.qty_after_transaction) - flt(qty_dict.bal_qty)
|
||||||
else:
|
else:
|
||||||
qty_diff = flt(entry.actual_qty)
|
qty_diff = flt(entry.actual_qty)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ frappe.query_reports["Stock Ledger Invariant Check"] = {
|
|||||||
options: "Item",
|
options: "Item",
|
||||||
get_query: function () {
|
get_query: function () {
|
||||||
return {
|
return {
|
||||||
filters: { is_stock_item: 1, has_serial_no: 0 },
|
filters: { is_stock_item: 1 },
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user