Odoo Help


many2one Relational Types fields

on 5/24/13, 2:42 PM 2,904 views

Hai Friends ,

I have question regards - many2one relation types fields .

1.It is possible to make use of many2one relation type fields for more than fields ?

Example : Let as assume Table - Customer (python class)

  _rec_name = 'customer' 
  _columns ={
    'customer' : fields.char('customer' , size = 30 ),
    'phone' : fields.integer('phone')

Table - Sales Order

Using  many2one - customer name will be displayed in Sales Order table .

But, If i need to display phone in Address table . What will be the syntax . Friend Please guide me .

Thanks & Regards OMPRAKAHS.A


Brett Lehrer

--Brett Lehrer--

| 5 5 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 5/24/13, 9:03 PM

If I'm understanding correctly, you're looking to choose when to have a many2one field be a clickable link say either the phone number or the customer name?

To do something like that, you'd need to create the name_get() function in the Customer class and have it evaluate the context dictionary for some arbitrary key term you define. The res_partner.py file in the base module already has it defined, so you can use that as an example. Also, check the documentation! In the act_window record that opens a certain view that you want to operate differently, add that field to the context:

<field name="context" eval="'{\'name_get_phone\':True}'"/>

Now in your name_get() function, check the context for your term:

if context is None:
    context = {}
if context.get('name_get_phone') is True:
    if isinstance(ids, (int, long)):
        ids = [ids]
    phone_data = self.read(cr, uid, ids, ['customer', 'phone'], context=context)
    result = []
    for record in phone_data:
        # Use the regular name if the customer doesn't have a phone number
        new_name = record['phone'] or record['customer']
        result.append((record['id'], new_name))
    return result

Hi Brett Lehrer , Thanks for your immediate reply . I will make use of it ....

on 5/25/13, 1:53 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/24/13, 2:42 PM
Seen: 2904 times
Last updated: 3/16/15, 8:10 AM