This question has been flagged
8 Replies
11575 Views

We have recently rolled out Odoo to our sales staff and one of the biggest features that they wish they could have is this. Basically when you create a contact in Odoo, you have the ability to create child contacts. This is great, except that the form to create the child contacts (inside the parent contact) has very little useful information available.

What I'm looking for is the ability to click one of the contacts, and instead of the "Open: Contacts" modal opening, to navigate to the contact in question (so it's the same view as the parent) possibly into a new tab. 

I have looked into the form view for res.partner and found a template where I could probably add more data, but that isn't helpful in my case. I have also looked at the page client side, but found that there is no information there that I can use to be able to redirect those clicks to a useful location.


Any help would be greatly appreciated 


Avatar
Discard
Author Best Answer

Well this is unfortunate. The only answer to this problem I was able to find was to create my own solution.

This required two modifications that can easily be put into a custom module that inherits res.partner. 


The first modification I had to make was to make the document IDs available on the client. Inside res.partner.form, scroll down until the template is defined. In here, we are going to use a field to make the ID available; This can be put pretty much anywhere within the markup for the actual kanban boxes.


The modification that I had to make to this view is

<a class="partnerCardID" style="display:none"><field name="id"/></a>

I chose to put the ID into an anchor because they are easy to work with. This is invisible to the end user (thanks to display:none) so we can manipulate this all we want with JS

I chose to put the modification just above 

<div class="oe_kanban_details">


The other part of the modification is, naturally a little bit of JavaScript magic. I'll include the code that made it work, but you'll have to set it up to work directly on your page/run automatically.

// Select all divs that have the classes ow_kanvan_global_click and o_kanban_record that have a child anchor with a class of partnerCardID (our tag containing the ID)

$('div.oe_kanban_global_click.o_kanban_record > a.partnerCardID').each(function(){

// Wrap the above div with a link that navigates to the correct partner in a new tab

$(this).parent().wrapInner('<a href="//odoo/web#model=res.partner&view_type=form&id='+$(this).text()+'" target="odoo-'+$(this).text()+'"></a>');

});

Change the location of the link above to your own host, run this javascript after the page has loaded and all of your Contacts & Addresses will be clickable, with the full information available. Style the link as you see fit.


Note: I am opening these links in a new tab (through the use of target) because the user's current context will not follow, so if they are working from a search or something else, it isn't lost by navigating away

Avatar
Discard

This is still a problem in v16 and v17. Why do Odoo want these limited pop up views? It just means we have to customize the contact card layouts and the pop-up layouts.

I would prefer to just always open the full view.

Has anyone found a better solution than the above by David Todd for v16 and/or v17?

Best Answer

Hi David,

If it's still of any help, to reformulate your question (for odoo 8 at least) :  

how can I instruct odoo to use a different view than the modal view displayed when clicking on a contact card from a Partner's form ?

And the answer lies in the partner_form_view code itself, below the kanban template, there is an inline form :

<form string="Contact"> 
 <sheet>
    <field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/>
<div class="oe_title">
...

The mechanism of choosing a view (when no action forces a specific one..)  is by evaluating the priority of a view (form or tree or any other one), the highest priority being given to the inline ones. View records with specific priorities defined in their code are then evaluated, and finally, if none of these are found, odoo will choose a default view (for example the only form view ever defined for a model) or again compose a default view with all existing fields for an object. 

Therefore what you have to do is force odoo to ignore this inline form by either forcing the priority of another view (impossible with partner view inside a partner view, it would lead to a mess). 

Or ... remove that inline view, and let odoo guess which default form should be used. In this case : the normal form.

It can be achieved by inheriting the base.view_partner_form and selecting / replacing with xpath the elements that are in your way:

<xpath expr="//sheet/notebook/page/field/form[@string='Contact']" position="replace"/>

Now, embed it in a record:

<record model="ir.ui.view" id="res_partner_form"> 
    <field name="name">res.partner.form</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <xpath expr="//sheet/notebook/page/field/form[@string='Contact']" position="replace"/>
    </field>
</record>

Next you will need to heal other view records relying on the elements you just removed, and luckily by default there is only one in the sale module addons/sale/res_partner_view.xml :

You will have to overwrite that one (instead of inheriting it, up to you really there are pro's an con's..), here is the raw record :

<record id="res_partner_address_type" model="ir.ui.view"> 
<field name="name">res.partner.view.address_type</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//label[@for='type']" position="attributes">
<attribute name="groups">sale.group_delivery_invoice_address</attribute>
<attribute name="invisible">False</attribute>
</xpath>
<xpath expr="//div[@name='div_type']" position="attributes">
<attribute name="invisible">False</attribute>
<attribute name="groups">sale.group_delivery_invoice_address</attribute>
</xpath>
<!-- Version-specific hacks to avoid breaking view inheritance when the sale module is installed on top of an older 7.0 version of the base module (as the second embedded div_type was added later in the 7.0 release) TODO: remove the hacks in trunk -->
<xpath expr="//div[@name='div_type'][field[@name='use_parent_address']] | //field[@name='child_ids']//div[@name='div_type']" position="attributes">
<attribute name="invisible">False</attribute>
<attribute name="groups">sale.group_delivery_invoice_address</attribute>
</xpath>
<xpath expr="//label[@for='type'][following-sibling::div[@name='div_type']/field[@name='use_parent_address']] | //field[@name='child_ids']//label[@for='type']" position="attributes">
<attribute name="invisible">False</attribute>
<attribute name="groups">sale.group_delivery_invoice_address</attribute>
</xpath>
</field>
</record>

override it by taking out path selectors pointing to the code you just removed, here is the result:

<record id="sale.res_partner_address_type" model="ir.ui.view"> 
    <field name="name">res.partner.view.address_type</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form" />
    <field name="arch" type="xml">
        <xpath expr="//label[@for='type']" position="attributes">
            <attribute name="groups">sale.group_delivery_invoice_address</attribute>
            <attribute name="invisible">False</attribute>
        </xpath>
        <xpath expr="//div[@name='div_type']" position="attributes">
            <attribute name="invisible">False</attribute>
            <attribute name="groups">sale.group_delivery_invoice_address</attribute>
        </xpath>
    </field>
</record>

Make a custom module with this code, think of dependencies in the manifest (base, sale), load, force update with command line -u my_custom_module, and test..

Hope this helps, as this quick create view is nothing but a bogger, it leads people to enter incomplete partner records.

- Nicolas -

Avatar
Discard
Author

Thank you for this incredibly concise answer! I'll definitely have to keep it in mind when I have to re-visit this part of the system for our Sales team to give them new features.

Cheers - you can mark this post as the right answer if you are satisfied with it. tx.

Best Answer

A solution for Odoo 11, where instead of making the whole box clickable, I add a small link to it.

<!-- Add small "link button" to existing view. -->
<record model="ir.ui.view" id="partner_vendor_form_view">
<field
name="name">res.partner.with.buttons</field>
<field
name="model">res.partner</field>
<field
name="inherit_id" ref="base.view_partner_form"/>
<field
name="arch" type="xml">
<data>
<!-- Make sure that template has access to the 'id' value, before "Name". !-->
<xpath expr="//field[@name='child_ids']/kanban/field[@name='name']" position="before">
<field
name="id"/>
</xpath>
<!-- Add the actual link to the template. !-->
<xpath expr="//field[@name='child_ids']/kanban/templates//div[@class='oe_kanban_details']/field[@name='name']" position="before">
<a
t-att-href="'#id='+record.id.raw_value+'&amp;model=res.partner'" class="fa fa-fw o_button_icon fa-pencil-square-o pull-right">
</a>
</xpath>
</data>
</field>
</record>
Avatar
Discard
Best Answer

What is really anoying is that it was working on V7... on V8+ disapeared... The new form is trully uselless as one need to get out and either update the contact OR get out of the partner to create a new contact with the propper form and assign it to the account.


Im waiting for V11 to see what happens...odoo has some really nice features, its a pitty on each new version they mess with something...


Avatar
Discard
Best Answer

https://apps.openerp.com/apps/modules/8.0/web_tree_many2one_clickable/

Can you show the contacts in treeview instead of kanban view, and install the module to allow them to be clicked?


Avatar
Discard
Author

I looked at the module that you linked and I'm pretty sure it won't do what I need. If you have an instance of Odoo available to you, if you go into Contacts and select any contact, you'll be taken into the form view for that specific contact. Now there is a notebook at the bottom of the form with a page that says "Contacts & Addresses". Normally when there are contacts in this page, they are their own contacts with their parent_id set. These specific contacts are what I'm looking to be able to click to be brought into the same form view that the parent was on. The reason being is that we have a couple extra pages in the notebook I mentioned above that contains information that we need access to when looking specifically at the contact from the company page. Thanks for the suggestion though, it might come in handy further down the line.