Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

many2many relation with attributes

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
relationshipmany2manyattribute
2 Răspunsuri
25205 Vizualizări
Imagine profil
Martin Varela

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
Imagine profil
Abandonează
Imagine profil
Adan Cortes Medina
Cel mai bun răspuns

To create a self-related Many2many relation, the following parameters must be used: relation, column1 and column2. The value given to the former parameter will become the table name in the database, while the values given to column1 and column2 will become field names for the afore mentioned table so, in order to add attributes, we simply declare a new model which uses exactly the same table and fields, thus tricking the Odoo's ORM.

from openerp import api, fields, models

class MainModel(models.Model):
    _name = 'mymodule.mainmodel'
    # See https://www.odoo.com/documentation/10.0/reference/orm.html#relational-fields 
    related_ids = fields.Many2many('mymodule.mainmodel', relation='mymodule_mainmodel_rel', column1='left', column2='right', string='Related instances')
    # ... more field definitions

class MainmodelRelations(models.Model):
    _name = 'mymodule.mainmodel.rel'
    left = fields.Integer(string='Left', required=True)
    right = fields.Integer(string='Right', required=True)
    # ... more field definitions:
relationship = fields.Selection(string='Left to Right Relationship', selection='_get_relationship', required=True)
    def _get_relationship(self):
        return [
            ('01','relationship1'),
            ('02','relationship2'),
            ('03','relationship3')#,
      # ... and so on
        ]
# In case the relationship is not reflexive, otherwise this can be omitted
    @api.one
    @api.constrains('left', 'right')
    def _check_description(self):
        if self.left == self.right:
            raise ValidationError("A MainModel instance cannot be related to itself.")

Note: This is a redacted code taken from one that worked for me with Odoo 10 but I'm confident it works with earlier versions.


1
Imagine profil
Abandonează
Imagine profil
Evelb Tecnicas Y Sistemas Sl.
Cel mai bun răspuns

#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>
0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to get Value for Relation table in odoo 10 Rezolvat
relationship many2many odoo10
Imagine profil
Imagine profil
2
iun. 17
7166
Why my bidirectional many2many is not showing data?
inheritance relationship many2many
Imagine profil
Imagine profil
2
mar. 15
12686
Many2many relation on the same model does not work Rezolvat
fields relationship many2many model
Imagine profil
Imagine profil
3
iun. 18
15838
Allowing groups to only edit relationship fields in a model
security relationship many2many groups
Imagine profil
0
oct. 16
3393
ODOO V16 Associate Parts to a Finished Good
many2many
Imagine profil
Imagine profil
1
feb. 24
2924
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now