Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Clickable "Contacts & Addresses" inside res.partner

By
David Todd
on 3/29/16, 6:03 PM 630 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 


0
David Todd
On 4/11/16, 12:56 PM

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

1
Nicolas Clavier
On 9/20/16, 11:35 AM

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 -

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.

David Todd
on 9/29/16, 5:30 PM

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

Nicolas Clavier
on 10/13/16, 11:08 AM
0

Ray Carnes

--Ray Carnes--
15717
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 3/30/16, 1:00 AM

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.

David Todd
on 3/30/16, 1:33 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/29/16, 6:03 PM
Seen: 630 times
Last updated: 9/20/16, 11:35 AM