Custom workflow in Sales Order

How can I set a condition to change my Sales order workflow to go completed automatically when the delivery note is made and all items are sent?

Thanks

I found that I could trigged something when the delivery state is set to fully delivered. I’m not sure how to do that or what are the parameters called. Any suggestions?

Thanks

I tried with doc.per_delivered == “100%”
doc.per_delivered == 100
doc.delivery_status == “Fully Delivered”

if I make a error like doc.delivery_status === “Fully Delivered” I get an error so I know it’s doing something but my conditions doesnt work and doesnt change the status.

Any suggestions? I’m close but it doesnt work

I found this Some customs scripts that I use

And made a custom script. It’s now working but I need to manually press on Update button in the form for it to update because it’s trigged on the “refresh”.

I guess I need to change the trigger but I’m not sure what to use

frappe.ui.form.on(“Sales Order”, “refresh”, function (frm) {

//Variables for delivery and billing status
var NS = frm.doc.delivery_status === “Not Delivered” ;
var PS = frm.doc.delivery_status === “Partly Delivered” ;
var FS = frm.doc.delivery_status === “Fully Delivered”;
var NB = frm.doc.billing_status === “Not Billed” ;
var PB = frm.doc.billing_status === “Partly Billed” ;
var FB = frm.doc.billing_status === “Fully Billed” ;

var CN = frm.doc.workflow_state === "Cancelled" ;

//Variables for naming workflows. Your workflow names may vary
var READY = “Ready to ship”;
var COMPLETED = “Completed”;
var TOBILL = “To Bill”;
var CANCELLED = “Cancelled”;

//following if function checks to see if the document is submitted
if (frm.doc.docstatus == 1) {
    if (FS && NB) {
    cur_frm.set_value("workflow_state", TOBILL);
    } else if (FS && FB) {
    cur_frm.set_value("workflow_state", COMPLETED); 
} else if (NS && NB && !CN) {
    cur_frm.set_value("workflow_state", READY);
    } 
}

});

anyone? I’m ready to pay for this