Skip to Content
Menu
This question has been flagged
2 Replies
2371 Views

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.


 

Avatar
Discard

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,

Author Best Answer

Hey Jack,

Thanks for your quick feedback.

I've decided to recreate a view from scratch cause my company absolutely needs to split Suppliers and Customers so it can be easy for users to look for what they need.

And instead of having a "Contacts" tree view where a lot of unnecessary things are displayed (individual contacts from supplier, from customers, from employees, ...) and to avoid creating a lot of filters (that requires multiples mouse clicks, ...) i wanted to have two new menus : Suppliers / Customers and displays only fields that i want.

That way, everything is separated ad catagorized and informations are displayed clearly.

Avatar
Discard
Best Answer

Hello Guillaume,

That makes sense, I believe the issue is that you are inheriting the res.partner main list view. Remove the inherit_id and try this:

<record id="fournisseur_tree_view" model="ir.ui.view">

<field name="name">cvs.fournisseur.tree</field>

<field name="model">res.partner</field>

<field name="arch" type="xml">

<tree>

<field name="name"/>

<field name="email"/>

<field name="phone"/>

</tree>

</field>

</record>

It works for me on V14 after originally seeing your issue.

Thanks,

Avatar
Discard
Author

Hello Jack,

Thanks for your answer.

I've just tested your solution by removing the inherit tag and unfortunately got the same tree view as the res.partner one...

I should only be able to see columns "name", "email" and "phone", right ?

Hello Guillaume,

Correct, originally, I saw the standard until removing the inherit_id and mode.

Have you made sure to update the app when making the changes to the XML?

Thanks,

Author

Hi Jack,

Yes indeed, each time i make an XML change, i go to Apps > My Module > Upgrade.

Should i update the Apps List beforehand ?

Author

I finally managed to make it works by uninstalling the module and reinstalling it. I'm not sure what happend, but it seems to be workings now.

Thanks for your time Jack !