Skip to Content
Menu
This question has been flagged
1 Reply
7251 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

Avatar
Discard
Best Answer

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
Avatar
Discard
Author

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

Related Posts Replies Views Activity
0
Aug 24
980
1
Jun 22
3035
1
Jan 22
3351
0
Dec 15
5175
0
Mar 15
4517