It is currently Mon May 21, 2012 7:19 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to call a function when I press a button ??
PostPosted: Tue Apr 12, 2011 3:58 pm 
Offline

Joined: Tue Feb 15, 2011 2:18 pm
Posts: 26
Hello.
I'm making a new module, and the view I have a button that calls a function passed as parameter a char field. My intention is that when I press the fill another field with the description of the field that I pass as a parameter. The problem I have is that I have not made ​​any button so far and I do not work well. I think the view I have no right to call the method declared "generar_nombre_producto" or that the .py, in the function declaration, I haven't the code correctly.

My code is as follows:

Code:
.......
         <field name="inherit_id" ref="product.product_normal_form_view"/>
         <field name="type">form</field>
         <field name="arch" type="xml">
            <field name="categ_id" position="replace">
                   <field name="categ_id" on_change = "onchange_categ_id(categ_id)"/>   
               </field>
            <xpath expr="/form/notebook[@colspan='4']/page[@string='Information']" position="after">
                 <page string="Información 2">
                     <group colspan="6" col="6">
                      ............
                      <field name="descripcionarticulo" colspan="3"/>
                      <button name="generar_nombre_producto(descripcionarticulo)" string="Generar nombre producto" type="object" icon="icon" colspan="3"/>
                      <field name="campoprueba" colspan="6"/>
                    </group>


and the .py ...

Code:
class product_product(osv.osv):
    _inherit = 'product.product'
    _name = 'product.product'
   
    .....

    _columns = {
        ......
        'descripcionarticulo' : fields.char('Descripción adicional', size=128),
        'campoprueba' : fields.char('campo prueba', size=256),
    }
   
    def generar_nombre_producto(self, cr, uid, ids, descripcionarticulo_param):
        descripcionarticulo_obj = self.pool.get('product.descripcionarticulo')
        descripcionarticulo = descripcionarticulo_obj.browse(cursor,user,[descripcionarticulo_param])[0]
        #####descripcionarticulo_obj = self.browse(cr, uid, ids)
        #####descripcionarticulo = self.read(cr, uid, ids, ['product_id'],context)
       
        values = {}
       
        values = {'campoprueba' : descripcionarticulo}
        return {'value': values}
   
product_product()


I hope I have specified either my problem. Sorry for my English.

Anyone can help me??


Top
 Profile  
 
 Post subject: Re: How to call a function when I press a button ??
PostPosted: Wed Apr 13, 2011 3:08 pm 
Offline

Joined: Mon Jan 10, 2011 11:08 am
Posts: 78
Hi..

You can call a function from Button, but i beileve it should be parameterless function...

If i am right, you want to fill the field "campoprueba" with the same data as "descripcionarticulo".

If that is the case, then you can go for "On Change Event" method, which is more simpler and easier way..

Here the code will be as follows [In Python]
Code:
    def onchange_producto(self, cr, uid, ids, descripcionarticulo):
        values = {}       
        if not descripcionarticulo:
            return {}       
        values = {'campoprueba' : descripcionarticulo}
        return {'value': values}


then [In XML]
Code:
<group colspan="6" col="6">                     
  <field name="descripcionarticulo" colspan="3" on_change="onchange_producto(descripcionarticulo)"/>       
  <field name="campoprueba" colspan="6"/>
<group>


Hope this helps..

Note: You can browse through the standard modules for examples on this
[hint: Use Ctrl + H for searching]


Top
 Profile  
 
 Post subject: Re: How to call a function when I press a button ??
PostPosted: Wed Apr 13, 2011 3:43 pm 
Offline

Joined: Tue Feb 15, 2011 2:18 pm
Posts: 26
Thanks for your input deep.
The method "onchange" I've used it before and it works perfectly, but I really need to know how to call a function by passing parameters when I press a button.
Anyway thanks again.

Someone has the same problem?? Any help??


Top
 Profile  
 
 Post subject: Re: How to call a function when I press a button ??
PostPosted: Mon May 30, 2011 11:05 am 
Offline

Joined: Thu Mar 31, 2011 8:45 am
Posts: 241
Location: Málaga, Spain
I don't know if this is possible or not, i have the same or similar problem, i want to fill the fields of a form reading the data from the first entry on res_partner, and on_change event it does not fit my requirements.

As far as i know, the only way is creating a workflow, i still need to dig about this.

_________________
Desarrollo Compuservice
Parque Tecnológico de Andalucía


Top
 Profile  
 
 Post subject: Re: How to call a function when I press a button ??
PostPosted: Fri Jul 08, 2011 2:35 pm 
Offline

Joined: Fri May 28, 2010 10:33 am
Posts: 409
Seem we cannot pass arguments on a button function, but, by default, the ids of actual object is passed.

We can use the ids to browse the object and obtain the record and the fields
---------------------------------------
Posiblemente tarde, pero para completar el hilo.

Parece que no puedes pasar argumentos en la función que llamas desde un botón, pero sin embargo si estás pasando el id correspondiente al registro del objeto, con lo que puedes cargarlo y leer los campos guardados.

Vista:
Code:
<field name="empresa_id" />
<button  icon="gtk-ok" name="boton_genera_instalaciones_detalles" string="Genera detalles" type="object"/>


Código:
Code:
def boton_genera_instalaciones_detalles(self,cr,uid,ids,context):
    detalles_obj =    self.pool.get('mantenimientos.instalaciones').browse(cr,uid,ids)
    print '--------self.empresa_id', detalles_obj[0].empresa_id.name
...


Un saludo
Juanjo A

_________________
Formación online OpenERP - Programación módulos - Apoyo instalación
http://www.malagatic.com @malagatic


Top
 Profile  
 
 Post subject: Re: How to call a function when I press a button ??
PostPosted: Wed Jul 20, 2011 2:35 pm 
Offline

Joined: Thu Oct 28, 2010 1:51 pm
Posts: 53
Have you tried sticking a context in and then pulling your args out of that?
context="{'somefieldinview':somefieldinview}"

_________________
Developing OpenERP Modules for what seems like an eternity
Smart IT Ltd
http://www.smart-ltd.co.uk


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP