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 23, 2024
1 parent f3b91d4 commit a67b696
Show file tree
Hide file tree
Showing 19 changed files with 1,057 additions and 71 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
14 changes: 11 additions & 3 deletions 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 @@ -102,7 +103,7 @@
"no_copy": 1,
"oldfieldname": "status",
"oldfieldtype": "Select",
"options": "\nDraft\nSubmitted\nNot Started\nIn Process\nCompleted\nStopped\nClosed\nCancelled",
"options": "\nDraft\nSubmitted\nNot Started\nIn Process\nStock Reserved\nStock Partially Reserved\nCompleted\nStopped\nClosed\nCancelled",
"read_only": 1,
"reqd": 1,
"search_index": 1
Expand Down Expand Up @@ -214,7 +215,6 @@
"read_only": 1
},
{
"allow_on_submit": 1,
"fieldname": "sales_order",
"fieldtype": "Link",
"in_global_search": 1,
Expand Down Expand Up @@ -322,6 +322,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 +586,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-23 16:56:00.483027",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order",
Expand Down
Loading

0 comments on commit a67b696

Please sign in to comment.