Odoo 10:从向导调用确认表(是/否)
Odoo 10 : Call a confirmation form (Yes / No) from Wizard
我想在我的采购订单中添加一个 'cancel' 按钮。此按钮会将我的记录状态更改为 'canceled'。
当用户单击此按钮时,脚本会验证所有购买查询和供应商订单(如果有任何订单尚未完成或已取消)。
我想添加一个弹出窗口来警告用户。用户可以取消操作或追踪,取消所有相关询盘和订单。
这是我的精灵模型:
# -*- 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 方法时才会触发模型。这让我无法追求我的代码。当用户单击按钮时,只会出现一个弹出窗口然后消失。
我想通过 canceled_progressbar 调用 return_confirmation(弹出窗口),这样我就可以 return 值并继续。
您应该 return 直接从 def canceled_progressbar
方法中获取 Action,而不是单独定义它。
此外,我认为您的方法 def return_confirmation
无法像您通过 returning 'True' 或 'False' 尝试的那样接收值。
这里你应该直接在向导中添加你的代码基于点击 'Yes' 或 'No' 按钮,你计划在 def return_confirmation
.
嗯,这是我写的:
@api.multi
def yes(self):
print 'yes function'
self.env['tjara.purchase_order'].function1()
@api.multi
def no(self):
print 'no function'
self.env['purchase_order'].function1()
'canceled_progressbar'方法return:
@api.multi
def canceled_progressbar(self):
print 'canceled_progressbar'
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 function1(self):
print 'this function 1'
@api.multi
def function2(self):
print 'this function 2'
我想知道我是否只能实现一个功能,但似乎不可能。
谢谢大家的帮助。
您可以添加:
confirm="Your Custom message like Are you sure you want to process this?"
在 xml 中的按钮。
我想在我的采购订单中添加一个 'cancel' 按钮。此按钮会将我的记录状态更改为 'canceled'。 当用户单击此按钮时,脚本会验证所有购买查询和供应商订单(如果有任何订单尚未完成或已取消)。 我想添加一个弹出窗口来警告用户。用户可以取消操作或追踪,取消所有相关询盘和订单。
这是我的精灵模型:
# -*- 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 方法时才会触发模型。这让我无法追求我的代码。当用户单击按钮时,只会出现一个弹出窗口然后消失。 我想通过 canceled_progressbar 调用 return_confirmation(弹出窗口),这样我就可以 return 值并继续。
您应该 return 直接从 def canceled_progressbar
方法中获取 Action,而不是单独定义它。
此外,我认为您的方法 def return_confirmation
无法像您通过 returning 'True' 或 'False' 尝试的那样接收值。
这里你应该直接在向导中添加你的代码基于点击 'Yes' 或 'No' 按钮,你计划在 def return_confirmation
.
嗯,这是我写的:
@api.multi
def yes(self):
print 'yes function'
self.env['tjara.purchase_order'].function1()
@api.multi
def no(self):
print 'no function'
self.env['purchase_order'].function1()
'canceled_progressbar'方法return:
@api.multi
def canceled_progressbar(self):
print 'canceled_progressbar'
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 function1(self):
print 'this function 1'
@api.multi
def function2(self):
print 'this function 2'
我想知道我是否只能实现一个功能,但似乎不可能。
谢谢大家的帮助。
您可以添加:
confirm="Your Custom message like Are you sure you want to process this?"
在 xml 中的按钮。