Reputation: 1043
In my module I have states:
_STATES = [
('draft', 'Draft'),
('to_approve_first', 'Waiting for approval'),
('approved', 'Approved'),
('purchase_conditions','Purchase conditions'),
('create_order','Creating Order'),
('to_approve_second','Approved'),
('in_stock','Products in stock'),
('rejected', 'Rejected')
]
Can I have 2 different workflows based on condition on draft state in form view? For example if field iam_in boolean in draft state is true
worklow will be:
<header>
<button name="%(action_sale_order_reset)d" attrs="{'invisible': [('state','not in', ('to_approve_first'))]}" string="Reset" type="action" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_to_approve_first" states="draft" string="Request approval" type="object" class="oe_highlight"/>
<button name="button_approved" states="to_approve_first" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_purchase_conditions" states="approved" string="Return Request" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_create_order" states="purchase_conditions" string="Create Order" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_user"/>
<button name="button_to_approve_second" states="create_order" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_in_stock" states="to_approve_second" string="Done" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_rejected" states="draft,purchase_conditions" string="Reject" type="object" groups="purchase_request.group_purchase_request_user"/>
<button name="%(action_sale_order_cancel)d" attrs="{'invisible': [('state','not in', ('to_approve_first', 'approved', 'create_order'))]}" string="Cancel with feedback" type="action" groups="purchase_request.group_purchase_request_manager"/>
<field name="state" widget="statusbar" statusbar_visible="draft,to_approve_first,approved,rejected" statusbar_colors="{"approved":"green"}"/>
</header>
And if iam_in boolean in draft is false
the workflow will be shorter:
draft -> to_approve_first -> in_stock
How can I do that? I was thinking about two different views. Because in views I can't use if .. else
conditions.
Upvotes: 0
Views: 611
Reputation: 14768
You could just use your field iam_in
in attrs
(invisible) to show or hide buttons. It could be a bit complex but should work, for example in your button button_approved
:
<button name="button_approved" states="to_approve_first"
string="Approve" type="object" class="oe_highlight"
groups="purchase_request.group_purchase_request_manager"
attrs="{'invisible': [('iam_in', '=', True)]}" />
That will only show the button if the state is to_approve_first
and iam_in=True
. Requirements: The field iam_in
has to be on the model and defined in the view, too (invisible is enough).
Care using states
in combination with attrs
(invisible), because both will be combinated automatically.
Upvotes: 1