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

How to create a recursive function in Python to create a dict which maps Odoo 8 relational field records?

Abonare

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

Această întrebare a fost marcată
python2.7recursiondictionaryodoo8
1 Răspunde
16363 Vizualizări
Imagine profil
SlyK

Hi everyone,

I am trying to create a Python function that maps nodes of a web created by Odoo relational fields, and returns such map as a dictionary. 

I'll try to explain. 


Let us consider the model 'account.account', and its fields 'child_parent_ids' (o2m to same class) and 'parent_id' (m2o to same class, inverse of previous field). 

How can I create a dictionary where every key is a record of 'account.account', and every key's values are dictionaries made of their children records recursively, or 'True' if such record has no child records? 


E.g., let us consider this web:

account

|

|_child-1

|

|_child-2

|            |

|            |_child-21

|            |_child-22

|            |_child-23

|

|_child-3

|             |

|             |_child-31

|             |_child-32

|             |              |

|             |              |_child-321

|             |              |_child-322

|             |              |_child-323

|             |              |_child-324

|             |

|             | _child-33

|

|_child-4

 

The function I'm looking for should return a dictionary like this:

{'account':

    {'child-1': True},

    {'child-2':

        {'child-21': True},

        {'child-22': True},

        {'child-23': True},

    },

    {'child-3':

        {'child-31': True},

        {'child-32':

            {'child-321': True},

            {'child-322': True},

            {'child-323': True},

            {'child-324': True}

        },

        {'child-33': True},

    }

    {'child-4': True},

}

 

I tried to create a recursive function as follows:


@api.multi

def get_tree_dict(self):

    tree_dict = {}

    if self.child_parent_ids:

        for child in child_parent_ids:

        tree_dict[self] = child.get_tree_dict()

    return tree_dict

    else:

        tree_dict[self] = True

        return tree_dict

 

It doesn't seem to work, and I can't find out why (please don't be too hard on me).

Can please anyone help me, by showing the error I'm making and how can I solve it?

Please note that the depth of the dictionary is not known a priori, so I think the method should be recursive (or iterative).

0
Imagine profil
Abandonează
Imagine profil
ayman mohammed adam
Cel mai bun răspuns

Dear SLYK;

Try to make this by using while , that better to make recursive , but you need  the Right Condition to prevent infinite loop.

I hope I helped you...

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
Pivot view does not display in odoo 8 Rezolvat
python2.7 odoo8
Imagine profil
Imagine profil
1
oct. 22
6235
Odoo 8: how to prevent wizard from closing after a new one is opened?
wizard python2.7 odoo8
Imagine profil
Imagine profil
Imagine profil
2
nov. 17
6936
How to get values and keys from dict in odoo10
values python2.7 key dictionary
Imagine profil
Imagine profil
3
iul. 19
15500
How to validate the image dimension in odoo 9?
python2.7 openerp odoo8 odoo9
Imagine profil
0
sept. 16
4328
NoneType' object is not callable" while evaluating Rezolvat
pos xml python2.7 odoo8
Imagine profil
Imagine profil
Imagine profil
3
oct. 15
19727
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