Odoo Help

Welcome!

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.

0

How do you use _defaults in the new API?

By
E.M.
on 2/12/16, 4:32 AM 661 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?

1
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)

1

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
http://www.odoo.com
913
| 2 1 5
India
--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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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