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

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.