首页 > 解决方案 > Odoo 10:从客户表单视图中删除按钮

问题描述

我想从客户表单视图中删除“未在网站上发布”按钮。

在此处输入图像描述

这个按钮不是表单视图的一部分,所以当我尝试下面的代码时,我得到一个错误,即父视图中不存在元素:

<xpath expr='//div[@class="oe_button_box"]//button[@name="website_publish_button"]' position='replace'>   
   <button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
        <field string="Surveys"  name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
   </button>                   
</xpath>

然后我尝试使用 css 将其删除。我的 css.css 文件:

button[name=website_publish_button] 
                {    
                    display:none !important;
                }  

和模板:

<openerp>
    <data>
    <!-- Adds all assets in Odoo -->
        <template id="assets_backend" name="contacts_custom assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
        <!--These links will be called when loading your Odoo -->
                <link rel="stylesheet" href="/contacts_custom/static/css/css.css"/> 

            </xpath>
        </template>
    </data>
</openerp>

但仍然出现按钮。我做错了什么还是有没有其他方法可以删除这个按钮?

标签: cssxmlformsbuttonodoo

解决方案


您可以像这样扩展视图:

<record id="view_partners_form_website" model="ir.ui.view">
    <field name="name">view.res.partner.form.website</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="website_partner.view_partners_form_website"/>
    <field eval="18" name="priority"/>
    <field name="arch" type="xml">
        <data>
            <button name="website_publish_button" position="replace">
                <button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
                    <field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
                </button>
            </button>
        </data>
    </field>
</record>

向模块添加一个依赖条目,website_partner以便能够继承添加按钮的视图,如上面的代码片段


推荐阅读