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

Guide for relationships.

By
Ashok Kumar Sahoo
on 12/11/13, 9:30 AM 645 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'),
}
person()

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

how to define my relationships.

1
PT SIVI
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'),
        'address_ids':fields.one2many('halo.address','person_id','Addresses'), 
}


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.

PT SIVI
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

PT SIVI
on 1/27/15, 10:02 PM
0

Fabrice Henrion (fhe)

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

Director Odoo USA

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

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

0 follower(s)

Stats

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