Odoo Help


How do you use _defaults in the new API?

on 2/12/16, 4:32 AM 845 views

How can you do this:

_defaults = { 'sale_order_id': lambda self, cr, uid, context: context.get('sale_order_id', False), }

In the new API?

Krupesh Laiya
On 2/12/16, 4:37 AM

You can use it while defining new field:

 user_id = fields.Many2one('res.users', string='Salesperson', track_visibility='onchange',

readonly=True, states={'draft': [('readonly', False)]},

default=lambda self: self.env.user)


Hiral Patel (hip)

--Hiral Patel (hip)--
Hiral Patel (hip)
| 2 1 5
--Hiral Patel (hip)--

Hiral Patel (hip)
On 2/12/16, 4:53 AM

In new API, you can define default at field level.

Try this:

sale_order_id = fields.Many2one('sale.order', default=lambda self: self.env.context.get('sale_order_id', False))

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


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)


Asked: 2/12/16, 4:32 AM
Seen: 845 times
Last updated: 2/12/16, 4:53 AM