Reputation: 2358
Is it possible call functin in domain Many2one field?
For example:
time = fields.Many2one('my.time', #call function here)
The time field is populated from database table my_time. In table I have several row:
id name
1 10:00
2 11:00
3 12:00
4. 13:00
In other table my_booked_time, I insert id (1) from time field, now I need filter Many2one "Select all available time (11:00,12:00,13:00)" not 10:00, where user_id = self.user_id and partner_id = self.partner_id
Any simple solution?
Upvotes: 0
Views: 3656
Reputation: 14751
define domain on many2one let say that the my_booked_time
has m2o to table my_time
named time_id
:
m2o_field = fields.Many2one(....,
domain=lambda self: [("id", "not in", self.env['my.booked.time'].search([]).mapped("time_id").ids)])
Upvotes: 2