在我的模块中,我说:
_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')
]
我可以根据表单视图中的草稿状态条件设置2个不同的工作流程吗?例如if field iam_in boolean in draft state is true
worklow将是:
<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>
如果iam_in boolean in draft is false
工作流程更短:
draft -> to_approve_first -> in_stock
我该怎么做?我在考虑两种不同的观点。因为在视图中我无法使用if .. else
条件。
答案 0 :(得分:1)
您可以使用iam_in
中的字段attrs
(不可见)来显示或隐藏按钮。它可能有点复杂但应该可以工作,例如在按钮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)]}" />
如果状态为to_approve_first
和iam_in=True
,则只显示按钮。要求:字段iam_in
必须位于模型上并在视图中定义(不可见就足够了)。
使用states
与attrs
(不可见)结合使用,因为两者都会自动合并。