If the user already selected a value (list generated from Many2one) in a record, Now I dont want to show that value in the list that is generated from Man2one fields for any new form (records) to avoid same many2one value in two different records
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Hi,
Try to return domain by id not in [list of ids ie, already used in prev records], either you can return domain in onchange.
Can you please post any example, I have no clue how to do this.
@api.onchange('test_domain')
def onchange_test_domain_fiedl(self):
#here use your model to fetch the records
obj = self.search([])
available_ids = []
for i in obj:
# appends the man2one fields idsss
available_ids.append(i.test_domain.id)
return {'domain': {'test_domain': [('id', 'not in', available_ids)]}}
test_domain = fields.Many2one('sale.order', "Testttttttt")
Dont forget to upvote if my answer helps you
Hi Hilar,
Thanks for your Precious time, This is exactly what i wanted.
Thank you sir!
You can restrict selection on field that already selected using _sql_constraints.
_sql_constraints = [ ('many2one_field', 'unique (many2one_field)','This one is already selected.') ]
Thank for the response, but It is not good in term of User Experience, It will be best if we hide that value before showing error to user
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Nov 22
|
14647 | ||
|
3
Aug 22
|
10754 | ||
|
2
Aug 22
|
3045 | ||
|
0
Jul 22
|
835 | ||
Many2one field doesn't exist
Solved
|
|
2
Oct 21
|
1435 |