Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
7636 มุมมอง

Hello,

I have a button in the crm form view. When I click this button I want to open a wizard with 2 buttons: YES or NO.

When the user click yes button the yes() function is executed, if the user click no button the no() function is executed.

How to do that?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,
1. You can open a wizard by adding the below code inside the function of button click .
For example here the function is action_open_wizard.

def action_open_wizard(self):
    return {
        'name': "Test Wizard",
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'test.wizard',
        'view_id': self.env.ref('test_module.test_wizard_view').id,
        'target': 'new',
            }

2. To create a wizard first create a new transient model and add necessary fields to it. Then create a view for the wizard.
For example here I am given the python code and xml code for the above:

class GenTestWizard(models.TransientModel):
        _name = "test.wizard"
        _description = 'Testing of wizard'
        msg = fields.Text(string="Test message", default="Do you want to continue?",readonly=True)
       
        def yes(self):
            print("yes")

        def no(self):
            print("no")

in .xml

        <record id="test_wizard_view" model="ir.ui.view">


            <field name="name">Test wuzard</field>


            <field name="model">test.wizard</field>


            <field name="arch" type="xml">


                <form string="Warning">


                    <group>


                        <field name="msg" nolabel="1"/>


                    </group>


                    <footer>


                        <button name="yes" string="Ok" type="object" class="oe_highlight"/>


                        <button name="no" string="Cancel" type="object" class="oe_highlight"/>


                    </footer>


                </form>


            </field>


        </record>


        <record id="test_wizard_action" model="ir.actions.act_window">


            <field name="name">Test Wizard</field>


            <field name="res_model">test.wizard</field>


            <field name="view_id" ref="test_wizard_view"/>


            <field name="view_mode">form</field>


            <field name="target">new</field>


        </record>


To know more about wizard creation, you can refer to the below mentioned blogs.

1. https://www.cybrosys.com/blog/how-to-create-manage-wizard-in-the-odoo-15
2. https://www.cybrosys.com/blog/how-to-create-wizard-in-odoo-13

Hope it helps

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Check this out:
https://stackoverflow.com/questions/43983595/odoo-10-call-a-confirmation-form-yes-no-from-wizard

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ธ.ค. 24
785
4
มี.ค. 19
9204
How to connect button with function? แก้ไขแล้ว
3
ธ.ค. 23
19333
2
พ.ค. 16
12858
2
มี.ค. 15
3991