Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profit organisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

delegation inheritance, parent to child, child to parent, odoo 11

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
inheritanceinheritdelegationinheritsodoo11
1 Beantwoorden
12751 Weergaven
Avatar
ai

I have 3 classes:

class Parent(models.Model):

    _name='parent.parent'


class Child1(models.Model):

    _name="child.child1"

    _inherits={'parents.parents': 'parent_id'}

    parent_id = fields.Many2one('parent.parent', required=True, ondelete="cascade")

class Child2(models.Model):

    _name="child.child2"

    _inherits={'parents.parents': 'parent_id'}

    parent_id = fields.Many2one('parent.parent', required=True, ondelete="cascade")

How can I navigate from parent.parent to his (all) children? Do I need to declare to new fields in the parent like ?:

child1 = fields.Many2one('child.child1', store=False)

child2 = fields.Many2one('child.child2', store=False)

Is there a better solution?




0
Avatar
Annuleer
Adrien

'store' is used for computed fields which are by default not stored in database, so you can add store=True to store it.

In your example, the use of store=False is irrelevant.

Also, it seems you need to understand better the inheritance concept and relational field concept. See my answer below.

Avatar
Adrien
Beste antwoord

Hi,

1. About Model inheritance

First of all, are you sure you really need "_inherits" ?
It is much more common to use "inherit" which works like this :
_name = 'child1.child1'
_inherit = ['parent.parent']
And then you can use the field of the parent in the child object :
child1.parent_field

If you don't know the difference, see e.g. :

https://www.odoo.com/fr_FR/forum/how-to/developers-13/the-different-openerp-model-inheritance-mechanisms-what-s-the-difference-between-them-and-when-should-they-be-used-46


2. About parent / child relation :

This is not related with inheritance but to relational fields.

In that case you can have :

- a One2many field in the parent model to its children

example : child1_ids = fields.One2many(comodel_name='child1.child1', inverse_name='parent_id')

then you can do:

for child1 in parent.child1_ids:

    ... do smth ...

- a Many2one field in the child object to its parent (that must then be called 'parent_id' to correspond to the 'inverse_name' used before)

see for example the link between a partner and its contacts in native Odoo.

And explanation of relational fields :

https://www.odoo.com/fr_FR/forum/aide-1/question/relational-fields-114056

1
Avatar
Annuleer
ai
Auteur

Thanks, Yes I think I need inherits. Because I have many classes which use the parent.parent. If I use One2many and Many2one, I need to declare many of them in parent.parent. I want to access some attributes of the child1, child2, childn from parent.parent.

Maybe, I want to display/choose children with fields.Many2one(parent.parent) in a view.

Is this possible?

Adrien

It is not clear what you mean and need.

Can you clarify what you need :

- parent/child relation between RECORDS ? ===> This is handled with relational fields

- or parent/child relation between MODELS ==> This is handled with inheritance

Maybe you could provide a minimal practical example of what you want to do?

ai
Auteur

class Selector(models.Model):

_name = 'selector.model'

selectOne = fields.Many2one('parent.parent')

fieldOfChildren1 = fields.Char(related='selectOne.attributeOfChildren1')

fieldOfChildren2 = fields.Integer(related='selectOne.attributeOfChildren2')

Is this somehow possible?

I think it is relation between MODELS.

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
violates not-null constraint
inheritance delegation inherits odoo12
Avatar
Avatar
1
dec. 19
6591
delete inherited child (inherits) odoo 12
inheritance many2one delegation odoo11 odoo12
Avatar
0
okt. 18
4499
Odoo 11: Adding child model to res.partner Opgelost
inheritance odoo11
Avatar
Avatar
1
sep. 19
4920
How to change field default value in model 'A' when changing field from model 'B' ?
inherit odoo11
Avatar
Avatar
Avatar
2
sep. 19
7069
How to extend an existing class and include social newtork features in the sub class
inheritance inherit
Avatar
Avatar
3
jul. 18
4643
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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