Jihane Hemicha
Jihane Hemicha

Reputation: 165

Show records on TreeView that are related to Active User

I'm Trying to show records based on the active user, My task_submission.py

 class TaskSubmission(models.Model):
        _name = 'training_program_management.task_submission'
        solution_description = fields.Html(string="Task submission's Description", required=True)
        partner_id = fields.Many2one('res.partner', string='trainee: ',
                                     default=lambda self: self.env.user.partner_id.id, readonly=True)
        task_id = fields.Many2one('project.task', readonly=True, string="submitting Task :")
        project_id = fields.Many2one(related="task_id.project_id", string="Practical work ", readonly=True)

In TreeView i need to show only task submissions with Partner_id= current_user_id.partner_id I tried this but it doesn't seem to be working:

<record model="ir.actions.server" id="mysub_task_action">
        <field name="name">My Task submissions</field>
            <field name='model_id' ref='training_program_management.task_submission'/>
             <field name="state">code</field>
            <field name="code">
                action = {
                    'type': 'ir.actions.act_window',
                    'name': 'My task submissions',
                    'view_mode': 'tree',
                    'view_type': 'tree',
                    'view_id': env.ref("training_program_management.mysub_task_tree_view").id,
                    'context': '{ "tree_view_ref":"mysub_task_tree_view"}',
                    'res_model': 'training_program_management.task_submission',
                    'views': [(env.ref('training_program_management.mysub_task_tree_view').id, 'tree')],
                    'domain' : '[("partner_id", "=","user.id.id_partner.id")]',
                }
            </field>
        </record>

Does anyone have an idea of how to do it ?

Upvotes: 0

Views: 645

Answers (1)

Unatiel
Unatiel

Reputation: 1080

It doesn't work because you mustn't use quotes around user.id.id_partner.id in your domain : user is actually a python object you can use in domains.

'domain' : '[("partner_id", "=", user.partner_id.id)]',

Should work.

Upvotes: 1

Related Questions