mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 17:53: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({
|
frappe.call({
|
||||||
method: "erpnext.stock.report.stock_qty_vs_batch_qty.stock_qty_vs_batch_qty.update_batch_qty",
|
method: "erpnext.stock.report.stock_qty_vs_batch_qty.stock_qty_vs_batch_qty.update_batch_qty",
|
||||||
args: {
|
args: {
|
||||||
batches: selected_rows,
|
selected_batches: selected_rows,
|
||||||
},
|
},
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (!r.exc) {
|
if (!r.exc) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"idx": 0,
|
"idx": 0,
|
||||||
"is_standard": "Yes",
|
"is_standard": "Yes",
|
||||||
"letterhead": null,
|
"letterhead": null,
|
||||||
"modified": "2025-10-07 20:03:45.952352",
|
"modified": "2025-11-18 11:35:04.615085",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Stock Qty vs Batch Qty",
|
"name": "Stock Qty vs Batch Qty",
|
||||||
@@ -21,10 +21,7 @@
|
|||||||
"report_type": "Script Report",
|
"report_type": "Script Report",
|
||||||
"roles": [
|
"roles": [
|
||||||
{
|
{
|
||||||
"role": "Stock Manager"
|
"role": "Item Manager"
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "Stock User"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"timeout": 0
|
"timeout": 0
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ def get_data(filters=None):
|
|||||||
item = filters.get("item")
|
item = filters.get("item")
|
||||||
batch_no = filters.get("batch")
|
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 = {}
|
stock_qty_map = {}
|
||||||
for row in batch_sle_data:
|
for row in batch_sle_data:
|
||||||
@@ -69,17 +74,17 @@ def get_data(filters=None):
|
|||||||
batch_records = query.run(as_dict=True) or []
|
batch_records = query.run(as_dict=True) or []
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for batch_doc in batch_records:
|
for row in batch_records:
|
||||||
name = batch_doc.get("name")
|
name = row.get("name")
|
||||||
batch_qty = batch_doc.get("batch_qty") or 0
|
batch_qty = row.get("batch_qty") or 0
|
||||||
stock_qty = stock_qty_map.get(name, 0)
|
stock_qty = stock_qty_map.get(name, 0)
|
||||||
difference = stock_qty - batch_qty
|
difference = stock_qty - batch_qty
|
||||||
|
|
||||||
if difference != 0:
|
if difference != 0:
|
||||||
result.append(
|
result.append(
|
||||||
{
|
{
|
||||||
"item_code": batch_doc.get("item"),
|
"item_code": row.get("item"),
|
||||||
"item_name": batch_doc.get("item_name"),
|
"item_name": row.get("item_name"),
|
||||||
"batch": name,
|
"batch": name,
|
||||||
"batch_qty": batch_qty,
|
"batch_qty": batch_qty,
|
||||||
"stock_qty": stock_qty,
|
"stock_qty": stock_qty,
|
||||||
@@ -91,15 +96,25 @@ def get_data(filters=None):
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def update_batch_qty(batches=None):
|
def update_batch_qty(selected_batches=None):
|
||||||
if not batches:
|
if not selected_batches:
|
||||||
return
|
return
|
||||||
|
|
||||||
batches = json.loads(batches)
|
selected_batches = json.loads(selected_batches)
|
||||||
for batch in batches:
|
for row in selected_batches:
|
||||||
batch_name = batch.get("batch")
|
batch_name = row.get("batch")
|
||||||
stock_qty = batch.get("stock_qty")
|
|
||||||
|
|
||||||
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)
|
frappe.msgprint(_("Batch Qty updated successfully"), alert=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user