I have two 'state' fields to apply to two different workflows of the same model and I would like to switch between them based on a field value.
Can I achieve that?
Thanks in advance.
[EDIT]
file .py
branch1 = fields.Selection([
('state1', 'State 1'),
('state2', 'State 2'),
]
)
branch2 = fields.Selection([
('b2_state1', 'State 1'),
('b2_state2', 'State 2'),
]
)
wkf.xml
I use same states and transitions methodology for both branches, obviously with appropriate field names which I modified here to post.
DEFINITION
<record model="workflow" id="wkf_branch1">
<field name="name">Branch 1</field>
<field name="osv">model.name</field>
<field name="on_create">True</field>
</record>
<record model="workflow" id="wkf_branch2">
<field name="name">Branch 2</field>
<field name="osv">model.name</field>
<field name="on_create">True</field>
</record>
STATES
<record model="ir.actions.server" id="set_model_to_state2">
<field name="name">Set Model to State2</field>
<field name="model_id" ref="model_name"/>
<field name="code">
model.search([('id', 'in', context['active_ids'])]).function()
</field>
</record>
<record model="workflow.activity" id="state1">
<field name="name">State 1</field>
<field name="wkf_id" ref="wkf_branch1"/>
<field name="flow_start" eval="True"/>
<field name="kind">dummy</field>
<field name="action"></field>
<field name="action_id" ref="set_model_to_state2"/>
</record>
....
and so for branch2
TRANSITIONS
<record model="workflow.transition" id="model_state1_to_state2">
<field name="act_from" ref="state1"/>
<field name="act_to" ref="state2"/>
<field name="signal">state2</field>
</record>
....
and so for branch2
view.xml
<header>
<!-- FORWARD BUTTONS -->
<button name="state1" type="workflow"
string="Reset to state1"
states="state2"/>
<button name="state2" type="workflow"
string="State 2" states="state1"/>
<button name="b2_state1" type="workflow"
string="Reset to State1"
states="b2_state2"/>
<button name="b2_state2" type="workflow"
string="State 2"
states="state1"/>
<field name="branch1" widget="statusbar"
attrs="{'invisible': [('type', '=', 'certain_type')]}"/>
<field name="branch2" widget="statusbar"
attrs="{'invisible': [('type', 'in', ['other_type1', 'other_type2'])]}"/>
</header>
So the problems are:
- I can hide the statusbar of the 'branch1' in the view.xml based on the condition in the 'attrs' attribute, but it doesn't work for the buttons (not present in the code here, but i attempt with both 'attrs' and 'invisible' attributes).
- I can not show the statusbar of the 'branch2' and not even the buttons.
- I don't know how to tell to Odoo to diversify the two workflows, since they belong to the same model.
- I don't think the subflow solution will be fine for my case, since I would to use a flow if the model is of one type and the other otherwise.
Thanks again.