feat: provision to close the Work Order

This commit is contained in:
Anupam 2021-10-29 17:27:17 +05:30
parent d0e2b52f51
commit 23af036894
3 changed files with 60 additions and 24 deletions

View File

@ -135,24 +135,26 @@ frappe.ui.form.on("Work Order", {
frm.set_intro(__("Submit this Work Order for further processing."));
}
if (frm.doc.docstatus===1) {
frm.trigger('show_progress_for_items');
frm.trigger('show_progress_for_operations');
}
if (frm.doc.status != "Closed") {
if (frm.doc.docstatus===1) {
frm.trigger('show_progress_for_items');
frm.trigger('show_progress_for_operations');
}
if (frm.doc.docstatus === 1
&& frm.doc.operations && frm.doc.operations.length) {
if (frm.doc.docstatus === 1
&& frm.doc.operations && frm.doc.operations.length) {
const not_completed = frm.doc.operations.filter(d => {
if(d.status != 'Completed') {
return true;
const not_completed = frm.doc.operations.filter(d => {
if(d.status != 'Completed') {
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 = {
set_custom_buttons: function(frm) {
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') {
frm.add_custom_button(__('Stop'), function() {
erpnext.work_order.stop_work_order(frm, "Stopped");
erpnext.work_order.change_work_order_status(frm, "Stopped");
}, __("Status"));
} else if (doc.status == 'Stopped') {
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"));
}
@ -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({
method: "erpnext.manufacturing.doctype.work_order.work_order.stop_unstop",
method: `erpnext.manufacturing.doctype.work_order.work_order.${method_name}`,
freeze: true,
freeze_message: __("Updating Work Order status"),
args: {

View File

@ -99,7 +99,7 @@
"no_copy": 1,
"oldfieldname": "status",
"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,
"reqd": 1,
"search_index": 1
@ -573,7 +573,8 @@
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2021-10-27 19:21:35.139888",
"migration_hash": "a18118963f4fcdb7f9d326de5f4063ba",
"modified": "2021-10-29 15:12:32.203605",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order",

View File

@ -175,7 +175,7 @@ class WorkOrder(Document):
def update_status(self, status=None):
'''Update status of work order if unknown'''
if status != "Stopped":
if status != "Stopped" and status != "Closed":
status = self.get_status(status)
if status != self.status:
@ -624,7 +624,6 @@ class WorkOrder(Document):
def validate_operation_time(self):
for d in self.operations:
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))
def update_required_items(self):
@ -967,6 +966,10 @@ def stop_unstop(work_order, status):
frappe.throw(_("Not permitted"), frappe.PermissionError)
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_planned_qty()
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:
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):
if not cint(frappe.db.get_value("Operation",
row.operation, "create_job_card_based_on_batch_size")):