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.


Where are the 'vals' coming from?

on 12/10/13, 8:54 PM 1,378 views


OK I really must post a disclaimer before asking because this is a really basic question but as I am learning python and OpenERP I can't seem to figure it out and its taking me forever.

I am trying to understand some custom code I requested from a developer. Basically what I need is to add some values to a variable called vals, but I look and I look and I can't find where is vals initially created or where it is getting its contents from.

Here is the code of the class I am working with:

class guest_amenities_vals(osv.osv):
    _name = "sim.guest_amenities_vals"
    _description = "GuestAmenitiesVals"
    _columns = {

        'name': fields.char('Name',required=True),
        'cols': fields.many2one('sim.resumen_wizard','Order Reference', required=True, ondelete='cascade', select=True),
        'price': fields.float('Price'),
        'period': fields.float('Period')
    _defaults = {
        'price' : 0,

    def create(self, cr, uid, vals, context=None):
        print vals
        print "------------"
        if 'cols' in vals and 'name' in vals:
            existing_recs = self.search(cr, uid, ['&',('cols','=',vals['cols']),('name','=',vals['name'])], context=context)
        if not existing_recs:
            return super(guest_amenities_vals, self).create(cr, uid, vals, context=context)
            ids = existing_recs[0]
            if ids:
                super(guest_amenities_vals, self).write(cr, uid,[ids], vals, context=context)
                print vals
                return ids


From what I could debug the code gets executed when the user clicks on a 'Print' button from a wizard.

Vals has something like this {'price': 3000, 'name': 'b', 'cols': 116L}

What I am trying to do is also add the Period to vals so I can insert it into de DB

So the question is how would you look for were vals is initialized so I can pass the value of period to this class and insert it into the DB like the rest of the fields?

Please again excuse me if this is super basic. I spent a lot of time digging into the code and can't find it so any clue on where to look or what to look for will be deeply appreciated.

Hi, vals is dictionary its contains Key and Value. Here Key is the field name of the table. Vals value coming from the form entered Field value. You can pass the value of period For example, vals['period'] = Your_value

on 12/11/13, 1:21 AM

Oh! thats why I couldn't find it! (sorry, super new with python). So basically if I enter more fields in the form the values will appear in vals, right?

on 12/11/13, 8:33 AM

Yes In the create methods vals contains table column name and value. If more fields added in shows in the vals

on 12/11/13, 8:40 AM
On 12/12/13, 3:49 AM

You must inherit related view in your xml file that refer to "sim.guest_amenities_vals" model and add period field.

<field name="period"/>

Please read article(s) about inheriting openerp view for more explanation.

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: 12/10/13, 8:54 PM
Seen: 1378 times
Last updated: 3/16/15, 8:10 AM