Workflow proccess in code

How Does workflow process work from code?

I’ve added new role called “Department manager” and I grant this role just for one Employee in the department.
Let take an example.
I create a new workflow for the Leave Application that will work as the following:
1- Employee create leave application
2- Department Manager approve or reject
3- If he didn’t have enough leave balance days the HR manager approve or reject

I want to add specific rules for the Department manager to detect the who is the department manager of the employee.
so I have to update the workflow process from code , but I didn’t find where should I insert my code.

My question is Where can I find the workflow process from the code?

@mostafa you dont need of code to do this! Just use the permission system, some links and fetches!

Due that each Employee, is member of only one department

In the Leave Application, add a Link field, to the Departament, and use add_fetch based on employee, to fetch him department!

In the Role Permission Manager, check the option “Apply user permissions” for the “Department Manager” in the doctype “Leave Application”.

Select the option “If Department is permitted” in Select document type

And using “Documents Permitted for a User” do a relation between the “Department Manager” user and his department.

And Enjoy!

http://frappe.github.io/erpnext/user/manual/en/setting-up/users-and-permissions/

@max_morais_dmm Thank you for your responding.
I want to as about the add_fetch i wrote it as the following, and nothing happen.

cur_frm.add_fetch(‘department_name’ , ‘department’, ‘department’);

Any help?

@mostafa, I think it is cur_frm.add_fetch("employee", "department", "department");

cur_frm.add_fetch(“employee”, “department”, “department”)

it doesn’t work…

What does employee refer to?
is it refer to field name or the doctype?

By implementing your scenario any department manager can approve or reject any request.

I want the department manager who is in the same department with the employee to make this action.

@mostafa, you are completely wrong! Revise the permissions, I’m sure about what I’m talking!

The add fetch section, should be added as a custom script in your Leave request, it refers to the Employee link field in it!

1st department is the department in the body of the employee record
2nd department is a custom link field to link with Department doctype that do you need add in the body of Leave Request

it seems works, Could you please explain the previous note?