Odoo Help


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.


insert into database the input fields

Francisco Castro
on 3/13/14, 12:04 PM 1,810 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

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

0 follower(s)


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