Odoo Help


How do you use _defaults in the new API?

on 2/12/16, 4:32 AM 1,416 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)
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))

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: 1416 times
Last updated: 2/12/16, 4:53 AM