Odoo 10:从Wizard中调用确认表(是/否)

问题描述 投票:0回答:3

我想在我的采购订单中添加“取消”按钮。此按钮会将记录的状态更改为“已取消”。当用户单击此按钮时,脚本将验证所有购买查询和提供商订单(如果尚未执行或取消)。我想添加一个弹出窗口来警告用户。用户可以取消操作或追踪并取消所有相关的查询和订单。

这是我的向导模型:

# -*- 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(弹出窗口),这样我就可以返回值并继续前进。

python openerp odoo-10
3个回答
1
投票

您应该直接从def canceled_progressbar方法返回Action,而不是单独定义它。

此外,我不认为您的方法def return_confirmation将能够通过返回“True”或“False”以您尝试的方式获得值。

在这里,您应该直接在向导中添加代码,方法是单击“是”或“否”按钮,这是您在def return_confirmation中计划的按钮。


1
投票

嗯,这就是我写的:

    @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'方法返回:

    @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'

我想知道我是否只能制作一个功能,但似乎不可能。

谢谢大家的帮助。


0
投票

你可以加:

confirm="Your Custom message like Are you sure you want to process this?"

在xml中的按钮。

© www.soinside.com 2019 - 2024. All rights reserved.