Skip to Content
Menu
This question has been flagged
3 Replies
6000 Views

I'm trying to create a wizard.

This is the view code:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_mymodule_wizard_form" model="ir.ui.view">
<field name="name">Wizard</field>
<field name="model">mymodule.wizard</field>
<field name="arch" type="xml">
<form string="mymodule Wizard">
<sheet>
<group name="top">
<group name="left">
<h1>Demo Wizard</h1>
</group>
<group name="right">
<button type="object"
name="crea_servizio"
string="Crea Servizio"/>
<button type="object"
name="crea_attivita"
string="Crea Attivita"/>
</group>
</group>
</sheet>
<footer>
<button string="cancella" special="cancel"/>
</footer>
</form>
</field>
</record>

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

<field name="name">Selezione link</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">mymodule.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<!-- Action to open To-do Task list -->
<act_window id="action_mymodule_wizard" name="Attività / Servizio" res_model="mymodule.wizard" view_mode="tree,form" />
<!-- Menu item to open To-do Task list -->
<menuitem id="menu_mymodule_wizard" name="Menu mymodule Wizard" parent="mail.mail_feeds" sequence="40" action="action_mymodule_wizard" />

</data>
</openerp>

and this is the py file:

# -*- encoding: utf-8 -*-
from openerp import models, api

class wizard(models.TransientModel):
_name = 'mymodule.wizard'
_description = "Wizard per la scelta dell'azione"

@api.multi
def crea_attivita(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'mymodule.tbl_attivita',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',
}

def crea_servizio(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'mymodule.tbl_servizio',
'view_type': 'form',
'view_mode': 'form',
'target': 'new',
}

This is mymodule.py:

# -*- encoding: utf-8 -*-
from openerp import models, fields

class mymodule_attivita(models.Model):
_name = 'mymodule.tbl_attivita'
_description = 'Tabella Attivita'

scode_attivita_contr = fields.Char('Code', size=1, required=True)
sdescrizione = fields.Text('Descrizione', equired=True)

class mymodule_servizio(models.Model):
_name = 'mymodule.tbl_servizio'
_description = 'Tabella Servizio'

scode_servizio = fields.Char('Code', size=1, required=True)
sdescrizione = fields.Text('Descrizione', required=True)

I have two problems.

1) When I click on "Crea servizio" in the wizard, I get this error:

Traceback (most recent call last):
File "/home/openerp/openerp/http.py", line 530, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/openerp/openerp/http.py", line 567, in dispatch
result = self._call_function(**self.params)
File "/home/openerp/openerp/http.py", line 303, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/openerp/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/home/openerp/openerp/http.py", line 300, in checked_call
return self.endpoint(*a, **kw)
File "/home/openerp/openerp/http.py", line 796, in __call__
return self.method(*args, **kw)
File "/home/openerp/openerp/http.py", line 396, in response_wrap
response = f(*args, **kw)
File "/home/openerp/openerp/addons/web/controllers/main.py", line 953, in call_button
action = self._call_kw(model, method, args, {})
File "/home/openerp/openerp/addons/web/controllers/main.py", line 941, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
TypeError: crea_servizio() takes exactly 1 argument (5 given)

Instead, everything is ok with the other button (Crea Attivita).

2) I'm not able to make an action when I click on "Crea Attivita". I see the module 'mymodule' in the pop up, but I don't know I I have to do for writing in the db.

This is mymodule_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_mymodule_attivita" model="ir.ui.view">
<field name="name">mymodule Attivita</field>
<field name="model">mymodule.tbl_attivita</field>
<field name="arch" type="xml">
<form string="mymodule Attivita">
<sheet>
<notebook>
<page string="Tab 1">
<group name="top">
<group name="left">
<field name="scode_attivita_contr"/>
<field name="sdescrizione"/>
</group>
</group>
</page>
<page string="Tab 2">
<group name="top">
<group name="left">
<field name="id" attrs="{'invisible': [('write_date', '=', False)]}"/>
<field name="write_date" attrs="{'invisible': [('write_date', '=', False)]}"/>

</group>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record id="view_mymodule_servizio" model="ir.ui.view">
<field name="name">mymodule Servizio</field>
<field name="model">mymodule.tbl_servizio</field>
<field name="arch" type="xml">
<form string="mymodule Servizio">
<sheet>
<group name="top">
<group name="left">
<field name="id" attrs="{'invisible': [('write_date', '=', False)]}"/>
<field name="write_date" attrs="{'invisible': [('write_date', '=', False)]}"/>
</group>
<group name="left">
<field name="scode_servizio"/>
<field name="sdescrizione"/>
</group>
</group>
</sheet>
</form>
</field>
</record>

<!-- Action to open To-do Task list -->
<act_window id="action_mymodule_attivita" name="Attivita" res_model="mymodule.tbl_attivita" view_mode="tree,form" />
<act_window id="action_mymodule_servizio" name="Servizio" res_model="mymodule.tbl_servizio" view_mode="tree,form" />
<!-- Menu item to open To-do Task list -->
<menuitem id="menu_mymodule_attivita" name="Menu mymodule Attivita" parent="mail.mail_feeds" sequence="20" action="action_mymodule_attivita" />
<menuitem id="menu_mymodule_servizio" name="Menu mymodule Servizio" parent="mail.mail_feeds" sequence="30" action="action_mymodule_servizio" />

</data>
</openerp>

Could you help me, please?

Avatar
Discard
Best Answer

Always create transiant model for wizard.

class wiz_form(models.TransientModel):

_name = 'wiz'

tname=fields.Char('Name 1')

pname= fields.Char('Name 2')

state = fields.Selection([('step1', 'step1'),('step2', 'step2')])


@api.multi

def action_next(self):

 return True


@api.multi

def action_previous(self):

return True

Proceed your xml part like this.


<?xml version='1.0' encoding='UTF-8'?>

<openerp>

<data>

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

<field name="name">wiz.form</field>

<field name="model">wiz</field>

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

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

<form string="Wizard with step" version="7.0">

<sheet>

<group>

<field name="tname" />

<field name="pname" />

<field name="state" />

</group>

</sheet>

<footer>

<button name="action_next" string="Next" type="object" />

<button name="action_previous" string="Previous" type="object"

class="oe_highlight" />

</footer>

</form>

</field>

</record>

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

<field name="name">wiz.form</field>

<field name="res_model">wiz</field>

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

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

</record>

</data>

</openerp>

Dont forget to create init file for wizard..

and dnt forget to import in main init.pls try it for your case and put it in openerp data[''wizard/wiz.xml'] top most end

Avatar
Discard
Author

Thank you for your help. I need some explanation. First of all, I haven't understood if I have to raplace my wizard.py and wizard_view.xml files with yours. Then, What I have to set as "step1" and "step2"?

Best Answer

1. Put @api.multi before your method.

2. Try to add:

"view_id": self.env.ref("mymodule.view_mymodule_attivita"),

to the dictionnary returned by the crea_attivita method.

Avatar
Discard
Author Best Answer

Thank you!

Any advice about the other problem?

Avatar
Discard