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

using name_get how to shows two different display values?

By
Prakash
on 2/21/13, 12:56 AM 5,143 views

I have two fields related with res.partner.addreess

_name = "contact_details"
_columns = {
        'contact_id': fields.many2one('res.partner.address', 'Contact Name'),
        'contact_address_id': fields.many2one('res.partner.address', 'Contact Address'),
 }

In the contact_details Form:-

Currently display

Contact Name --> Contact Name with address

Contact Address --> Contact Name with address

Actual Requirement

Contact Name --> Contact Name only

Contact Address --> Contact Name with address

Using name_get Is it possible using name_get to show contact Name and Contact Address in Field 1 and field 2 ???

Thanks

4

Fabien Pinckaers (fp)

--Fabien Pinckaers (fp)--
6598
| 6 8 8
fsdsdfsdf, Belgium
--Fabien Pinckaers (fp)--

Odoo Founder & CEO

Fabien Pinckaers (fp)
On 3/2/13, 9:15 AM

Yes, you must put a context on one of the two fields (in the view or in the field) and develop a name_get on thre res.partner object that returns different values according to the context.

OpenERP has already such an implementation for partners. This should work in your view, for v7:

<field name="contact_id"/>
<field name="contact_address_id" context="{'show_address': 1}" options='{"always_reload": True}'/>

Hi Fabien Pinckaers , I have doubt regards passing context value in XML file . Can you please explain with example .

omprakash
on 6/5/13, 1:45 PM
1
Abegail Sanchez
On 7/15/14, 2:04 AM

Hi Fabien,

this helped me, thanks

this was he meant

def name_get(self,cr,uid,ids,context=None):
        if context is None:
            context ={}
        res=[]
        record_name=self.browse(cr,uid,ids,context)
        for object in record_name:

                if object.name
                   if context.get('show_address',False):
                          //name for contact_address_id field

                         res.append((object.id,object.name+object.address))
                  else:
                       //name for contact_id field                     

                      res.append((object.id,object.name))
        return res

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: 2/21/13, 12:56 AM
Seen: 5143 times
Last updated: 3/16/15, 8:10 AM