【问题标题】:Disable Create button in Tree view but keep Import in odoo在树视图中禁用创建按钮,但在 odoo 中保留导入
【发布时间】:2021-07-19 20:29:49
【问题描述】:

我需要创建一个无法编辑的新视图,并且必须禁用创建按钮,但导入应该保留。 使用 create = "false" 导入选项也被禁用,是否有任何选项可以禁用创建按钮但保留导入按钮

<record id="historic_quote_sale_order_tree_view" model="ir.ui.view">                
    <field name="name">historic.tree</field>                
    <field name="model">historic.sale.order</field>                
    <field name="arch" type="xml">                    
        <tree string="Historic Sale Form" create="false" edit="false">                            
            <field name="id_offer_register"/>                            
            <field name="id_offer"/>                            
            <field name="num_offer"/>                            
        </tree>                
    </field>        
</record>

【问题讨论】:

标签: odoo odoo-view


【解决方案1】:

可以在视图中隐藏创建按钮,而无需使用 CSS 隐藏导入和编辑按钮。

您需要在相关模型上添加一个 HTML 字段,例如

  x_hide_css = fields.Html(
        string='Hide CSS',
        sanitize=False,
        compute='_compute_hide_css',
        store=False,
    )
then you can put your logic on _compute_hide_css function like 

 

def _compute_css(self):
            for rec in self:
                if your condition:
                    rec.x_css = '<style>.o_form_button_create {display: none !important;}</style>'
                else:
                    rec.x_css = False

【讨论】:

  • 这是一个独特的解决方案,我不知道你能做到这一点:)
  • @ObayAbd-Algader 我已经实现了这个解决方案。
【解决方案2】:

试试这个:

<record id="sale_view_form_inherit" model="ir.ui.view"> 
<field name="name">sale.form.new</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="groups_id" eval="[(6, 0, 
[ref('custom_module.group_name')])]"/>
<field name="arch" type="xml">
<xpath expr="/tree" position="attributes">
<attribute name="create">false</attribute>
</xpath>
</field>
</record>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多