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

many2many relation with attributes

By
Martin Varela
on 11/27/13, 8:38 AM 1,943 views

I want to create a many2many relation in res.partner (self related). This relationship needs to have attributes.

For example: PartnerA is 'manager' of PartnerB. PartnerB is 'owner' of PartnerB1. PartnerC is 'business agent' of PartnerA. ....

The type of relation (enclosed by '') will be a new model partner_relations.

How can I implement this?

0
raul paz
On 4/24/14, 2:35 PM

#file: res.partner.py

from osv import osv
from osv import fields

class res_partner_rel(osv.osv):
        _name = 'res.partner.rel'
        _columns = {
                   'partner_left_id' : fields.many2one('res.partner'),
                   'partner_right_id': fields.many2one('res.partner','Relationed Partner'),
                   'property_left2right': fields.char('Relation',size=32),
                   }
class res_partner(osv.osv):
        _name = 'res.partner'
        _inherit = 'res.partner'
        _columns = {
                    'm2m_right2left' : fields.many2many('res.partner','res_partner_rel','partner_right_id','partner_left_id'),
                    'm2m_left2right' : fields.many2many('res.partner','res_partner_rel','partner_left_id','partner_right_id'),
                    'o2m_left_ids': fields.one2many('res.partner.rel','partner_left_id'),
                    }

<

#file: partner_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record id="base_view_partner_form" model="ir.ui.view">
            <field name="name">openjobs.res.partner.form</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="arch" type="xml">
                <data>
                    <notebook position="inside">
                        <page string="Link Relations">
                            <field name="m2m_left2right" widget="many2many" />
                        </page>
                        <page string="Relations">
                            <field name="o2m_left_ids" widget="one2many" >
                                <tree>
                                    <field name='property_left2right'/>
                                    <field name='partner_right_id'/>
                                </tree>
                            </field>
                        </page>
                    </notebook>
                 </data>
            </field>
        </record>
    </data>
</openerp>

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: 11/27/13, 8:38 AM
Seen: 1943 times
Last updated: 3/16/15, 8:10 AM