콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
12532 화면

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

    comment_lm = fields.Char(string='Comment by Line Manager')
    comment_ceo = fields.Char(string='Comment by CEO')
    comment_gd = fields.Char(string='Comment by Gruop Director')
    comment_finance = fields.Char(string='Comment by Finance')

and in xml

                    <field name="comment_lm"/>
                    <field name="comment_ceo"/>
                    <field name="comment_gd"/>
                    <field name="comment_finance"/>

user groups are

<record id="contract_apporval" model="ir.module.category">
        <field name="name">Contract Approval </field> 
        <field name="description">people whose approval required</field>
    </record>


    <record id="group_line_manager" model="res.groups">
        <field name="name">Line Manager</field>
        <field name="comment">will approve after contract is created</field>
        <field name="category_id" ref="contract_apporval"/>
    </record>

    <record id="group_ceo" model="res.groups">
        <field name="name">CEO</field>
        <field name="comment">will approve contract after line manager</field>
        <field name="category_id" ref="contract_apporval"/>
    </record>

    <record id="group_gd" model="res.groups">
        <field name="name">Group Director</field>
        <field name="comment">will approve contract after CEO</field>
        <field name="category_id" ref="contract_apporval"/>
    </record>

    <record id="group_finance" model="res.groups">
        <field name="name">Finance</field>
        <field name="comment">final approval for contract</field>
        <field name="category_id" ref="contract_apporval"/>
    </record>

    <record id="group_hr" model="res.groups">
        <field name="name">Human Resource</field>
        <field name="comment">create and final approval</field>
        <field name="category_id" ref="contract_apporval"/>
    </record>
아바타
취소

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

베스트 답변

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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,

아바타
취소