fix: Alternative Items button in Work Order
(cherry picked from commit e28382afc1)
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on("Work Order Item", {
|
||||
allow_alternative_item(frm, cdt, cdn) {
|
||||
frm.trigger("allow_alternative_item");
|
||||
},
|
||||
});
|
||||
|
||||
frappe.ui.form.on("Work Order", {
|
||||
setup: function (frm) {
|
||||
frm.custom_make_buttons = {
|
||||
@@ -130,6 +136,32 @@ frappe.ui.form.on("Work Order", {
|
||||
);
|
||||
},
|
||||
|
||||
allow_alternative_item: function (frm) {
|
||||
let has_alternative = false;
|
||||
if (frm.doc.required_items) {
|
||||
has_alternative = frm.doc.required_items.find((i) => i.allow_alternative_item === 1);
|
||||
}
|
||||
|
||||
if (frm.doc.allow_alternative_item && frm.doc.docstatus == 0 && has_alternative) {
|
||||
frm.add_custom_button(__("Alternate Item"), () => {
|
||||
erpnext.utils.select_alternate_items({
|
||||
frm: frm,
|
||||
child_docname: "required_items",
|
||||
warehouse_field: "source_warehouse",
|
||||
child_doctype: "Work Order Item",
|
||||
original_item_field: "original_item",
|
||||
condition: (d) => {
|
||||
if (d.allow_alternative_item) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
} else {
|
||||
frm.remove_custom_button(__("Alternate Item"));
|
||||
}
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
erpnext.toggle_naming_series();
|
||||
erpnext.work_order.set_custom_buttons(frm);
|
||||
@@ -163,26 +195,6 @@ frappe.ui.form.on("Work Order", {
|
||||
}
|
||||
}
|
||||
|
||||
if (frm.doc.required_items && frm.doc.allow_alternative_item) {
|
||||
const has_alternative = frm.doc.required_items.find((i) => i.allow_alternative_item === 1);
|
||||
if (frm.doc.docstatus == 0 && has_alternative) {
|
||||
frm.add_custom_button(__("Alternate Item"), () => {
|
||||
erpnext.utils.select_alternate_items({
|
||||
frm: frm,
|
||||
child_docname: "required_items",
|
||||
warehouse_field: "source_warehouse",
|
||||
child_doctype: "Work Order Item",
|
||||
original_item_field: "original_item",
|
||||
condition: (d) => {
|
||||
if (d.allow_alternative_item) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (frm.doc.status == "Completed") {
|
||||
if (frm.doc.__onload.backflush_raw_materials_based_on == "Material Transferred for Manufacture") {
|
||||
frm.add_custom_button(
|
||||
@@ -618,7 +630,7 @@ erpnext.work_order = {
|
||||
set_custom_buttons: function (frm) {
|
||||
var doc = frm.doc;
|
||||
|
||||
if (doc.status !== "Closed") {
|
||||
if (doc.docstatus === 1 && doc.status !== "Closed") {
|
||||
frm.add_custom_button(
|
||||
__("Close"),
|
||||
function () {
|
||||
|
||||
Reference in New Issue
Block a user