Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
48890 Vizualizări

I have a field many2one relation to res.users like this : 'salesman':fields.many2one('res.users', string='Salesman').

I want default value it field is current user ID (current login) like Administrator, Custom User, etc. How to do it?

Imagine profil
Abandonează
Cel mai bun răspuns

This is so short for getting the current user info:

self.env.user

Imagine profil
Abandonează
Cel mai bun răspuns

@Miftah

under the _defaults you can write the following code

_defaults={

'salesman':lambda self, cr, uid, ctx=None: uid

}

hope this helps !!

Imagine profil
Abandonează

In the 8.0 API this would be something like this: salesman = fields.Many2one( string="Salesman", comodel_name='res.users', default= lambda self: self.env.user.id )

Cel mai bun răspuns

Hello,

You can use below code.

context = self._context

current_uid = context.get('uid')

user = self.env['res.users'].browse(current_uid)

Hope this help you.

Best Thanks,

Ankit H Gandhi.

Imagine profil
Abandonează

thank you very much

Cel mai bun răspuns

Why don't you take a look at sale.order model from odoo/addons/sale/sale.py.  It has user_id defined which - AFAIK - mimics what you need.  It uses _default as well as @Emipro had suggested.

Imagine profil
Abandonează
Cel mai bun răspuns

salesperson = fields.Many2one('res.users', string="Salesperson", default=lambda self: self.env.user)

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 15
8600
2
sept. 21
9852
2
iun. 20
13969
4
nov. 15
6167
1
mar. 15
4930