Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to create action to my button of custom openerp module

By
arsalan
on 7/12/13, 5:18 AM 13,156 views

Hi to all . I have been working on developing openerp v-7 module . I have put a button along with fields , and have also created an action to the button . But on clicking the button , it is doing nothing.

here is myform.py

from osv import fields, osv import time

class my_form(osv.osv):

_name = "my.form"
_description = 'Formview Module'
_columns = {
    'name': fields.char('Name', size=64),
    'project': fields.char('Project', size=64),
    'image': fields.binary('Image'),
    'file':fields.binary('attach file')
}

class my_form2(osv.osv):

_name="my.form2"
_description="new form"
_columns={
          'add':fields.char('Address',size=64)
          }

here is myform_view.xml

<openerp> <data>

    <record model="ir.ui.view" id="from_view_form">
        <field name="name">form.view.form</field>
        <field name="model">my.form</field>
        <field name="arch" type="xml">
            <form string="Form" version="7.0">
                <group>
                    <field name="name" />
                    <field name="project" />
                    <button id="add_field" string="Add Field" type="action" />
                </group>
            </form>
        </field>
    </record>



    <record model="ir.ui.view" id="from_view_form2">
        <field name="name">form.view.form</field>
        <field name="model">my.form</field>
        <field name="arch" type="xml">
            <form string="Form" version="7.0">
               <group>
                   <field name="name"/>
               </group>
            </form>
        </field>
    </record>





    <record model="ir.ui.view" id="from_view_tree">
        <field name="name">form.view.tree</field>
        <field name="model">my.form</field>
        <field name="arch" type="xml">
            <tree string="Form">
                <field name="name" />
            </tree>
        </field>
    </record>    

    <record model='ir.actions.act_window' id='add_field'>
        <field name="name">Form</field>
        <field name="res_model">my.form</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="context">{}</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to create a new record.
            </p>
            <p>This is a test class developed to learn Openerp.</p>
        </field>
    </record>




    <record model='ir.actions.act_window' id='form_view_action'>
        <field name="name">Form</field>
        <field name="res_model">my.form</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{}</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click to create a new record.
            </p>
            <p>This is a test class developed to learn Openerp.</p>
        </field>
    </record>

    <menuitem id="myform_ID" name="myforms" />

    <menuitem id="myform_menu_ID" name="myform" parent="myform_ID"  />

    <menuitem id="myform_menu2_ID" name="myform" parent="myform_menu_ID"  action='form_view_action' />

</data>

</openerp>

2
Alessandro Pillan
On 7/12/13, 6:37 AM

You should use name attribute instead of id in your button

name='%(add_field)d'

This answer is backed up by the official documentation. See http://openerp-server.readthedocs.org/en/latest/03_module_dev_03.html#button and https://doc.openerp.com/trunk/server/form-view-guidelines/

Devvyn Murphy
on 2/14/14, 4:50 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 7/12/13, 5:18 AM
Seen: 13156 times
Last updated: 3/16/15, 8:10 AM