Doctype Custom States

Hi,

I have been wanting to implement a few custom doctypes, and in one particular case … needing to implement custom states. Basically, let the user know in what situation a document is at, similar to “To Bill”, “To Ship” states that come with a Sales Order upon approval.

I checked out Workflow states, but that seems more for when I need approval. Is there any ways of changing the state of a document automatically by some even happening else where in the system?

Should I simply have a hidden field called status, and have it updated every time a related document is changed. Or is there a more elegant approach?

Somehow, you need to store the current 'Status' in the database.
What you suggested above is the typical way. DocTypes such as Sales and Purchase Orders, Stock Entries, and many others do exactly this.

As an example, below is a screenshot of some Sales Invoice code for setting the Status:

Note: You may want to avoid creating DocFields named “disabled” or “status”. The framework makes assumptions about certain spellings. It can become annoying/confusing later. Add a prefix like “is_disabled” or “order_status” to prevent that from happening.

1 Like

You can also do this purely on the client side, defining different indicator colors and labels for different document states, using list-type client scripts. For an example, see the get_indicator function defined here:

https://frappeframework.com/docs/v14/user/en/api/list#standard-list-js

1 Like