Skip to Content
Menu
This question has been flagged
2 Replies
5358 Views

Hello,

I have a button, which call a wizard when we click on it. The button function was declared as follows:

@api.multi

                  def call_confirmation_wizard(self):

                      return {

                          'name': 'Confirmation',

                          'type': 'ir.actions.act_window',

                          'view_type': 'form',

                          'view_mode': 'form',

                          'res_model': 'affichage2.wizard_confirmation',

                          #'res_id': self.id,

                          #'view_id': self.env.ref("affichage2.confirm_wizard_form").id,

                          'view_id': False,

                          'target': 'new',

                          'nodestroy': True,

                      }


This Wizard call function from the previous class, as follows :


class Wizard_confirmation(models.TransientModel):

    _name = "affichage2.wizard_confirmation"

    @api.multi

    def call_vente(self):

        self.env["affichage2.vente_packs"].vendre_cap()


In the XML, the wizard is defined as follows:


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

            <field name="name">affichage2.wizard_confirmation.form</field>

            <field name="model">affichage2.wizard_confirmation</field>

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

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

                <form string="Confirm dialog">

                    <group>

                       <label string="Êtes vous sur de vouloir mettre ce produit en vente?"/>

                    </group>

                    <group>

                      <ul>

                          <li>Valeur actual</li>

                          <li>Valeur min</li>

                          <li>Valeur max</li>

                          <li>Le temps de valeur min</li>

                          <li>Le temps de valeur max</li>

                      </ul>

                    </group>

                    <footer>

                        <button class="oe_highlight" type="object" name="call_vente" string="Yes" />

                        <button string="Cancel" class="oe_link" special="cancel" />

                    </footer>

                </form >

            </field>

        </record>


The problem is a get an erreur when i cliking in Yes from the wizard.

Any help please?


Avatar
Discard
Best Answer

Hello Zakaria,

I hope you are doing well.

The button in your XML wizard calls call_vente, but the method in your Python code is named call_sales. These names must match. Rename the method in Python to call_vente
@  api.multi

    def call_sales(self):  # Please Changed method name

        ​self.env["affichage2.vente_packs"].vendre_cap()

I hope this msg finds you well.

Thanks & Regards,
Kunjan Patel

Avatar
Discard
Best Answer

For those who (also) found this through Google, this is how I create a Yes/No wizard:

The view:

<?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">mymodule.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" type="object" string="Yes"/>
<button class="oe_highlight" name="no" type="object" string="No"/>
</footer>
</form>
</field>
</record>
</data>
</odoo>

The model:

# -*- coding: utf-8 -*-

from types import FunctionType

from odoo import models, fields, api

class confirm_wizard(models.TransientModel):
_name = 'mymodule.confirm_wizard'

yes_no = fields.Char(default=lambda self: self.env.context.get('confirmation_message'))

def get_return_method(self) -> FunctionType:
rtn_class = self.env[self.env.context.get('return_class')]
record_id = self.env.context.get('record_id')
rtn_object = rtn_class.browse([record_id])
return getattr(rtn_object, self.env.context.get('return_method'))

def yes(self):
method = self.get_return_method()
method(result=True)

def no(self):
method = self.get_return_method()
method(result=False)

The context:

return {'name': 'Confirmation dialog',
'type': 'ir.actions.act_window',
'res_model': 'mymodule.confirm_wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
'context': {'confirmation_message': 'This is a custom message to ask yes or no for ?',
'return_class': 'mymodule.myclass',
'return_method': 'mynextmethod',
'record_id': self.ids[0]}}
Avatar
Discard