Disable Create button in Tree view but keep Import in odoo

1.3k Views Asked by At

I need to create a new View which can´t be editable and the button Create has to be disabled, but the Import should stay. With create = "false" the import option is disabled too, is there any option to disable the create button but keeping the import button

<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>
2

There are 2 best solutions below

2
wajahat On

there is a possibility to hide create button from the view, without hiding the import and edit buttons by using CSS.

you need to add an HTML field on a related model like

  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
0
Sakthi Priya On

Try this :

<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>