Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
5594 มุมมอง

Hi i want to hide a button on a user

I create a boolean field 

user_id = fields.Many2one('res.users', 'User', related='resource_id.user_id')
current_user = fields.Boolean('is current user ?', compute='_get_current_user')

@api.depends('user_id')
def _get_current_user(self):
for e in self:
    e.current_user = (True if e.env.user.id == e.user_id.id else False)


<xpath expr="//button[@name='action_view_picking']"  position="attributes">

             <attribute name="attrs">{'invisible':[('current_user', '=', False)]}</attribute>

   </xpath>

but it does not work

Field 'current_user' used in attributes must be present in view but is missing:

 - 'current_user' in attrs="{'invisible':[('current_user', '=', False)]}"

       

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

From the error message itself, you can see what is the issue, You haven't added the field in the view.

So add the field to your view and make it invisible.


<field name="current_user" invisible="1"/>


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

I added

<xpath expr="//sheet//group//group//field[@name='partner_id']" position="after">

<field name="current_user"/>

</xpath>

but i have a new error

'purchase.order' object has no attribute '_get_curent_user'

ผู้เขียน คำตอบที่ดีที่สุด

I added 

  <xpath expr="//sheet//group//group//field[@name='partner_id']" position="after">

<field name="current_user"/>

</xpath>

but i have a new error 

'purchase.order' object has no attribute '_get_curent_user'

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You must add your boolean field in XML by making it invisible True.

Read more: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

อวตาร
ละทิ้ง
ผู้เขียน

I added

<xpath expr="//sheet//group//group//field[@name='partner_id']" position="after">

<field name="current_user"/>

</xpath>

but i have a new error

'purchase.order' object has no attribute '_get_curent_user'