How to apply condition for work order closure

Hello all,

hope you are doing great !

i would like to set certain conditions while work order closure - Specifically “Finish” button

Condition is “If any work order has Non Conformance open, work order should not get closed”

image

How to apply, where to apply and what condition should we write in this?

please guide

To apply the condition you described in ERPNext, you can use a custom script. Here’s a step-by-step guide on how to implement the condition for the “Finish” button in work order closure:

  1. Access the ERPNext desk as an administrator.
  2. Go to the “Custom Script” doctype by typing “Custom Script” in the search bar and selecting it from the results.
  3. Click on “New” to create a new custom script.
  4. In the “Custom Script” form, set the “DocType” field to “Work Order”.
  5. In the “Script” field, you can write the code to implement the condition. Here’s an example:

javascript

frappe.ui.form.on('Work Order', {
  validate: function(frm) {
    if (frm.doc.status === 'Completed') {
      frappe.call({
        method: 'your_custom_app.your_custom_module.your_custom_function',
        args: {
          work_order: frm.doc.name
        },
        callback: function(response) {
          if (response.message === 'open_non_conformance') {
            frappe.throw('Cannot close the work order. Non-Conformance is still open.');
          }
        }
      });
    }
  }
});

In the code above, replace 'your_custom_app.your_custom_module.your_custom_function' with the actual path to your custom Python function. This function should check if any non-conformance related to the work order is open. It should return 'open_non_conformance' if a non-conformance is open, and an empty string or any other value if not.

  1. Save the custom script.
  2. Test the functionality by opening a work order and trying to close it when a non-conformance is open. The system should display an error message preventing the closure.

Note: Make sure you have the necessary permissions and knowledge of custom scripting in ERPNext. Additionally, adjust the code according to your specific custom application and module structure.

Remember to always test the implemented functionality in a development or testing environment before applying it to your live production system.

1 Like

thanks a lot for your reply. let me do trial run with this.