Question

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/

Was it helpful?

Solution 2

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

OTHER TIPS

In openerp 7 osv.osv is deprecated you may use orm.Model

Here the guide lines to write a good code for openerp.

the class that you have post is a module class, but if you would write a record with a wizard you need to insert insert_recinto method inside a wizard class and not inside a model class. after in your wizard insert_recinto method you may to write a data in with the orm method like as your_class_object.write(cr,uid,id,vals,context).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top