mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 09:43:49 +00:00
fix: update batch_qty using get_batch_qty
(cherry picked from commit 15d9d8b719)
This commit is contained in:
committed by
Mergify
parent
10b0da8bc8
commit
ca835c831b
@@ -38,7 +38,7 @@ frappe.query_reports["Stock Qty vs Batch Qty"] = {
|
||||
frappe.call({
|
||||
method: "erpnext.stock.report.stock_qty_vs_batch_qty.stock_qty_vs_batch_qty.update_batch_qty",
|
||||
args: {
|
||||
batches: selected_rows,
|
||||
selected_batches: selected_rows,
|
||||
},
|
||||
callback: function (r) {
|
||||
if (!r.exc) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"idx": 0,
|
||||
"is_standard": "Yes",
|
||||
"letterhead": null,
|
||||
"modified": "2025-10-07 20:03:45.952352",
|
||||
"modified": "2025-11-18 11:35:04.615085",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Stock Qty vs Batch Qty",
|
||||
@@ -21,10 +21,7 @@
|
||||
"report_type": "Script Report",
|
||||
"roles": [
|
||||
{
|
||||
"role": "Stock Manager"
|
||||
},
|
||||
{
|
||||
"role": "Stock User"
|
||||
"role": "Item Manager"
|
||||
}
|
||||
],
|
||||
"timeout": 0
|
||||
|
||||
@@ -44,7 +44,12 @@ def get_data(filters=None):
|
||||
item = filters.get("item")
|
||||
batch_no = filters.get("batch")
|
||||
|
||||
batch_sle_data = get_batch_qty(item_code=item, batch_no=batch_no) or []
|
||||
batch_sle_data = (
|
||||
get_batch_qty(
|
||||
item_code=item, batch_no=batch_no, for_stock_levels=True, consider_negative_batches=True
|
||||
)
|
||||
or []
|
||||
)
|
||||
|
||||
stock_qty_map = {}
|
||||
for row in batch_sle_data:
|
||||
@@ -69,17 +74,17 @@ def get_data(filters=None):
|
||||
batch_records = query.run(as_dict=True) or []
|
||||
|
||||
result = []
|
||||
for batch_doc in batch_records:
|
||||
name = batch_doc.get("name")
|
||||
batch_qty = batch_doc.get("batch_qty") or 0
|
||||
for row in batch_records:
|
||||
name = row.get("name")
|
||||
batch_qty = row.get("batch_qty") or 0
|
||||
stock_qty = stock_qty_map.get(name, 0)
|
||||
difference = stock_qty - batch_qty
|
||||
|
||||
if difference != 0:
|
||||
result.append(
|
||||
{
|
||||
"item_code": batch_doc.get("item"),
|
||||
"item_name": batch_doc.get("item_name"),
|
||||
"item_code": row.get("item"),
|
||||
"item_name": row.get("item_name"),
|
||||
"batch": name,
|
||||
"batch_qty": batch_qty,
|
||||
"stock_qty": stock_qty,
|
||||
@@ -91,15 +96,25 @@ def get_data(filters=None):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_batch_qty(batches=None):
|
||||
if not batches:
|
||||
def update_batch_qty(selected_batches=None):
|
||||
if not selected_batches:
|
||||
return
|
||||
|
||||
batches = json.loads(batches)
|
||||
for batch in batches:
|
||||
batch_name = batch.get("batch")
|
||||
stock_qty = batch.get("stock_qty")
|
||||
selected_batches = json.loads(selected_batches)
|
||||
for row in selected_batches:
|
||||
batch_name = row.get("batch")
|
||||
|
||||
frappe.db.set_value("Batch", batch_name, "batch_qty", stock_qty)
|
||||
batches = get_batch_qty(
|
||||
batch_no=batch_name,
|
||||
item_code=row.get("item_code"),
|
||||
for_stock_levels=True,
|
||||
consider_negative_batches=True,
|
||||
)
|
||||
batch_qty = 0.0
|
||||
if batches:
|
||||
for batch in batches:
|
||||
batch_qty += batch.get("qty")
|
||||
|
||||
frappe.db.set_value("Batch", batch_name, "batch_qty", batch_qty)
|
||||
|
||||
frappe.msgprint(_("Batch Qty updated successfully"), alert=True)
|
||||
|
||||
Reference in New Issue
Block a user