mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-15 23:54:59 +00:00
Merge pull request #49923 from rohitwaghchaure/fixed-recalculate-batch-qty
feat: recalculate batch qty
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user