I have created 4 character fields and put them in xml file. But i want those fields to be editable only by the people of their respective group.
My fields are
and in xml
user groups are
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I have created 4 character fields and put them in xml file. But i want those fields to be editable only by the people of their respective group.
My fields are
and in xml
user groups are
Hello
try like below code
let see the below is your form.
<record id="my_object_form_view" model="ir.ui.view">
<field name="name">my.object.form</field>
<field name="model">my.object</field>
<field name="arch" type="xml">
<form>
<field name="comment_ceo" readonly="1"/>
</form
</field>
</record>
Now if you want to make the field editable for some specific groups of users. try like below code, so as per below code whoever user has "CEO" groups access can edit the field "commect ceo"
<record id="inherit_my_object_form_view" model="ir.ui.view">
<field name="name">my.object.form</field>
<field name="model">my.object</field>
<field name="inherit_id" ref="modulename.my_object_form_view"/>
<field name="groups_id" eval="[(4, ref('modulename.group_ceo'))]"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='comment_ceo']" position="attributes">
<attribute name="readonly">0</attribute>
</xpath>
</field>
</record>
for more detail contact us on
email : equickerp@gmail.com
skype : equickerp
Hello Daniyal,
There are multiple ways to achieve this:
Make the field visible to the relevant group only by setting e.g. groups="group_ceo". This will work only in the case the groups are not inherited from one another.
Define a computed boolean field for each corresponding field which will be True if the user belongs to the allowed group. Set attrs="{'readonly': [('is_ceo_comment_editable', '=', False)]}" and vice versa for all the other fields.
Define a computed selection field with the states as ceo_editable, lm_editable, gd_editable and fm_editable and set its value based on the user group.
Override the write method and check if the edited field present in the vals dictionary is allowed to be edited by the current user.
If it's still not clear then let me know which method you would like to go for and I will explain it to you in more detail.
Kind regards,
First get login user group: https://goo.gl/Ts3qqK
Second make a boolean field and on the basis of that field make field visible/invisible/readonly etc: https://goo.gl/BCxCpk