【发布时间】:2017-05-15 15:39:42
【问题描述】:
我想在我的采购订单中添加一个“取消”按钮。此按钮会将我的记录状态更改为“已取消”。 当用户单击此按钮时,脚本会验证所有购买查询和供应商订单(如果有任何一项尚未完成或取消)。 我想添加一个弹出窗口来警告用户。用户可以取消操作或追踪,取消所有相关的查询和订单。
这是我的向导模型:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class confirm_wizard(models.TransientModel):
_name = 'tjara.confirm_wizard'
yes_no = fields.Char(default='Do you want to proceed?')
@api.multi
def yes(self):
return True
@api.multi
def no(self):
return False
我的向导视图:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="confirm_wizard_form">
<field name="name">wizard.form</field>
<field name="model">tjara.confirm_wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Confirm dialog">
<field name="yes_no" readonly="1" />
<footer>
<button class="oe_highlight" name="yes" string="Yes" />
<button class="oe_highlight" name="no" string="No" />
</footer>
</form>
</field>
</record>
</data>
</odoo>
按钮:
<button string="Canceled" type="object" name="canceled_progressbar" class="oe_highlight" attrs="{'invisible': [('state', '=', 'done')]}"/>
最后是两种方法:
@api.multi
def return_confirmation(self):
return {
'name': 'Are you sure?',
'type': 'ir.actions.act_window',
'res_model': 'tjara.confirm_wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}
@api.multi
def canceled_progressbar(self):
if(self.return_confirmation()):
#Do some code
else:
#Do some code
只有当按钮指向 return_confirmation 方法时才会触发模型。这使我无法追求我的代码。当用户单击按钮时,只会出现一个弹出窗口然后消失。 我想通过 cancel_progressbar 调用 return_confirmation(弹出窗口),这样我就可以返回值并继续前进。
【问题讨论】:
-
请在表单中添加按钮标签,并在按钮中添加确认属性。请参考odoo.com/forum/help-1/question/…
-
您好,感谢您的回复。无论如何,这只会显示一个确认弹出窗口。我只想在一种情况下显示确认按钮:当记录的相关实体尚未完成时。
-
@Shreeram 感谢您的回复。在我的情况下,确认按钮没有用。请阅读下面我的回复中的解决方案。