Odoo Help


Guide for relationships.

Ashok Kumar Sahoo
on 12/11/13, 9:30 AM 998 views

Suppose I have a person who can has multiple addresses. I have made a person class with all personal details and one adress class with all address details, how to add a relationship that one person has many addresses.

class person(osv.osv):
  _name: 'foo'
  _description : 'bar'
  _columns: {
name' : fields.char('Name', size= 64, required = True),
        'age' : fields.integer('Age'),

class adress(osv.osv):
  _name : 'foo_a'
  _descrption : 'bar'
  _columns: {
'address' : fields.text('Add.'),

how to define my relationships.

On 12/12/13, 2:28 AM

You can try this one

from openerp.osv import osv, fields

class halo_person(osv.osv):
    _name: 'halo.person'
    _columns: {
        'name' : fields.char('Name', size= 64, required = True),
        'age' : fields.integer('Age'),

class halo_adress(osv.osv):
  _name : 'halo.address'
  _columns: {
        'address' : fields.text('Where is it?'),

        'person_id': fields.many2one('halo.person', 'Related Person'),

Simple Explanation : You have a person, and many address. so in halo.person class, define one_person->many_address or you can type them as one2many fields.

Otherwise, in halo.address class, you should define many2one fields.

on 12/12/13, 2:32 AM

what is the difference between defining address_ids and not defining it, just using person_id directly?

Ashok Kumar Sahoo
on 12/13/13, 10:26 AM

Sorry, I just saw your question. By defining one2many, odoo will automatically link from both sides. So you will be able to track data from two direction. If you want to look at which are the person's addresses, you can access it by using (browserecord,id).address_ids. If you dont define it. You have to search by using self.pool.get('halo.address').search(cr,uid,[('person_id','=',8)]) Sorry for super late answer

on 1/27/15, 10:02 PM

Fabrice Henrion (fhe)

--Fabrice Henrion (fhe)--
| 7 7 9
San Francisco, United States
--Fabrice Henrion (fhe)--

Director Odoo Americas

Fabrice Henrion (fhe)
On 12/11/13, 12:38 PM

I'm not sure why you involve code for this question. You can use the module base_contact: https://code.launchpad.net/~openerp-dev/openobject-addons/7.0-base-contact-xal

I am learning how to create new modules.. I want to know how it works.. example is made up just for practice..

Ashok Kumar Sahoo
on 12/11/13, 2:57 PM

You should use the technical memento and recreate the "idea" module for practice. It's a good step-by-step: https://www.openerp.com/files/memento/

Fabrice Henrion (fhe)
on 12/11/13, 4:23 PM

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

0 follower(s)


Asked: 12/11/13, 9:30 AM
Seen: 998 times
Last updated: 3/16/15, 8:10 AM