Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
6936 มุมมอง

i have this filed in source module account_voucher

_name = 'account.voucher'


branch_id = fields.Many2one('res.branch', 'Branch', ondelete="restrict",
default=lambda self: self.env['res.users']._get_default_branch())

but this default in the field is not triggering the default branch function and always giving a same branch of admin user. How can i resolve this? i used the debugger in pycharm to track from where it is getting always the same branch and not from current user. any help would be appreciated.

that was the other way i thought of.

Can I pass context in form action based on current user id? for example 

something like this? any way to do this? i want to get user branch 

<field name="context">{'default_branch_id': user.default_branch_id}</field>
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi @hamzashah47

Try to do it like this:

branch_id = fields.Many2one('res.branch', 'Branch', ondelete="restrict", default=lambda self: self.env.user.default_branch_id)
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.พ. 23
8929
2
ก.พ. 22
14588
2
ก.ย. 19
5091
2
มี.ค. 19
13086
2
ก.พ. 24
3213