5

I'm trying to launch a wizard from an action called from a button in OpenERP. I can launch the wizard using a side menu button just fine, but whenever I use the action in a button, I just get a couple of refreshes, without the new form opening up.

The wizard is pretty basic. Here is the code:

wizard.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>


        <record id="view_res_partner_add_terminal_wizard" model="ir.ui.view">
            <field name="name">res.partner.terminal.form</field>
            <field name="model">res.partner.terminal</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Add terminal">
                    <group colspan="4" >
                        <separator string="Select terminals to assign" colspan="4"/>
                        <field name="terminal_id" string="Terminals" domain="[('state','=','available')]"/>
                        <newline/>
                    </group>
                    <separator string="" colspan="4" />
                    <group colspan="4" col="6">
                        <button  icon="gtk-cancel" special="cancel" string="Cancel"/>
                        <button  icon="gtk-ok" name="add_terminal" string="Assign Terminal" type="object"/>
                    </group>
               </form>
            </field>
        </record>

        <record id="action_res_partner_terminal" model="ir.actions.act_window">
            <field name="name">Assign Terminal</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">res.partner.terminal</field>
            <field name="src_model">res.partner</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_res_partner_add_terminal_wizard"/>
            <field name="target">new</field> -->
            <field name="key2">client_action_multi</field>
        </record>

        <act_window id="action_res_partner_terminal_wizard"
                name="Assign Terminal"
                res_model="res.partner.terminal" 
                src_model="res.partner"
                view_mode="form" 
                key2="client_action_multi"
                target="new"
        />


    </data>
</openerp>

And I have the code for the button with:

<button  name="$(universal_account.action_res_partner_terminal_wizard)d" string="Assign Terminal" type="action" />

I've tried putting the straight XML id in there (without the $()d ), and I've tried using either action defined above, all with the same results. I get an error if I put a bad action name, but that's about it. Any ideas of where to go from here?

jordanm
  • 33,009
  • 7
  • 61
  • 76
Dan Lawson
  • 85
  • 1
  • 5

2 Answers2

6

In your button definition replace $(...)d with %(...)d.

XML_ID substitution uses the percentage sign, not the dollar sign.

BTW, you do not need the first act_window. Defining the act_window through record tag will not create the sidebar link; you have to use the shortcut tag <act_window> or add the side bar link with ir_value record. The second act_window (action_res_partner_terminal_wizard) will create the sidebar link and get used for the button action.

dhana
  • 6,487
  • 4
  • 40
  • 63
Mohammad Alhashash
  • 1,543
  • 1
  • 14
  • 30
  • That was exactly the issue! Thanks for clarifying the difference between the two act_windows. I'm sticking with the first one, mainly because I don't want it to show up in the sideview. – Dan Lawson Jul 26 '12 at 16:31
  • Yes @Ali right, Thst the exact issue, but their is no need to defione act_windoe also – ifixthat Jul 27 '12 at 04:27
  • @Ali I am Surprised Why you suggesting wrong doing guidelines over here, this lead Opensource product towards wrong end – ifixthat Jul 30 '12 at 04:27
-2

Your wizard.xml should look like this :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_res_partner_add_terminal_wizard" model="ir.ui.view">
            <field name="name">res.partner.terminal.form</field>
            <field name="model">res.partner.terminal</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Add terminal">
                    <group colspan="4" >
                        <separator string="Select terminals to assign" colspan="4"/>
                        <field name="terminal_id" string="Terminals" domain="[('state','=','available')]"/>
                        <newline/>
                    </group>
                    <separator string="" colspan="4" />
                    <group colspan="4" col="6">
                        <button  icon="gtk-cancel" special="cancel" string="Cancel"/>
                        <button  icon="gtk-ok" name="add_terminal" string="Assign Terminal" type="object"/>
                    </group>
               </form>
            </field>
        </record>


        <record id="action_res_partner_terminal" model="ir.actions.act_window">
            <field name="name">Assign Terminal</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">res.partner.terminal</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="view_res_partner_add_terminal_wizard"/>
            <field name="target">new</field>
        </record>
    </data>
</openerp>

and On View Button Should be Defined like below

<button  name="$(universal_account.action_res_partner_terminal)d" 
         string="Assign Terminal" 
         type="action" 
         help="Assign Terminal"/>

You must Define a XML Id of the ir.actions.act_window on button action instead act_window xml id.

Regards.

ifixthat
  • 6,137
  • 5
  • 25
  • 42
  • the tag is a shortcut, like – Mohammad Alhashash Jul 26 '12 at 07:55
  • @MohammadAli : I would like to remind that act_wondow is linking record it does not behave same as ir.actions.act_window. – ifixthat Jul 26 '12 at 09:00
  • Please correct me if I'm wrong; My understanding from openerp/tools/convert.py that act_window tag inserts normal ir.action.act_window record plus setting ir.value if src_model is defined to add the sidebar action. So, it should be equivalent record for simple actions but you can not use advanced record tag functions like ref or search attributes. – Mohammad Alhashash Jul 26 '12 at 11:37
  • This was how I had it originally set up. Fix ended up being substituting the $ for a %. – Dan Lawson Jul 26 '12 at 16:32
  • @MohammadAli: Certainly technically You are right and chosen right to show the point. But Would like to say you few point 1. act_window is basically designed to add the sidebar event. Must not over rule and violate the coding conventions. 2. when we define action that means we talk about creating a action event which will trigger a view. Yes the first case will also do same job, but their is not sense of violating the coding sense cause that affects the coding all over being OpenSOurce product their has to be consistency of coding in users. hope you understands – ifixthat Jul 27 '12 at 04:51