Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
7119 Переглядів

Hello,

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)
        else:
            ids = existing_recs[0]
            if ids:
                super(guest_amenities_vals, self).write(cr, uid,[ids], vals, context=context)
                print vals
                return ids

guest_amenities_vals()

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

Автор

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?

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

Найкраща відповідь

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.

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
бер. 15
11494
0
бер. 25
1263
4
квіт. 24
173968
0
груд. 23
2031
5
лип. 25
227497