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

I have a button which I need to hide if the user is a superuser (admin). My problem is that when I'm using xpath to include the attrs, nothing is working as expected. My code is:

<record id="wms_stock_view_move_form" model="ir.ui.view">

            <field name="name">wms.stock.view.move.form</field>

            <field name="model">stock.move</field>

            <field name="inherit_id" ref="stock.view_move_form" />

            <field name="arch" type="xml">

                <field name="location_id" position="attributes">

                    <attribute name="domain">[('name','!=', 'Scrapped')]</attribute>

                </field>

                <field name="location_id" position="after">

                    <field name="is_superuser"/>

                </field>

                <field name="location_dest_id" position="attributes">

                    <attribute name="domain">[('name','!=', 'Scrapped')]</attribute>

                </field>

                <xpath expr='//form[@string="Stock Moves"]' position='attributes'>

                    <attribute name="create">false</attribute>

                    <attribute name="edit">false</attribute>

                    <attribute name="delete">false</attribute>

                </xpath>

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

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

                </xpath>

            </field>

        </record>


is_superuser = fields.Boolean(compute='_is_super_user')

def _is_super_user(self):

    if self._uid == SUPERUSER_ID:
        self.is_superuser = True
    else:
        self.is_superuser = False


The original code for the button, in its original view is:

<button name="action_cancel" states="draft,assigned,confirmed" string="Cancel Move" type="object"/>


any idea, what I'm doing wrong ? Thanks in advance.

อวตาร
ละทิ้ง

I looked at stock.view_move_form, in Odoo v9 and v10, and could not find ANY buttons - so I don't think your xpath will find anything.

ผู้เขียน

I'm working in Odoo v8. I'm not aware how much the code has been changed in v9 and v10, but I guess it should be about the same. About the buttons, they are present inside header tag. If they didn't changed much of the code then it should be line no 990-993.

คำตอบที่ดีที่สุด

You have to override the state attribute also, this will keep the default behavior and add yours.

<xpath expr="//button[@name='action_cancel']" position="attributes">
      <attribute name="states"></ attribute>
      <attribute name="attrs">{'invisible':['|', ('is_superuser','=', True), ('state', 'not in', ('draft','assigned','confirmed'))]}</ attribute> 
</xpath>
อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

thanks @Mahmou Sekawe you saved me. that is the answer, just the modification that I need to do is_superuser=False. Else, its is the perfect answer.

อวตาร
ละทิ้ง

You most welcome :)

Related Posts ตอบกลับ มุมมอง กิจกรรม
How to get company name in qweb report? แก้ไขแล้ว
1
เม.ย. 22
22628
How to call css style in qweb report? แก้ไขแล้ว
2
ก.พ. 21
11226
1
มี.ค. 17
2933
4
พ.ค. 16
7823
0
มี.ค. 15
3372