user1540295
user1540295

Reputation: 39

create a button on product form in openerp

I am trying to create a button on product form. here is my xml

<record id="action_button" model="ir.actions.server">
    <field name="type">ir.actions.server</field>
    <field name="condition">True</field>
    <field name="state">code</field>
    <field name="model_id" ref="product_normal_form_view"/>
    <field eval="5" name="sequence"/>
    <field name="code">action=self.action_button(cr,uid, context)</field>                                                                                                       
</record>

=================

button defined as

<group col="2" colspan="2">
    <button name="%(action_button)d" type="action"  string="Test Hello"/>
</group>

in python file there is a method action_button

 def action_button(cr,uid,context):
        test={}
        modelname="Hello Usha"
        test['tryhello']=modelname
        return{'value':test}

=============

on button click i get error, no attribute defined on temp_range for action_button

pl. help, thanks in advance

-Usha

Upvotes: 1

Views: 3253

Answers (2)

Sudhir Arya
Sudhir Arya

Reputation: 3743

I have tried your code and after modification it's working fine and the method is also executing.

    <record id="action_button" model="ir.actions.server">
        <field name="type">ir.actions.server</field>
        <field name="name">Testing</field>
        <field name="condition">True</field>
        <field name="state">code</field>
        <field name="model_id" ref="model_product_product"/>
        <field eval="5" name="sequence"/>
        <field name="code">action=obj.action_button(context=context)</field>                                                                                                       
    </record>


def action_button(self, cr, uid, ids, context=None):
    #your code

Hope this will solve your problem.

Upvotes: 1

user1393412
user1393412

Reputation:

Try below code::

<record id="action_button" model="ir.actions.server">
    <field name="type">ir.actions.server</field>
    <field name="condition">True</field>
    <field name="state">code</field>
    <field name="model_id" ref="product_normal_form_view"/>
    <field eval="5" name="sequence"/>
    <field name="code">action=self.pool.get('product.product').action_button(cr, uid,  context
    </field> 

and make change also in py file where we the action_button method define

def action_button(self, cr, uid, context=None):
    test={}
    modelname="Hello usha"
    test['tryhello']=modelname
    return{'value':test}

Upvotes: 1

Related Questions