Ancient
Ancient

Reputation: 3057

Odoo- Add domain filter on field after creating

I am new to odoo, I have two drop downs in my models, which are loaded from res.users . What i want to do is that when someone select 'Administrator' or any other user in first_approver then that select user should be removed from second_approver drop down

class test(models.Model):
_name = 'test.test'

name = fields.Char()
first_approver = fields.Many2one('res.users')
second_approver = fields.Many2one('res.users')

I think it could be done by adding domain filter on second_approver but i don't know how to update field definition in onChange method

Upvotes: 0

Views: 5695

Answers (2)

user8143840
user8143840

Reputation:

You can apply same domain in xml also. if you add domain in .py(python) file same will be apply in database also.

<field name="first_approver"/>
<field name="second_approve domain="[('id', '!=', first_approver)]"/>

Upvotes: 1

Alpesh Valaki
Alpesh Valaki

Reputation: 1631

If you want domain then apply following

first_approver= fields.Many2one('res.users')
second_approve= fields.Many2one('res.users', domain="[('id', '!=', first_approver)]")

So the first_approver will not display in second_approver field.

Additional field options and other development help can be found in the Odoo Documentation.

Upvotes: 4

Related Questions