Search code examples
databaseodoouser-inputsql-insertopenerp-7

insert into database the input fields


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

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>

I have an image if you could help see here

http://help.openerp.com/question/46472/insert-into-database-the-input-fields/


Solution

  • I resolved this problem....

    <group string=" ">
    <field name="code"/>
    <field name="name"/>
    <field name="nameBilhetes"/>
    <field name="recinto_id" on_change="insert_piso(code,name,nameBilhetes,recinto_id)"/>   
    </group>
    

    I use the on change method and on the .py i use

    I query to insert into the Database.

    Please mark this answer with the tick this solution resolve my problem