0
votes

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:

  1. 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).
  2. I can not show the statusbar of the 'branch2' and not even the buttons.
  3. I don't know how to tell to Odoo to diversify the two workflows, since they belong to the same model.
  4. 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.

1
Please edit your question and add: 1. Your code/your attempts 2. Your input, current output and expected outputBhavesh Odedra

1 Answers

1
votes

Fixed.

I putted both branches inside the same workflow and splitted them up with the 'split_mode' and conditional transitions.

Still remain a problem, but it's secondary. I would like to show in the statusbar only the states of one branch. I don't know if it is possible or not.

[EDIT]

Solved that too. I am showing only the current state with 'statusbar_visible=" "'