Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

v14: how can i get parent value in the creation of child?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
parentchildv14
2 Odpowiedzi
6852 Widoki
Awatar
SmithJohn45

model is 'product.category ', want to inhereit and add a field 'level' to add the levels to find which level record i want.

we knew that by default (as recommended) that first entry 'All' here should present to start the parent child relations.

when user create a new category and select All as its parent, we knew that its level is 1 and we can add 2, programatically it should be parent level + 1 ... so we can add levels of any depth.

i don't know how to code it, so please help me for the below onchange function (or any other better approach, please specify), modify it to achieve what i wants to have.

@api.onchange(parent_id):

def _onchange_parent_id(self):

  find the level of parent here...

  self.level = parent_level + 1

regards


0
Awatar
Odrzuć
Awatar
Neha Sharma
Najlepsza odpowiedź

Hello SmithJohn45,

Suppose we have a product category hierarchy as below


A > B > C > D


and we need to find the level for the category "C" with the code (the answer is 3)

So to find the level for the category, here is the method that you need to write:


def find_level_of_category(self, catg_id):

    level = 1

    if catg_id.parent_id:

        parent_id = catg_id.parent_id

        while (parent_id):

            level += 1

            parent_id = parent_id.parent_id

        return level

    return level



You can simply call this method to your onchange, you need to pass "self.parent_id" as a parameter into the above method, so it will give you the level of the "self.parent_id".


Thanks!

For more information Contact us:- https://kanakinfosystems.com/odoo-development-services

0
Awatar
Odrzuć
SmithJohn45
Autor

thank you @Neha Sharma for help :), will implement and give feedback here.

SmithJohn45
Autor

@Neha Sharma, please check, if it is ok or i made mistake(s)

from odoo import api, fields, models

class ProductCateg(models.Model):

_inherit = 'product.category'

level = fields.Integer(string='Level')

@api.onchange('parent_id')

def find_level_of_category(self):

levels = 1

if self.parent_id:

parent_id = self.parent_id

while (parent_id):

levels += 1

parent_id = parent_id.parent_id

self.level = levels

regards

Neha Sharma

# -*- coding: utf-8 -*-

from odoo import api, fields, models

class ProductCateg(models.Model):

_inherit = 'product.category'

level = fields.Integer(string='Level')

@api.onchange('parent_id')

def onchange_parent_id(self):

if self.parent_id:

level = self.find_level_of_category()

self.level = level

def find_level_of_category(self):

level = 1

if self.parent_id:

parent_id = self.parent_id

while (parent_id):

level += 1

parent_id = parent_id.parent_id

return level

return level

SmithJohn45
Autor

@Neha Sharma, implemented the code for model, updated manually level column for All to 1 and All / Electronics to 2, from UI created a record, choose All / Electronics as its parent, but level not updated with required value. ( i have copy/pasted your last code as it is, indent with pycharm option and restart server, upgraded module and then checked ) anything else i missed ?

Neha Sharma

Can you share a screenshot of your pycharm code?

SmithJohn45
Autor

can't post screenshot here, so i have to use Answer portion here...

SmithJohn45
Autor

@Neha Sharma, i have added screenshot, please check.

Neha Sharma
Okay I will attach .py and xml file and video or flow maybe it helps you


On Fri, 29 Jan 2021 at 15:47, SmithJohn45 <oralover2006@gmail.com> wrote:

@Neha Sharma, i have added screenshot, please check.

Sent by Odoo S.A. using Odoo.

Neha Sharma

i have sent a mail to you with attached .py and xml file along with video maybe it works

SmithJohn45
Autor

thanks @Neha Sharma for your struggle to help me, i have seen in my gmail account for your email but not yet received, also checked in Spam, may be sometimes take time, will check after 15 minutes. thanks again :)

Neha Sharma
Ok, no problem. 

On Fri, 29 Jan 2021 at 18:15, SmithJohn45 <oralover2006@gmail.com> wrote:

thanks @Neha Sharma for your struggle to help me, i have seen in my gmail account for your email but not yet received, also checked in Spam, may be sometimes take time, will check after 15 minutes. thanks again :)

Sent by Odoo S.A. using Odoo.

Neha Sharma
Have you received my mail?

On Fri, 29 Jan, 2021, 6:15 PM SmithJohn45, <oralover2006@gmail.com> wrote:

thanks @Neha Sharma for your struggle to help me, i have seen in my gmail account for your email but not yet received, also checked in Spam, may be sometimes take time, will check after 15 minutes. thanks again :)

Sent by Odoo S.A. using Odoo.

SmithJohn45
Autor

@Neha Sharm, no, not yet received email, don't know why, even checked Spam and also Trash may be i accidently deleted but failed to find the email. what is the Subject of email? and is it through Odoo platform?

how i can request a feature in forum, there is no notification here within forum if someone Answer or Comment... user should check the email or On email's notification, but it is not possible for us especially when we are on Client.

Neha Sharma
okay, I will be sent you a mail again with some attachments of the .py and XML file and video flow.


On Sat, 30 Jan 2021 at 09:22, SmithJohn45 <oralover2006@gmail.com> wrote:

@Neha Sharm, no, not yet received email, don't know why, even checked Spam and also Trash may be i accidently deleted but failed to find the email. what is the Subject of email? and is it through Odoo platform?

how i can request a feature in forum, there is no notification here within forum if someone Answer or Comment... user should check the email or On email's notification, but it is not possible for us especially when we are on Client.

Sent by Odoo S.A. using Odoo.

Neha Sharma
I already sent you mail again if you find it then please reply to my mail.
Thanks...

On Mon, 1 Feb 2021 at 16:34, Neha Sharma <nsa@kanakinfosystems.com> wrote:
okay, I will be sent you a mail again with some attachments of the .py and XML file and video flow.


On Sat, 30 Jan 2021 at 09:22, SmithJohn45 <oralover2006@gmail.com> wrote:

@Neha Sharm, no, not yet received email, don't know why, even checked Spam and also Trash may be i accidently deleted but failed to find the email. what is the Subject of email? and is it through Odoo platform?

how i can request a feature in forum, there is no notification here within forum if someone Answer or Comment... user should check the email or On email's notification, but it is not possible for us especially when we are on Client.

Sent by Odoo S.A. using Odoo.

Awatar
SmithJohn45
Autor Najlepsza odpowiedź

@Neha Sharma, screenshot is here as instructed. (already mentioned in my opening post that "i don't now how to code it" so, it is copy pasted as you did it for me)


0
Awatar
Odrzuć
Julian Dumitrascu

Where did you paste it?

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
ver 14: how to search parent_id and its all child in model product.category in Many2one field
domain parent child v14
Awatar
Awatar
1
lip 23
6292
How to add child view field in Parent search view
parent child
Awatar
Awatar
1
mar 15
8469
Odoo Project oddities and limitations
project task parent child
Awatar
Awatar
1
kwi 24
2481
How to create Workcenter childs?
tree workcenter child v14
Awatar
0
lis 21
2605
How do i get a parent model in a child model?
models parent model child
Awatar
0
maj 17
4831
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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