Odoo Help


insert into database the input fields

Francisco Castro
on 3/13/14, 12:04 PM 3,649 views

HI guys I have two fields code and name I want to insert into the database the user inputs when they fill the form (I use a wizard)


my class is this... but this dont work...

class cria_edita_recinto(osv.osv):

    _description = 'Cria e Edita Recinto'


    _sql_constraints = [
        ('code', 'unique(code)', 'O codigo do recinto deve ser unico')
    _order = 'code'

    def insert_recinto(self,cr, uid,vals, context=None):


        cr.execute("INSERT INTO gs_recintos (code,name) VALUES (%s,'jt')" %(code)) 
        return True

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

       <field name="name">cria.edita.recinto.form</field>

           <field name="model">cria.edita.recinto</field>

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

               <form string="cria edita recinto" version="7.0">
        <group string=" ">
            <field name="code"/>
            <field name="name"/>

                <button name="insert_recinto" string="Configurar Pisos" type="object" class="oe_highlight"/>
                <button string="Cancelar" class="oe_link" special="cancel"/>




image description

I look at the create method, they said the "vals" argument has the input fields record and its a dictionary so it is like key:value but when I go to put the values into a list with the .values() the open shows an error, it says the vals is a list... and when I go to see what is on the list, it only shows one value, diferent of my input.....

If u could help...

Francisco Castro
On 3/14/14, 8:55 AM

the solution is put on the field (xml) the on_change

<group string=" ">
                <field name="code"/>
                <field name="name" on_change="insert_recinto(code,name)"/>


and the function is this

def insert_recinto(self,cr, uid,ids,code,name, context=None):

        cr.execute("INSERT INTO gs_recintos (code,name,active) VALUES ('%s','%s','1')" %(code,name)) 
        return True

pls if anyone see this mark this post has resolved on the tick image.

Francisco Castro
on 3/14/14, 9:03 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/13/14, 12:04 PM
Seen: 3649 times
Last updated: 3/16/15, 8:10 AM