This question has been flagged
1 Reply
11991 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...

Avatar
Discard
Author Best Answer

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
Avatar
Discard
Author

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