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.

1

create record both values shows name instead of Ref [Closed]

By
Prakash
on 2/13/13, 9:00 AM 571 views

The Question has been closed for reason: not relevant or out dated

by
Nicolas Bessi
on 02/14/2013 10:35:40

test_master.py

class test_master(osv.osv):
    _name = 'test.master'
    _columns = {
      'name' : fields.char('Name', size=64),
      'ref' : fields.char('Ref', size=64),
    }


    def name_get(self, cr, uid, ids, context=None):
        res = []
        if context.get('master_ref'):
            rec_name = 'ref'
        else:
            rec_name = 'name'
        res = [(r['id'], r[rec_name]) for r in self.read(cr, uid, ids, [rec_name], context)]     
        return res    

    def name_search(self, cr, uid, name='', args=None, operator='ilike', context=None, limit=100):   
        if not args:
            args=[]
        if not context:
            context={}
        if context.get('master_ref'):
            ids = self.search(cr, uid, [('ref', operator, name)] + args, limit=limit, context=context)
        else:
            ids = self.search(cr, uid, [('name', operator, name)] +args, limit=limit, context=context)        
        if not name:
            ids = self.search(cr, uid, args, limit=limit, context=context)
        return self.name_get(cr, uid, ids, context)


test_master()

test_contact.py

from osv import osv, fields

class test_contact(osv.osv):
    _name = 'test.contact'
    _columns = {
      'master_name' : fields.many2one('test.master', 'Name'),
      'master_ref' : fields.many2one('test.master', 'Reference'),
    }


test_contact()

test_contact_view.xml

<record id="view_test_contact_form" model="ir.ui.view">
        <field name="name">test.contact.form</field>
        <field name="model">test.contact</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Contact">
                  <field name="master_name" context="{'master_name':1}"/>
                  <field name="master_ref" context="{'master_ref':1}"/>
            </form>
        </field>    
      </record>

In the above code Test Contact form Name Field display 'contact1' and Reference Field display '0001' at the time of selection. But issues after the record saved it shows Name Field display 'contact1' and Reference Field display 'contact1'

How to solve this issue? thanks

-1: very low quality question (title, too much code, wording).

Antonin Bourguignon (abo)
on 2/13/13, 9:23 AM

I closed the question as it is not understandable

Camptocamp SA
on 2/14/13, 10:37 AM
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 2/14/13, 2:31 AM

Actually in my requirements:-

Contact Name shows only contact Name (res.partner.address) Contact Address show only contact Address (res.partner.address)

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

Is it possible using name_get in same form shows name and address for the both field used same object res.partner.address?

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 2/13/13, 9:00 AM
Seen: 571 times
Last updated: 3/16/15, 8:10 AM