Add search_context for specific model on a Reference field

In a model I have a Reference field to link different records from different models. This works as expected. But now I want to filter down the list of records for a specific model.

So when a user select as Model ‘project.work’ (Work Effort) I want to filter out all the ‘project.work’ records which has state ‘done’. Because I don’t need them. But for other models this should not happen because some of them don’t have a field state and will fail.

Is this possible? And if so, any example available?

Thanks.

Yes, you should build a domain that depends on the target module. There is an example implemented on the sale_compaint module.

Hope it helps!

It worked perfectly! Thanks!

1 Like