Approval Workflow Based On Department

I am looking to Create a Purchase Order Approval Workflow based on Department.

Scenario:

  1. Employee in a given department raises a Purchase Order
  2. Senior Admin Staff for that Department Gives First-Line Approval
  3. Final approval is given by Manager/CEO

See Below screenshot for proposed Workflow

Action Taken:

I have created a custom field in the Purchase Order Doctype to indicate Department and made the field compulsory.

Challenge:

  1. How do i enforce If Department is Permitted in User Permission? This was easier to accomplish in V10 but with changes to the permission manager in v11 and carried over to v12, i am finding it difficult to implement
  2. How do i ensure that only users whose Department=True will be notified via mail for approval.
  3. Is it possible to modify the default workflow mail alert auto-generated? or do i have to create custom mail alert to accomplish (2) above?

Any help in this regard will be appreciated.

Thanks.

3 Likes

I will appreciate any help on this… anyone???

Hi Felix, did you look into Workflows already?

You can define the different values for the “Status” field (“Draft”, “Approved by X”, Approved by Y", “Approved”, “Completed”, … ) and allow transitions from one status to the other only for certain roles (“Accounts User”, “Project Manager”, … ).

Working on this for a client. A little bit of custom scripting is necessary for this. Will share the script when it’s ready.

Thanks

Jay

2 Likes

Yes I tried that but it doesn’t exactly work for the flow required based on the diagram above. Being able to segment the workflow along a department line once initiated is the challenge.

@JayRam

I will very much appreciate it. Thanks a lot.

@JayRam any update on this?

Apologies. Here is the script. We use this in the Material Request Document. The Department is the Standard Feature in the Employee master. The script fetches the Department value for the user from the Employee master and populates a Department field in the Material Request document. Now (though I haven’t rolled this out for the client yet) user permissions for the approver to just be able to look at Material Requests from her/his department should ensure that the approver can only access and approve her/his department’s requests only.

We’ve learnt to add some characters to the Custom Fields we build as we want to reduce the probability of the core code using a similar field in the future. That’s the reason you see pch_department. Not department.

Hope this helps. Script after my signature.

Thanks

Jay

Here’s the script:

frappe.ui.form.on(“Material Request”, “refresh”, function(frm, cdt, cdn) {
console.log(“Entered------”);
var d = locals[cdt][cdn];
console.log(“Entered------” + d);
console.log(“items_list------” + JSON.stringify(d));
if(frm.doc.docstatus!=1){
var department= fetch_pch_department(d.modified_by);
console.log(“***********—” + JSON.stringify(department));
cur_frm.set_value(“pch_department”,department)
frm.refresh_field(“pch_department”)
}
});
function fetch_pch_department(arg1){
console.log(“entered into function”);
var pch_department=“”
frappe.call({
method: ‘frappe.client.get_value’,
args: {
‘doctype’: ‘Employee’,
‘fieldname’: “department”,
‘filters’: {
user_id:arg1,
}
},
async: false,
callback: function(r) {
if (r.message) {
pch_department=r.message.department;
console.log(“readings-----------” + JSON.stringify(r.message));
}
}
});
return pch_department
}

2 Likes

How to limit workflow action email to only certain user ? We have more than one project manager role.