Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
6930 Weergaven

I try to add a custom Boolean field to model res.users and put it on the User Preferences Form. The problem is that normal users have no rights to change this field on saving. Any idea howto deal with this?


Sorry, you are not allowed to modify this document. Only users with the following access level are currently allowed to do that:
- Administration/Access Rights
(Document model: res.users) 


from odoo import models, fields
class ResUsers(models.Model):
    _inherit = 'res.users'
    sidebar_visible = fields.Boolean("Show App Sidebar", default=True)


<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="res_users_preferences" model="ir.ui.view">
        <field name="name">res.users.preferences</field>
        <field name="model">res.users</field>
        <field name="inherit_id" ref="base.view_users_form_simple_modif" />
        <field name="arch" type="xml">
            <xpath expr="//group[last()]" position="after">
                <group name="App Sidebar">
                    <field name="sidebar_visible" readonly="0"/>
                </group>
            </xpath>
        </field>
    </record>
</odoo>
Avatar
Annuleer
Auteur Beste antwoord

Working solution:

def __init__(self, pool, cr):
        """ Override of __init__ to add access rights on notification_email_send
            and alias fields. Access rights are disabled by default, but allowed
            on some specific fields defined in self.SELF_{READ/WRITE}ABLE_FIELDS.
        """
        init_res = super(ResUsers, self).__init__(pool, cr)
        # duplicate list to avoid modifying the original reference
        type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
        type(self).SELF_WRITEABLE_FIELDS.extend(['sidebar_visible'])
        # duplicate list to avoid modifying the original reference
        type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
        type(self).SELF_READABLE_FIELDS.extend(['sidebar_visible'])
        return init_res
Avatar
Annuleer
Beste antwoord

Try to add class 'oe_read_only' in your field.
 Example:

field name="your_field" class="oe_read_only"/>
Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
nov. 24
3347
1
okt. 17
15711
2
dec. 16
11713
1
mei 16
5592
4
feb. 25
2286