Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

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

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
inheritanceinheritdelegationinheritsodoo11
1 Rispondi
12753 Visualizzazioni
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
Abbandona
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
Risposta migliore

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
Abbandona
ai
Autore

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
Autore

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.

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
violates not-null constraint
inheritance delegation inherits odoo12
Avatar
Avatar
1
dic 19
6595
delete inherited child (inherits) odoo 12
inheritance many2one delegation odoo11 odoo12
Avatar
0
ott 18
4499
Odoo 11: Adding child model to res.partner Risolto
inheritance odoo11
Avatar
Avatar
1
set 19
4922
How to change field default value in model 'A' when changing field from model 'B' ?
inherit odoo11
Avatar
Avatar
Avatar
2
set 19
7069
How to extend an existing class and include social newtork features in the sub class
inheritance inherit
Avatar
Avatar
3
lug 18
4645
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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