Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

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

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
python2.7recursiondictionaryodoo8
1 Atsakyti
16361 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
ayman mohammed adam
Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

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

Registracija
Related Posts Replies Rodiniai Veikla
Pivot view does not display in odoo 8 Solved
python2.7 odoo8
Portretas
Portretas
1
spal. 22
6234
Odoo 8: how to prevent wizard from closing after a new one is opened?
wizard python2.7 odoo8
Portretas
Portretas
Portretas
2
lapkr. 17
6936
How to get values and keys from dict in odoo10
values python2.7 key dictionary
Portretas
Portretas
3
liep. 19
15498
How to validate the image dimension in odoo 9?
python2.7 openerp odoo8 odoo9
Portretas
0
rugs. 16
4328
NoneType' object is not callable" while evaluating Solved
pos xml python2.7 odoo8
Portretas
Portretas
Portretas
3
spal. 15
19725
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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