Hello !
My goal is to create a duplicate "Contacts" tree view so i can modify it as i wish without impacting the original Contacts tree view.
I've created a new "fournisseur.py" file that inherits res.partner :
from odoo import api, fields, models
import logging
_logger = logging.getLogger(__name__)
class Fournisseur(models.Model):
_inherit = 'res.partner'
And created a "fournisseur.xml" file where i created a custom view named "cvs.fournisseur.tree" which i call from the "cvs_fournisseur_action".
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="cvs_fournisseur_action" model="ir.actions.act_window">
<field name="name">Liste des fournisseurs</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="fournisseur_tree_view"/>
</record>
<menuitem id="fournisseur_root"
name="Fournisseurs"
action="cvs_fournisseur_action"
sequence="-99" />
<record id="fournisseur_tree_view" model="ir.ui.view">
<field name="name">cvs.fournisseur.tree</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="email"/>
<field name="phone"/>
</tree>
</field>
</record>
</odoo>
When i open the "Fournisseur" menu, i'm seeing the same tree view as the "Contacts" one - So there is clearly a problem here - but what i don't understand is that when i go to Debug Mode > Edit View:List, the tree view loaded seems to be my custom view !
So i'm having troubles understanding why my custom view isn't properly displayed.
Do you guys have some tips on this ?
Thanks a lot in advance !
Guillaume.
Hello Guillaume,
Is there any reason why you are creating a new view from scratch rather than inheriting the base view and changing the values that way?
Usually in Odoo if you want to change the view of an existing model you would inherit that view and change attributes/add or remove fields that already exist on the view using XPath.
An example would be if I wanted to add the website field after the name:
<record id="module.name" model="ir.ui.view">
<field name="name">View Name</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="XML">
<xpath expr="//field[@name='display_name']" position="after">
<field name="website"/>
</xpath>
</field>
</record>
Thanks,