콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
49499 화면

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?

아바타
취소
베스트 답변

This is so short for getting the current user info:

self.env.user

아바타
취소
베스트 답변

@Miftah

under the _defaults you can write the following code

_defaults={

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

}

hope this helps !!

아바타
취소

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 )

베스트 답변

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.

아바타
취소

thank you very much

베스트 답변

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.

아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
1
3월 15
8840
2
9월 21
10161
2
6월 20
14286
4
11월 15
6499
1
3월 15
5121