Skip to content

Commit

Permalink
feat: stock reservation for Work Order
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Sep 20, 2024
1 parent f3b91d4 commit de8fc6a
Show file tree
Hide file tree
Showing 16 changed files with 928 additions and 66 deletions.
54 changes: 54 additions & 0 deletions erpnext/manufacturing/doctype/work_order/work_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ frappe.ui.form.on("Work Order", {
frm.trigger("add_custom_button_to_return_components");
},

has_unreserved_stock(frm) {
let has_unreserved_stock = frm.doc.required_items.some(
(item) => flt(item.required_qty) > flt(item.stock_reserved_qty)
);

return has_unreserved_stock;
},

has_reserved_stock(frm) {
let has_reserved_stock = frm.doc.required_items.some((item) => flt(item.stock_reserved_qty) > 0);

return has_reserved_stock;
},

add_custom_button_to_return_components: function (frm) {
if (frm.doc.docstatus === 1 && ["Closed", "Completed"].includes(frm.doc.status)) {
let non_consumed_items = frm.doc.required_items.filter((d) => {
Expand Down Expand Up @@ -545,6 +559,12 @@ frappe.ui.form.on("Work Order", {
erpnext.work_order.calculate_cost(frm.doc);
erpnext.work_order.calculate_total_cost(frm);
},

on_submit() {
frappe.route_hooks.after_submit = (frm) => {
frm.reload_doc();
};
},
});

frappe.ui.form.on("Work Order Item", {
Expand Down Expand Up @@ -657,6 +677,8 @@ erpnext.work_order = {
);
}

erpnext.work_order.setup_stock_reservation(frm);

if (!frm.doc.track_semi_finished_goods) {
const show_start_btn =
frm.doc.skip_transfer || frm.doc.transfer_material_against == "Job Card" ? 0 : 1;
Expand Down Expand Up @@ -750,6 +772,38 @@ erpnext.work_order = {
}
}
},

setup_stock_reservation(frm) {
if (frm.doc.docstatus === 1 && frm.doc.reserve_stock) {
if (
frm.events.has_unreserved_stock(frm) &&
(frm.doc.skip_transfer || frm.doc.material_transferred_for_manufacturing < frm.doc.qty)
) {
frm.add_custom_button(
__("Reserve"),
() => erpnext.stock_reservation.make_entries(frm, "required_items"),
__("Stock Reservation")
);
}

if (frm.events.has_reserved_stock(frm)) {
if (frm.doc.skip_transfer || frm.doc.material_transferred_for_manufacturing < frm.doc.qty) {
frm.add_custom_button(
__("Unreserve"),
() => erpnext.stock_reservation.unreserve_stock(frm),
__("Stock Reservation")
);
}

frm.add_custom_button(
__("Reserved Stock"),
() => erpnext.stock_reservation.show_reserved_stock(frm, "required_items"),
__("Stock Reservation")
);
}
}
},

calculate_cost: function (doc) {
if (doc.operations) {
var op = doc.operations;
Expand Down
11 changes: 10 additions & 1 deletion erpnext/manufacturing/doctype/work_order/work_order.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"process_loss_qty",
"project",
"track_semi_finished_goods",
"reserve_stock",
"warehouses",
"source_warehouse",
"wip_warehouse",
Expand Down Expand Up @@ -322,6 +323,8 @@
"label": "Expected Delivery Date"
},
{
"collapsible": 1,
"collapsible_depends_on": "eval:!doc.operations",
"fieldname": "operations_section",
"fieldtype": "Section Break",
"label": "Operations",
Expand Down Expand Up @@ -584,14 +587,20 @@
"fieldtype": "Check",
"label": "Track Semi Finished Goods",
"read_only": 1
},
{
"default": "0",
"fieldname": "reserve_stock",
"fieldtype": "Check",
"label": " Reserve Stock"
}
],
"icon": "fa fa-cogs",
"idx": 1,
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2024-03-27 13:13:00.129434",
"modified": "2024-09-19 12:04:00.701792",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order",
Expand Down
Loading

0 comments on commit de8fc6a

Please sign in to comment.