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.


how to set multiple default value using function?

on 5/17/16, 12:53 AM 507 views

i don't want to write multiple time.

_defaults = {

'extra_cleaning_hourly_rate': lambda self, cr, uid, c: self.pool.get('res.company').browse(cr, uid, uid, c).extra_cleaning_hourly_rate,

'extra_cleaning_hourly_rate_material': lambda self, cr, uid, c: self.pool.get('res.company').browse(cr, uid, uid, c).extra_cleaning_hourly_rate_material,

'extra_cleaning_hourly_rate_material': lambda self, cr, uid, c: self.pool.get('res.company').browse(cr, uid, uid, c).window_cleaning_hourly_rate,


it's not making sense , extra_cleaning_hourly_rate_material can have to two default on the basis on "certain condition" (so apply that condition in one lambda )

Prakash Sharma
on 5/17/16, 1:34 AM

Anil R. Kesariya

--Anil R. Kesariya--
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
Technical & Functional Expert
Anil R. Kesariya
On 5/17/16, 3:01 AM

Hi Vijay,

Here you go!

- override the default_get method to achieve this.

 in dictionary you have to pass key as your field name for which you want to set default value, would your updated value for that field.

def default_get(self, cr, uid, ids, context=None):
    # Either prepare your dictionary here to update in result dictionary    
    result = super(class_name, self).default_get(cr, uid, ids, context=context) # or directly update your result dictionary with new fields value to be updatr    return result

def default_get(self, vals):
#update dictionary with default fields
    result = super(product_new_revision, self).default_get(vals)
#Update dictionary with default fields
    return result
eg. Update dictionary value in this format -> {'field_name': 'default value'}

Hope this will help.




Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
| 5 3 5
--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 5/17/16, 1:58 AM


You can use the default_get method it returns a dict mapping fields names with their default values.

You can also check an example here 

Hope this could help

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

1 follower(s)


Asked: 5/17/16, 12:53 AM
Seen: 507 times
Last updated: 5/17/16, 4:58 AM