Odoo Help

0

How does vals.get('xxx','yyy') work?

By
Nicolás Mena
on 5/26/17, 1:19 PM 708 views

I'm trying to figure how the .get works, i'm looking the code from sale.py and how the sequence is added to any saleOrder and trying to understand this.

if vals.get('sequence','New') == 'New':

As I understand the vals.get('sequence') will return the value from the sequence field.  But I don't know and I didn't find information about the use of the other parameters and how gets compared with the string "New" (Or if is a reserved word for a new register).

That New is used after in the value assignation for the 'sequence' field, as the following code shows.

 if vals.get('sequence','New') == 'New':
                vals['sequence']    =   self.env['ir.sequence'].next_by_code(sequence_name) 
                result              = super(feature,self).create(vals)
                return result

Hope you can help me with my question.

Regards.

4
Janeesh
On 9/24/17, 5:17 AM

If the dictionary vals has a key 'xxx', then it will return vals['xxx']. If the dictionary doesn't have a key 'xxx', then 'yyy' will be returned.

1
Ray Carnes
On 5/26/17, 9:28 PM

vals is just a standard Python dictionary.

dict.get(key, default=None)

used with key - it will return the value that matches

used with default - it will return the value that matches, or the default (None)


In the example you have posted, vals.get('sequence','New') will return the value of the key sequence, or New.  So: the code checks if there is a sequence key in vals, and if there isn't, creates one, and calls super after putting the newly created value into vals.


https://www.odoo.com/documentation/10.0/reference/orm.html

https://www.tutorialspoint.com/python/dictionary_get.htm

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/26/17, 1:19 PM
Seen: 708 times
Last updated: 9/24/17, 5:18 AM