Leave Workflow customization

below is screenshot of leave workflow

if leave approver approved the leave application then it successfully save with status approved
but if it rejects then submit button comes and after submitting it throws error that

Only Leave Applications with status ‘Approved’ can be submitted

below is console log
Traceback (most recent call last):
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/handler.py”, line 40, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 898, in call
return fn(*args, **newargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 725, in submit
self._submit()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 714, in _submit
self.save()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in save
return self._save(*args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 269, in save
self.run_post_save_methods()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 773, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 651, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 860, in composer
return composed(self, method, *args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 843, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 645, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/erpnext/erpnext/hr/doctype/leave_application/leave_application.py”, line 56, in on_submit
frappe.throw(
(“Only Leave Applications with status ‘Approved’ can be submitted”))
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 310, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 303, in msgprint
_raise_exception()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 276, in _raise_exception
raise raise_exception, encode(msg)
ValidationError: Only Leave Applications with status ‘Approved’ can be submitted

have i made any mistake or these is behaviour as per workflow?

Doc Status for applied and pending should be 0, not 1.

@umair still same problem.

@Hardik_Mehta

set Doc Status 1 only for state Approved

@Sangram for others should i set 0 ?

@Hardik_Mehta

yes

let me try this and let you know.

@Sangram still same issue:sweat:

Please share the latest screenshot of your workflow as well as error screen.

below is console error

Traceback (most recent call last):
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/handler.py”, line 40, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 898, in call
return fn(*args, **newargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
doc.submit()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 725, in submit
self._submit()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 714, in _submit
self.save()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in save
return self._save(*args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 269, in save
self.run_post_save_methods()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 773, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 651, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 860, in composer
return composed(self, method, *args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 843, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/model/document.py”, line 645, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/hardik/intranet/frappe-bench/apps/erpnext/erpnext/hr/doctype/leave_application/leave_application.py”, line 56, in on_submit
frappe.throw(
(“Only Leave Applications with status ‘Approved’ can be submitted”))
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 310, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 303, in msgprint
_raise_exception()
File “/home/hardik/intranet/frappe-bench/apps/frappe/frappe/init.py”, line 276, in _raise_exception
raise raise_exception, encode(msg)
ValidationError: Only Leave Applications with status ‘Approved’ can be submitted

error screenshots

set Doc Status 0 to state Rejected.

@Sangram seems it is working can u please explain so that i can understand clearly.

Refer leave_application.py

https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/leave_application/leave_application.py#L50-L52

@Sangram if i set all doc status as 0 then i can directly approve or reject but if i make state as above at the time of approve it still give error.

@Hardik_Mehta

set Doc status 1 to Approved state as it is your final state. After Approve your leave application gets submitted. Also, there is validation on leave application . Only application with Approved status are submittable.

Refer the following link for more details about workflow.
Workflow Details

@Sangram i have tried previously this example from documentation it is not working.

Any issue in your current workflow ?

@Sangram yes for e.g i have applied my leave application for approval .so it goes to leave approval it changes it’s action to review and selects approve from action button then it is giving error as previous.only if i changed it’s status to approve it gets saved.

It’s not an issue. It’s validation on leave application only Approved status application are submittable.

@Sangram after commenting this code it is working.