Merge pull request #49923 from rohitwaghchaure/fixed-recalculate-batch-qty

feat: recalculate batch qty
This commit is contained in:
rohitwaghchaure
2025-10-06 21:59:25 +05:30
committed by GitHub
2 changed files with 22 additions and 0 deletions

View File

@@ -22,6 +22,17 @@ frappe.ui.form.on("Batch", {
frappe.set_route("query-report", "Stock Ledger");
});
frm.trigger("make_dashboard");
frm.add_custom_button(__("Recalculate Batch Qty"), () => {
frm.call({
method: "recalculate_batch_qty",
doc: frm.doc,
freeze: true,
callback: () => {
frm.reload_doc();
},
});
});
}
},
item: (frm) => {

View File

@@ -156,6 +156,17 @@ class Batch(Document):
if frappe.db.get_value("Item", self.item, "has_batch_no") == 0:
frappe.throw(_("The selected item cannot have Batch"))
@frappe.whitelist()
def recalculate_batch_qty(self):
batches = get_batch_qty(batch_no=self.name, item_code=self.item)
batch_qty = 0.0
if batches:
for row in batches:
batch_qty += row.get("qty")
self.db_set("batch_qty", batch_qty)
frappe.msgprint(_("Batch Qty updated to {0}").format(batch_qty), alert=True)
def set_batchwise_valuation(self):
from erpnext.stock.utils import get_valuation_method