Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
876 Widoki

In my (inherited) crm.lead model, I have a one2many field called presales_ids.

I want all presales_ids records to visible to all users who have access to the lead.

However, in the presales model list view, I want to restrict the visibility of records based on the user group. Using record rules will hide these records from the presales users viewing the lead form as well.

How can I do this?


Odoo v18 Community Edition

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can override the presales_ids field to always fetch data with sudo(), so it ignores record rules when viewed through a Lead:

from odoo import models, fields, api


class CrmLead(models.Model):

    _inherit = 'crm.lead'


    presales_ids = fields.One2many(

        'presales.model',

        'lead_id',

        string="Presales",

        compute="_compute_presales_ids",

        store=False

    )


    @api.depends('id')

    def _compute_presales_ids(self):

        for lead in self:

            lead.presales_ids = self.env['presales.model'].sudo().search([('lead_id', '=', lead.id)])


Hope it helps.

Awatar
Odrzuć
Najlepsza odpowiedź

Use the groups attribute in your view on the field in question, i.e.

<field name="presales_ids" groups="[module].[group_name]"/>
Awatar
Odrzuć
Autor

I don't want to restrict visibility of the one2many presales_ids field on the lead.
I want to restrict visibility of presales records in the list view of the presales model.

Powiązane posty Odpowiedzi Widoki Czynność
1
cze 25
1022
1
cze 25
1159
1
cze 25
877
1
lip 25
899
3
lip 25
1269