Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
2504 Visualizzazioni

I want to make all the data only show to admin. If it's not admin, only the assigned data will be shown

So the condition will be

( ('user_ids', 'in', uid) OR ('access_user','=', 'admin') ) AND ('proposal_type', '=', 'video_surveillance')


I make a function that compute and depends on itself because I think that's the only way to make the fields compute every time I open tree view

    
    access_user = fields.Selection(
        string='Access user',
        selection=[
            ('-', '-'),
            ('tech', 'Tech'),
            ('user', 'User'),
            ('adv', 'ADV'),
            ('admin', 'Admin')], compute='_compute_access_user')

    @api.depends('customer_id','access_user')
    def _compute_access_user(self):
        if self.env.user.has_group('configurator.group_parameter_user'):
            if self.env.user.has_group('configurator.group_parameter_adv'):
                if self.env.user.has_group('configurator.group_parameter_administrator'):
                    self.access_user = 'admin'
                else :
                    self.access_user = 'adv'
            else :
                self.access_user = 'user'
        else :
            self.access_user_inokap = 'tech'

But then I realize the value is not stored in the database. If I put store=True​, the compute is not executed when I open tree view (this is dilemma)


    <record id="action_videosurveillance" model="ir.actions.act_window">
        <field name="name">Video Surveillance</field>
        <field name="res_model">proposals</field>
        <field name="view_mode">tree,form</field>
        <field name="domain">[
            '|',
            '&amp;',
            ('user_ids', 'in', uid),
            ('access_user','=', 'admin'),
            ('proposal_type', '=', 'video_surveillance')
        ]</field>
        <field name="context">{'default_proposal_type':'video_surveillance'}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                You don't have Video Surveillance yet, let's do it!
            </p>
        </field>
    </record>


After upgrading, the view is getting error because it cannot found field access_user​ (ofc because I didn't put the store=True to make the compute execute every time I visit the treeview).


Then I try put another field but add '2' that I think will be stored when I visit the tree view and I change the compute method

    access_user2 = fields.Selection(
        string='Access user',
        selection=[
            ('-', '-'),
            ('tech', 'Tech'),
            ('user', 'User'),
            ('adv', 'ADV'),
            ('admin', 'Admin')])
    @api.depends('customer_id','access_user')
    def _compute_access_user(self):
        if self.env.user.has_group('inokap_configurator.group_parameter_user'):
            if self.env.user.has_group('inokap_configurator.group_parameter_adv'):
                if self.env.user.has_group('inokap_configurator.group_parameter_administrator'):
                    self.access_user = 'admin'
                    self.access_user2 = 'admin'
                else :
                    self.access_user = 'adv'
                    self.access_user2 = 'adv'
            else :
                self.access_user = 'user'
                self.access_user2 = 'user'
        else :
            self.access_user = 'tech'
            self.access_user2 = 'tech'
           

        <field name="domain">[
            '|',
            '&amp;',
            ('user_ids', 'in', uid),
            ('access_user2','=', 'admin'),
            ('proposal_type', '=', 'video_surveillance')
        ]</field>


The data is stored as expected. But the view still show all data even for non admin


Where is the error here?













Avatar
Abbandona
Risposta migliore

Hi,
How about creating one extra menu and showing that menu only for the admin ? Easily you can achieve the task without much tweaks in the code.

For the menu shown to admin, let the domain be [] so that all the records can be seen and other menu with domain to shown only user related records.


Thanks

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
lug 24
1601
3
mar 15
52154
3
nov 20
6327
3
lug 25
9003
2
gen 25
1018