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

insert into database the input fields

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

.py

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

class cria_edita_recinto(osv.osv):

    _name='cria.edita.recinto'
    _description = 'Cria e Edita Recinto'
    _rec_name='code'
    _columns={

            'code':fields.char("Código",size=10),
            'name':fields.char("Designação",size=50)
            }

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


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


        lista=vals.values()
        code=lista[0]


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

cria_edita_recinto()
.xml
<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"/>


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

           </form>

           </field>

    </record>

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

0
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)"/>

                    </group>

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)

Stats

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