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

many2one Relational Types fields

By
omprakash
on 5/24/13, 2:42 PM 2,254 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

0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 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 ....

omprakash
on 5/25/13, 1:53 AM

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: 5/24/13, 2:42 PM
Seen: 2254 times
Last updated: 3/16/15, 8:10 AM