mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
feat: provision to close the Work Order
(cherry picked from commit 23af036894)
This commit is contained in:
@@ -135,24 +135,26 @@ frappe.ui.form.on("Work Order", {
|
|||||||
frm.set_intro(__("Submit this Work Order for further processing."));
|
frm.set_intro(__("Submit this Work Order for further processing."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frm.doc.docstatus===1) {
|
if (frm.doc.status != "Closed") {
|
||||||
frm.trigger('show_progress_for_items');
|
if (frm.doc.docstatus===1) {
|
||||||
frm.trigger('show_progress_for_operations');
|
frm.trigger('show_progress_for_items');
|
||||||
}
|
frm.trigger('show_progress_for_operations');
|
||||||
|
}
|
||||||
|
|
||||||
if (frm.doc.docstatus === 1
|
if (frm.doc.docstatus === 1
|
||||||
&& frm.doc.operations && frm.doc.operations.length) {
|
&& frm.doc.operations && frm.doc.operations.length) {
|
||||||
|
|
||||||
const not_completed = frm.doc.operations.filter(d => {
|
const not_completed = frm.doc.operations.filter(d => {
|
||||||
if(d.status != 'Completed') {
|
if(d.status != 'Completed') {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(not_completed && not_completed.length) {
|
||||||
|
frm.add_custom_button(__('Create Job Card'), () => {
|
||||||
|
frm.trigger("make_job_card");
|
||||||
|
}).addClass('btn-primary');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if(not_completed && not_completed.length) {
|
|
||||||
frm.add_custom_button(__('Create Job Card'), () => {
|
|
||||||
frm.trigger("make_job_card");
|
|
||||||
}).addClass('btn-primary');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,14 +519,19 @@ frappe.ui.form.on("Work Order Operation", {
|
|||||||
erpnext.work_order = {
|
erpnext.work_order = {
|
||||||
set_custom_buttons: function(frm) {
|
set_custom_buttons: function(frm) {
|
||||||
var doc = frm.doc;
|
var doc = frm.doc;
|
||||||
if (doc.docstatus === 1) {
|
if (doc.docstatus === 1 && doc.status != "Closed") {
|
||||||
|
console.log("check");
|
||||||
|
frm.add_custom_button(__('Close'), function() {
|
||||||
|
erpnext.work_order.change_work_order_status(frm, "Closed");
|
||||||
|
}, __("Status"));
|
||||||
|
|
||||||
if (doc.status != 'Stopped' && doc.status != 'Completed') {
|
if (doc.status != 'Stopped' && doc.status != 'Completed') {
|
||||||
frm.add_custom_button(__('Stop'), function() {
|
frm.add_custom_button(__('Stop'), function() {
|
||||||
erpnext.work_order.stop_work_order(frm, "Stopped");
|
erpnext.work_order.change_work_order_status(frm, "Stopped");
|
||||||
}, __("Status"));
|
}, __("Status"));
|
||||||
} else if (doc.status == 'Stopped') {
|
} else if (doc.status == 'Stopped') {
|
||||||
frm.add_custom_button(__('Re-open'), function() {
|
frm.add_custom_button(__('Re-open'), function() {
|
||||||
erpnext.work_order.stop_work_order(frm, "Resumed");
|
erpnext.work_order.change_work_order_status(frm, "Resumed");
|
||||||
}, __("Status"));
|
}, __("Status"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,9 +720,10 @@ erpnext.work_order = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
stop_work_order: function(frm, status) {
|
change_work_order_status: function(frm, status) {
|
||||||
|
let method_name = status=="Closed" ? "close_work_order" : "stop_unstop";
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.manufacturing.doctype.work_order.work_order.stop_unstop",
|
method: `erpnext.manufacturing.doctype.work_order.work_order.${method_name}`,
|
||||||
freeze: true,
|
freeze: true,
|
||||||
freeze_message: __("Updating Work Order status"),
|
freeze_message: __("Updating Work Order status"),
|
||||||
args: {
|
args: {
|
||||||
|
|||||||
@@ -99,7 +99,7 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "status",
|
"oldfieldname": "status",
|
||||||
"oldfieldtype": "Select",
|
"oldfieldtype": "Select",
|
||||||
"options": "\nDraft\nSubmitted\nNot Started\nIn Process\nCompleted\nStopped\nCancelled",
|
"options": "\nDraft\nSubmitted\nNot Started\nIn Process\nCompleted\nStopped\nClosed\nCancelled",
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
@@ -573,7 +573,8 @@
|
|||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-10-27 19:21:35.139888",
|
"migration_hash": "a18118963f4fcdb7f9d326de5f4063ba",
|
||||||
|
"modified": "2021-10-29 15:12:32.203605",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Work Order",
|
"name": "Work Order",
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class WorkOrder(Document):
|
|||||||
|
|
||||||
def update_status(self, status=None):
|
def update_status(self, status=None):
|
||||||
'''Update status of work order if unknown'''
|
'''Update status of work order if unknown'''
|
||||||
if status != "Stopped":
|
if status != "Stopped" and status != "Closed":
|
||||||
status = self.get_status(status)
|
status = self.get_status(status)
|
||||||
|
|
||||||
if status != self.status:
|
if status != self.status:
|
||||||
@@ -624,7 +624,6 @@ class WorkOrder(Document):
|
|||||||
def validate_operation_time(self):
|
def validate_operation_time(self):
|
||||||
for d in self.operations:
|
for d in self.operations:
|
||||||
if not d.time_in_mins > 0:
|
if not d.time_in_mins > 0:
|
||||||
print(self.bom_no, self.production_item)
|
|
||||||
frappe.throw(_("Operation Time must be greater than 0 for Operation {0}").format(d.operation))
|
frappe.throw(_("Operation Time must be greater than 0 for Operation {0}").format(d.operation))
|
||||||
|
|
||||||
def update_required_items(self):
|
def update_required_items(self):
|
||||||
@@ -967,6 +966,10 @@ def stop_unstop(work_order, status):
|
|||||||
frappe.throw(_("Not permitted"), frappe.PermissionError)
|
frappe.throw(_("Not permitted"), frappe.PermissionError)
|
||||||
|
|
||||||
pro_order = frappe.get_doc("Work Order", work_order)
|
pro_order = frappe.get_doc("Work Order", work_order)
|
||||||
|
|
||||||
|
if pro_order.status == "Closed":
|
||||||
|
frappe.throw(_("Closed Work Order can not be stopped or Re-opened"))
|
||||||
|
|
||||||
pro_order.update_status(status)
|
pro_order.update_status(status)
|
||||||
pro_order.update_planned_qty()
|
pro_order.update_planned_qty()
|
||||||
frappe.msgprint(_("Work Order has been {0}").format(status))
|
frappe.msgprint(_("Work Order has been {0}").format(status))
|
||||||
@@ -1001,6 +1004,30 @@ def make_job_card(work_order, operations):
|
|||||||
if row.job_card_qty > 0:
|
if row.job_card_qty > 0:
|
||||||
create_job_card(work_order, row, auto_create=True)
|
create_job_card(work_order, row, auto_create=True)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def close_work_order(work_order, status):
|
||||||
|
if not frappe.has_permission("Work Order", "write"):
|
||||||
|
frappe.throw(_("Not permitted"), frappe.PermissionError)
|
||||||
|
|
||||||
|
work_order = frappe.get_doc("Work Order", work_order)
|
||||||
|
if work_order.get("operations"):
|
||||||
|
job_cards = frappe.get_list("Job Card",
|
||||||
|
filters={
|
||||||
|
"work_order": work_order.name,
|
||||||
|
"status": "Work In Progress"
|
||||||
|
},
|
||||||
|
pluck='name')
|
||||||
|
|
||||||
|
if job_cards:
|
||||||
|
job_cards = ", ".join(job_cards)
|
||||||
|
frappe.throw(_("Can not close Work Order. Since {0} Job Cards are in Work In Progress state.").format(job_cards))
|
||||||
|
|
||||||
|
work_order.update_status(status)
|
||||||
|
work_order.update_planned_qty()
|
||||||
|
frappe.msgprint(_("Work Order has been {0}").format(status))
|
||||||
|
work_order.notify_update()
|
||||||
|
return work_order.status
|
||||||
|
|
||||||
def split_qty_based_on_batch_size(wo_doc, row, qty):
|
def split_qty_based_on_batch_size(wo_doc, row, qty):
|
||||||
if not cint(frappe.db.get_value("Operation",
|
if not cint(frappe.db.get_value("Operation",
|
||||||
row.operation, "create_job_card_based_on_batch_size")):
|
row.operation, "create_job_card_based_on_batch_size")):
|
||||||
|
|||||||
Reference in New Issue
Block a user