Workflow conditions in erpnext

Can we add conditions in workflow?
If material requests of amount less than 5000 i need to approve by stock manager.How can I handle it?

Hi @Jeemon_George,

You can add a condition for the Transition to be applicable. For example, in this case, if sales executive creates a quotation with grand total of $100,000 or more, a particular role must approve. For this to happen in the particular transition, you can set a property for condition:

doc.grand_total <= 100000

Please check it.

ok. Thanks.

here how i get grand total in material request.

Material Request form does not Grand Total field; therefore, you need to add a custom field named “Grand Total.” You must also establish the logic using a client/server script to aggregate the totals from Material Request items into the Grand Total. Once this is set up, you can then implement conditions within the workflow based on this field.

Let me check.

Can we add python code for calculating grand total in workflow condition?

No @Jeemon_George

First set the calculation in custom field.

ok.thanks.


Above Picture shows my workflow.When condition(total >5000) satisfies need to approve material reqyest by manager.Otherwise no need of approval.After saving Material Request we have to create purchase order without any approval.How handle in this scenario?

Please check the documentation.

Let me check.

How to use conditions like below.

frappe.utils.add_to_date(doc.time, hours=-frappe.db.get_single_value('My Custom Settings', 'hours')) > frappe.utils.now_datetime()

Value of frappe.db.get_single_value('My Custom Settings', 'hours') will be in int (Non Negative)

Where My Custom Settings is single doctype

When I am using this condition in workflow, it’s giving error as below

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 95, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 48, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 86, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1611, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/model/workflow.py", line 68, in get_transitions
    if not is_transition_condition_satisfied(transition, doc):
  File "apps/frappe/frappe/model/workflow.py", line 95, in is_transition_condition_satisfied
    return frappe.safe_eval(transition.condition, get_workflow_safe_globals(), dict(doc=doc.as_dict()))
  File "apps/frappe/frappe/__init__.py", line 2261, in safe_eval
    return safe_eval(code, eval_globals, eval_locals)
  File "apps/frappe/frappe/utils/safe_exec.py", line 107, in safe_eval
    return eval(
  File "<safe_eval>", line 1, in <module>
TypeError: 'NoneType' object is not callable

Please try it.

frappe.utils.add_to_date(doc.time, hours=-int(frappe.db.get_value('My Custom Settings', None, 'hours'))) > frappe.utils.now_datetime()

You can only use the function below.

1 Like

Thanks @NCP It’s working.