Skip to Content
Menu
This question has been flagged
2 Replies
3699 Views

Hi all


i added  a many2many field on timesheet view which display all the project available on timesheet line.


this is the code :

project_ids = fields.Many2many('project.project', relation='timesheet_project_rel', string='Project',

                                   compute='_get_default_project')



    @api.depends('line_ids.project_id')

    def _get_default_project(self):

        project_ids = []

        lst = []

        for sheet in self:

            for rec in sheet.line_ids:

                project_ids.append(rec.project_id.id)

            sheet.update({'project_ids': [(6, 0, project_ids)]})


and on xml :

<filter string="List Of project" name="groupby_project_ids" domain="[]"

                        context="{'group_by':'project_ids'}"/>

But i'm  getting an error on filter of the list project because we can not group by many2many fields 

Can any have another solution for help me ?


thanks in advance.

Avatar
Discard
Best Answer

it can be possible with the compute field but if value is two in m2m field then it will show by comma (,) like project1, project2

try this code,

project_names = fields.Char ('Project Names', compute = "compute_project_names", store = True)

@ api.depends (project_ids')

    def compute_project_names (self):

        for rec in self:

            if rec.project_ids:

                project_names = ',' .join ([p.name for p in rec.project_ids])

            else:

                project_names = ''

            rec.project_names = project_names

on the xml file:

<filter string = "Project" name = "project" context = "{'group_by': 'project_names'}" />

hope it's work for you.

disha.

Avatar
Discard