mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-14 18:23:55 +00:00
Merge pull request #45098 from frappe/mergify/bp/version-15-hotfix/pr-45084
fix: Alternative Items button in Work Order (backport #45084)
This commit is contained in:
@@ -130,6 +130,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 +189,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(
|
||||
@@ -210,6 +216,7 @@ frappe.ui.form.on("Work Order", {
|
||||
}
|
||||
|
||||
frm.trigger("add_custom_button_to_return_components");
|
||||
frm.trigger("allow_alternative_item");
|
||||
},
|
||||
|
||||
add_custom_button_to_return_components: function (frm) {
|
||||
@@ -540,6 +547,9 @@ frappe.ui.form.on("Work Order", {
|
||||
});
|
||||
|
||||
frappe.ui.form.on("Work Order Item", {
|
||||
allow_alternative_item(frm) {
|
||||
frm.trigger("allow_alternative_item");
|
||||
},
|
||||
source_warehouse: function (frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (!row.item_code) {
|
||||
@@ -618,7 +628,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