I've created a module in odoo18 and in that I created a xml called product_views. It has a list in it. I added a button in the header of the list but I can't see it.
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_product_list" model="ir.ui.view">
<field name='name'>"electronic.product.list"</field>
<field name='model'>product.product</field>
<field name="priority" eval="99"/>
<field name="arch" type="xml">
<list>
<header>
<button name="import_action"
string="import"
type='object'/>
</header>
<field name="name" string="product name" />
<field name="volume" string="quantity" />
<field name="x_link" string="quantity" />
</list>
</field>
</record>
<record id="action_electronic_products" model="ir.actions.act_window">
<field name="name">Electronic Products</field>
<field name="res_model">product.product</field>
<field name="view_mode">list</field>
<field name="view_id" ref="view_product_list"/>
</record>
<menuitem
id="menu_electronic_product_root"
name="Electronic Products"
action="action_electronic_products"
sequence="10"
groups="base.group_user"/>
This is my model:
from odoo import models, fields, api
class ProductProduct(models.Model):
_inherit = 'product.product' # Correct inheritance
x_link = fields.Char(
string='Product Link',
help='URL of the product',
default='',
tracking=True # Shows changes in chatter
)
def import_action(self):
return {
'name': 'Import Products',
'type': 'ir.actions.act_window',
'res_model': 'product.import.wizard',
'view_mode': 'form',
'target': 'new',
'context': {'default_product_id': self.id},
}
Can you help me please?
Actually, your code works, the button does appear.
I assume that, you didn't know that in Odoo, for general, buttons that used in the tree/list view don't always show, they only appear when any data is selected. So, if I don't select any data, you can see on the picture below, the "import" button of yours will disappear.
Therefore, if what you want is for the button to always be shown, then you need to make further customization by utilizing the Owl JS component (but it needs more advanced knowledge)
You can see a topic discussed in Odoo forum similar with that here:
How to add a button next to Create in List View in Odoo 16