Skip to Content
Menu
This question has been flagged
5 Replies
7462 Views

Hey anyone was able to manually instantiate a new workflow in Odoo 9.0???

Where do I put the code to create the workflow instance? I tried the code below. The workitem and instance get created, and I compared it that what's created when on_create is True, and it seems the same... I don't see what I do wrong... it just doesn't register it correctly... By the way, when I use on_create = True, there is no problem... I just want to have a specific workflow for my specific item.

Any idea what I do wrong?

Thanks


@api.model    
def create(self, vals):
    res = super(SaleOrder, self).create(vals)
    
    if res.is_print:
        res.create_workflow()
    
    return res
Avatar
Discard
Best Answer

You can do this:

from openerp.workflow.instance import WorkflowInstance
from openerp.workflow.helpers import Record, Session
wkf_id = self.env.ref('your_model.your_workflow_id').id
WorkflowInstance.create(Session(self.env.cr, self.env.uid), Record(self._name, res.id), wkf_id)
Avatar
Discard
Best Answer

Hi,

Workflows can be managed in two ways:

1. Define a state field in your model with the required states. Then the state changes can be managed by python methods in your model. For eg: by executing those methods on button click and the record state changes.

2. Create a real workflow instance, by defining a state field as usual and then create a yourmodule_workflow.xml. In that file, add the workflow instance, activities & transitions, as you need. Then you can trigger the transitions from either buttons (create button with type="workflow") or python methods (using signal_workflow())

You may refer this for more details:

https://www.odoo.com/documentation/9.0/howtos/backend.html#workflows

Avatar
Discard
Author

Again "Where do I put the code to create the workflow instance?"... I mean where to I call create_workflow() MANUALLY (I know how to create the workflow definition!). I don't want a workflow for all the records in the database, that's why I want to manage it myself.

Did you check the Odoo official link above? It clearly explains how to create workflow for a newly created model. I just summarized the whole idea and gave that link for you to check more details or an example. If you refer that you will surely come to know, where to put the code to create a new workflow in Odoo 9. What does this create_workflow() in your code do?

Author

Yeah I checked it out... nowhere they are starting the workflow manually. The method create_workflow() is part of the BaseModel class of Odoo and it creates the workflow instance. I can see it in the instance and in the Workitem data... but somehow the instantiated workflow is ignored. Creating an instance of workflow doesn't seem to be supported very well!

Related Posts Replies Views Activity
3
Mar 16
2094
1
Aug 23
1364
1
May 19
2226
0
May 19
2151
0
Dec 18
4273