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

Hii

see my code below.

add_field.py

class CrmLead(models.Model):
    _inherit = 'crm.lead'

    add_portal_id = fields.Many2one('add.portal')

class AddPortal(models.Model):
    _name = "add.portal"
    _description = "Add Portal"
    _rec_name = "add_portal_name"

    add_portal_name = fields.Char(string='Add Portal Name', required=True)

add_field_view.xml

<record id="profile_field_form_inherit" model="ir.ui.view">
    <field name="name">Add Profie Field</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
    <field name="arch" type="xml">
        <field name="team_id" position="after">
            <field name="add_portal_id" string="Portal Name"/>
        </field>
    </field>
</record>

아바타
취소

The need of this post is, to sometime we need to visible invisible, readonly etc some filed on the basis of login user group or we want to perform some action on the basis of login user. To do so we need to get login user group: https://goo.gl/Ts3qqK

How to visible and invisible fields in odoo: https://goo.gl/BCxCpk

베스트 답변

Hi  Kiran,

You can achieve this by using following code

In Python

from lxml import etree
@api.model
def fields_view_get(self, view_id='you_form_view_id', view_type='form', toolbar=False, submenu=False):
res = super(ClassName, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
doc = etree.XML(res['arch'])
if self.env.user.has_group('group1'):
for node in doc.xpath("//field[@name='field1']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
elif self.env.user.has_group('group2'):
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field3']"):
node.set('modifiers', '{"readonly": true}')
res['arch'] = etree.tostring(doc)
return res

You need to assign that user to specific Group based on that group you can achieve that easily

Othewise based on Login also, you can achieve

Thanks

아바타
취소
작성자

Hi @Gokulakrishnan

i used this above code but error are occurred you can see below error

NameError: name 'TrailQueue' is not defined

how to define TrailQueue tell me

Thanks In advanced

Hi KIran,

That's Class name of the Method.

베스트 답변

Hi if you want to make the field readonly for a particular group, say for all the users present in a group.. you can use fields view get function to make the field readonly for a particular user.. or you can create your own record rules... 

There is another alternative, you can create a boolean field and make it invisible.. use compute function to make the field True/False based on the user logged in using self.id .... you can then use this boolean field in attrs for your field...

<field name="add_portal_id" attrs="{'readonly': [('your_boolean_field', '=', True)]}"/>

아바타
취소
베스트 답변

Here attrs will not work for the dynamic domain so (maybe only) option is passed context from the action and eval it on the field

like pass 'readonly_user' key from action context base on a particular user and

            <field name="add_portal_id"  string="Portal Name" readonly="context.get('readonly_user', False)"/>

아바타
취소
작성자

Hello @Ravi you told that pass the 'readonly_user' key means their will be put the user's username or what plz tell me clearly.

thanks

관련 게시물 답글 화면 활동
1
4월 19
10008
1
2월 19
5633
1
3월 22
11709
1
9월 21
5678
3
1월 20
6873