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

Hi everybody,

I'm working with Odoo 10, I want to hide the form Edit button with my new field (compute field).

My code is:

<data>
    <xpath expr="//field[@name='description']" position="before"> <field name="editable" invisible="1"/>
    </xpath>
    <xpath expr="//form[1]" position="attributes">
         <attribute name="edit">[('editable','=',True)]</attribute> 

    </xpath>
</data>

But I got error when try to run the form, error regarding JSON value.

Did I made something wrong?

Thank you.

 

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi Mayank,

It does not solve my issue, but really helpful

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

Hello Vu Huynh,

Use this reference and set your condition.

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(Entity, self).fields_view_get(view_id=view_id, view_type=view_type,
context=context,
toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
if view_type == 'form' and [some_condition]:
for node_form in doc.xpath("//form"):
node_form.set("create", 'false')
res['arch'] = etree.tostring(doc)
return res

Hope it Helps,

Best Regards,

Mayank Gosai

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

Yes, this work fine.

But I'd like to show/hide the edit button base on the value of field "editable" value (this is my new field). How can I do that?

Thanks

For that make 1 Boolean button.

Xpath till your button and then use reference of following code.

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

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

</xpath>

Do your computation and make boolean true on your requirement.

Hope it helps,

Mayank Gosai

ผู้เขียน

Hi, I think you are misunderstand my issue, the button "Edit" I want to hide that is not define in the form view, it's the template button of form view. And the only way to hide it is using the attribute 'edit'. I tried with 'attrs' but it didn't work. My form view is:

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

<field name="name">oit.mail.channel.form</field>

<field name="model">mail.channel</field>

<field name="inherit_id" ref="mail.mail_channel_view_form"/>

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

<xpath expr="//field[@name='description']" position="before">

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

</xpath>

<xpath expr="//form[1]" position="attributes">

<attribute name="edit">[('editable','=',True)]</attribute>

</xpath>

</field>

</record>

Updated answer, Please have a look.