Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
parentchildv14
2 Odpovědi
6837 Zobrazení
Avatar
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
Avatar
Zrušit
Avatar
Neha Sharma
Nejlepší odpověď

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
Avatar
Zrušit
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.

Avatar
SmithJohn45
Autor Nejlepší odpověď

@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
Avatar
Zrušit
Julian Dumitrascu

Where did you paste it?

Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
ver 14: how to search parent_id and its all child in model product.category in Many2one field
domain parent child v14
Avatar
Avatar
1
čvc 23
6283
How to add child view field in Parent search view
parent child
Avatar
Avatar
1
bře 15
8458
Odoo Project oddities and limitations
project task parent child
Avatar
Avatar
1
dub 24
2451
How to create Workcenter childs?
tree workcenter child v14
Avatar
0
lis 21
2589
How do i get a parent model in a child model?
models parent model child
Avatar
0
kvě 17
4808
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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