mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-27 02:28:30 +00:00
fix: negative batch report showing same batch-warehouse multiple times
(cherry picked from commit 700572980d)
This commit is contained in:
committed by
Mergify
parent
d9d8fc6912
commit
3229fce9a5
@@ -90,45 +90,62 @@ def get_data(filters) -> list[dict]:
|
|||||||
batch_negative_data = []
|
batch_negative_data = []
|
||||||
|
|
||||||
flt_precision = frappe.db.get_default("float_precision") or 2
|
flt_precision = frappe.db.get_default("float_precision") or 2
|
||||||
|
distinct_batches = set()
|
||||||
for company in companies:
|
for company in companies:
|
||||||
for batch in batches:
|
warehouses = get_warehouses(filters, company)
|
||||||
_c, data = stock_ledger_execute(
|
for warehouse in warehouses:
|
||||||
frappe._dict(
|
for batch in batches:
|
||||||
{
|
_c, data = stock_ledger_execute(
|
||||||
"company": company,
|
frappe._dict(
|
||||||
"batch_no": batch,
|
|
||||||
"from_date": add_to_date(today(), years=-12),
|
|
||||||
"to_date": today(),
|
|
||||||
"segregate_serial_batch_bundle": 1,
|
|
||||||
"warehouse": filters.get("warehouse"),
|
|
||||||
"valuation_field_type": "Currency",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
previous_qty = 0
|
|
||||||
for row in data:
|
|
||||||
if flt(row.get("qty_after_transaction"), flt_precision) < 0:
|
|
||||||
batch_negative_data.append(
|
|
||||||
{
|
{
|
||||||
"posting_date": row.get("date"),
|
"company": company,
|
||||||
"batch_no": row.get("batch_no"),
|
"batch_no": batch,
|
||||||
"item_code": row.get("item_code"),
|
"from_date": add_to_date(today(), years=-12),
|
||||||
"item_name": row.get("item_name"),
|
"to_date": today(),
|
||||||
"warehouse": row.get("warehouse"),
|
"segregate_serial_batch_bundle": 1,
|
||||||
"actual_qty": row.get("actual_qty"),
|
"warehouse": warehouse,
|
||||||
"qty_after_transaction": row.get("qty_after_transaction"),
|
"valuation_field_type": "Currency",
|
||||||
"previous_qty": previous_qty,
|
|
||||||
"voucher_type": row.get("voucher_type"),
|
|
||||||
"voucher_no": row.get("voucher_no"),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
previous_qty = row.get("qty_after_transaction")
|
previous_qty = 0
|
||||||
|
for row in data:
|
||||||
|
key = (row.get("warehouse"), batch)
|
||||||
|
if key in distinct_batches:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if flt(row.get("qty_after_transaction"), flt_precision) < 0:
|
||||||
|
batch_negative_data.append(
|
||||||
|
{
|
||||||
|
"posting_date": row.get("date"),
|
||||||
|
"batch_no": row.get("batch_no"),
|
||||||
|
"item_code": row.get("item_code"),
|
||||||
|
"item_name": row.get("item_name"),
|
||||||
|
"warehouse": row.get("warehouse"),
|
||||||
|
"actual_qty": row.get("actual_qty"),
|
||||||
|
"qty_after_transaction": row.get("qty_after_transaction"),
|
||||||
|
"previous_qty": previous_qty,
|
||||||
|
"voucher_type": row.get("voucher_type"),
|
||||||
|
"voucher_no": row.get("voucher_no"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
distinct_batches.add(key)
|
||||||
|
|
||||||
|
previous_qty = row.get("qty_after_transaction")
|
||||||
|
|
||||||
return batch_negative_data
|
return batch_negative_data
|
||||||
|
|
||||||
|
|
||||||
|
def get_warehouses(filters, company):
|
||||||
|
warehouse_filters = {"company": company, "disabled": 0}
|
||||||
|
if filters.get("warehouse"):
|
||||||
|
warehouse_filters["name"] = filters["warehouse"]
|
||||||
|
|
||||||
|
return frappe.get_all("Warehouse", pluck="name", filters=warehouse_filters)
|
||||||
|
|
||||||
|
|
||||||
def get_batches(filters):
|
def get_batches(filters):
|
||||||
batch_filters = {}
|
batch_filters = {}
|
||||||
if filters.get("item_code"):
|
if filters.get("item_code"):
|
||||||
|
|||||||
Reference in New Issue
Block a user