Odoo 10:从向导中致电确认表格(是/否) [英] Odoo 10 : Call a confirmation form (Yes / No) from Wizard

查看:237
本文介绍了Odoo 10:从向导中致电确认表格(是/否)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的采购订单中添加一个取消"按钮.此按钮会将我的记录状态更改为取消". 当用户单击此按钮时,脚本将验证所有购买查询和提供者订单(如果尚未完成或取消). 我想添加一个弹出窗口来警告用户有关它们的信息.用户可以取消操作或追求,并取消所有相关的查询和订单.

I want to add to my purchase order a 'cancel' button. This button will change the state of my record to 'canceled'. When the user click on this button the script verify all the purchase inquiries and provider orders if there is any one not done or canceled yet. I want to add a pop-up to warn the user about them. The user can cancel the operation or pursuit and cancel all the related inquiries and orders.

这是我的向导模型:

# -*- 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(弹出窗口),因此我可以返回该值并继续.

The model is triggered only when the button is pointed on return_confirmation method. Which make me incapable to pursuit my code. Only a pop-up appear then disappear when the user click on a button. I want to call the return_confirmation (pop-up) via the canceled_progressbar, so I can return the value and moving on.

推荐答案

好吧,这就是我写的:

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

The 'canceled_progressbar' method 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',
        }

然后根据确认我添加了两个功能:

And I added two function according to the confirmation :

    @api.multi
    def function1(self):
        print 'this function 1'

    @api.multi
    def function2(self):
        print 'this function 2'

我想知道我是否只能执行一个功能,但这似乎是不可能的.

I was wondering if I can make only one function but it seems like impossible.

谢谢大家的帮助.

这篇关于Odoo 10:从向导中致电确认表格(是/否)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆