mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-17 01:07:19 +00:00
fix: show incorrect entries filter in Stock Ledger Invariant Check report (backport #43619) (#43622)
fix: show incorrect entries filter in Stock Ledger Invariant Check report (#43619)
fix: show incorrect entry filter in Stock Ledger Invariant Check report
(cherry picked from commit 8beee1982f)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -32,6 +32,12 @@ frappe.query_reports["Stock Ledger Invariant Check"] = {
|
|||||||
mandatory: 1,
|
mandatory: 1,
|
||||||
options: "Warehouse",
|
options: "Warehouse",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
fieldname: "show_incorrect_entries",
|
||||||
|
fieldtype: "Check",
|
||||||
|
label: "Show Incorrect Entries",
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
formatter(value, row, column, data, default_formatter) {
|
formatter(value, row, column, data, default_formatter) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import json
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import get_link_to_form, parse_json
|
from frappe.utils import cint, flt, get_link_to_form, parse_json
|
||||||
|
|
||||||
SLE_FIELDS = (
|
SLE_FIELDS = (
|
||||||
"name",
|
"name",
|
||||||
@@ -36,7 +36,7 @@ def execute(filters=None):
|
|||||||
|
|
||||||
def get_data(filters):
|
def get_data(filters):
|
||||||
sles = get_stock_ledger_entries(filters)
|
sles = get_stock_ledger_entries(filters)
|
||||||
return add_invariant_check_fields(sles)
|
return add_invariant_check_fields(sles, filters)
|
||||||
|
|
||||||
|
|
||||||
def get_stock_ledger_entries(filters):
|
def get_stock_ledger_entries(filters):
|
||||||
@@ -48,9 +48,12 @@ def get_stock_ledger_entries(filters):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_invariant_check_fields(sles):
|
def add_invariant_check_fields(sles, filters):
|
||||||
balance_qty = 0.0
|
balance_qty = 0.0
|
||||||
balance_stock_value = 0.0
|
balance_stock_value = 0.0
|
||||||
|
|
||||||
|
incorrect_idx = 0
|
||||||
|
precision = frappe.get_precision("Stock Ledger Entry", "actual_qty")
|
||||||
for idx, sle in enumerate(sles):
|
for idx, sle in enumerate(sles):
|
||||||
queue = json.loads(sle.stock_queue) if sle.stock_queue else []
|
queue = json.loads(sle.stock_queue) if sle.stock_queue else []
|
||||||
|
|
||||||
@@ -95,6 +98,12 @@ def add_invariant_check_fields(sles):
|
|||||||
)
|
)
|
||||||
sle.diff_value_diff = sle.stock_value_from_diff - sle.stock_value
|
sle.diff_value_diff = sle.stock_value_from_diff - sle.stock_value
|
||||||
|
|
||||||
|
if not incorrect_idx and filters.get("show_incorrect_entries"):
|
||||||
|
if is_sle_has_correct_data(sle, precision):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
incorrect_idx = idx
|
||||||
|
|
||||||
if idx > 0:
|
if idx > 0:
|
||||||
sle.fifo_stock_diff = sle.fifo_stock_value - sles[idx - 1].fifo_stock_value
|
sle.fifo_stock_diff = sle.fifo_stock_value - sles[idx - 1].fifo_stock_value
|
||||||
sle.fifo_difference_diff = sle.fifo_stock_diff - sle.stock_value_difference
|
sle.fifo_difference_diff = sle.fifo_stock_diff - sle.stock_value_difference
|
||||||
@@ -104,9 +113,23 @@ def add_invariant_check_fields(sles):
|
|||||||
"Batch", sle.batch_no, "use_batchwise_valuation", cache=True
|
"Batch", sle.batch_no, "use_batchwise_valuation", cache=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if filters.get("show_incorrect_entries"):
|
||||||
|
if incorrect_idx > 0:
|
||||||
|
sles = sles[cint(incorrect_idx) - 1 :]
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
return sles
|
return sles
|
||||||
|
|
||||||
|
|
||||||
|
def is_sle_has_correct_data(sle, precision):
|
||||||
|
if flt(sle.difference_in_qty, precision) != 0.0 or flt(sle.diff_value_diff, precision) != 0:
|
||||||
|
print(flt(sle.difference_in_qty, precision), flt(sle.diff_value_diff, precision))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user