This question has been flagged
1 Reply
9046 Views

Hi everybody,

I am creating a filter avec the context based on the many2one field but I get an error.

More details : I would like to get a list of task works and group them by task_id and project_id.

  • So I created a menu item and search view based on project.task.work model.
  • This model has task_id field so I created the filter based on it and everything is going correctly
  • But the object doesn't have project_id field so when I try do write a filter base on project_id like this:

 <filter string="Project" name="project" icon="terp-folder-violet" context="{'group_by':'task_id._project_id'}"/>

I get this error :

AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True

Any help?

thanks

Avatar
Discard
Best Answer

The error message explains the problem explicitly, i.e. the field you want to use for groupby (task_id.project_id) is not stored in project.task.work model.  If the requirement is to group by Project, then you need to do:

  1. Create a related field in project.task.work to hold the project_id of task_id and make it stored (e.g 'project_id' : fields.related('task_id', 'project_id', type='many2one', relation='project.project', store=True)
  2. After restarting and upgrading to initiate the new field, use that field instead in the groupby context.
Avatar
Discard
Author

Hi Jonh, I did it like you said. It is working correctly. Thanks