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

How to hide a field/column inside a Tree based on conditions in Odoo 17

Odebírat

Get notified when there's activity on this post

This question has been flagged
treeviewcolumsodoo 17
2 Odpovědi
3846 Zobrazení
Avatar
Sonny

I need to hide a column depending on a condition. This is a snippet of the Shipment Package Line model:

class ShipmentPackageLine(models.Model):
    _name = 'shipment.package.line'
    _rec_name = 'package'
    ...
    gross_column_air_hidden = fields.Boolean(compute='_compute_column_visibility')
   
    @api.depends('shipment_id.transport')
    def _compute_column_visibility(self):
        for line in self:
            if (line.shipment_id.transport == 'air'):
                line.gross_column_air_hidden = True
                _logger.info('Gross column set to invisible')
            else:
                line.gross_column_air_hidden = False
                _logger.info('Gross column set to visible')

Here is the Freight Shipment model:

class FreightShipment(models.Model):
    _name = 'freight.shipment'
    _inherit = ['mail.thread', 'mail.activity.mixin']
    ...
    transport = fields.Selection(([('air', 'Air'), ('ocean', 'Ocean'), ('land', 'Land')]),
                                 string='Transport Via')
    freight_packages = fields.One2many('shipment.package.line', 'shipment_id')


This is the XML view template snippet, please note that the model used in the Freight Shipment

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record model="ir.ui.view" id="freight_shipment_form_view">
            <field name="name">freight.shipment.form.view</field>
            <field name="model">freight.shipment</field>
            <field name="arch" type="xml">
                <form edit="stage_id != 5">
                ...
                <notebook>
                ...
                   <page string="Package Details">
                       <field name="freight_packages" nolabel="1" widget="one2many_list">
                          <tree string="Package">
                             <field name="gross_column_air_hidden" invisible="1" column_invisible="1"/>
                             <field name="name" />
                             <field name="seal_number"/>
                             <field name="package_type"/>
                             <field name="package" required="1"/>
                             <field name="container_type" optional="hide"/>
                             <field name="qty" sum="Total Qty."/>
                             <field name="volume" column_invisible="gross_column_air_hidden"/>
                             <field name="gross_weight" column_invisible="gross_column_air_hidden"/>
                             <field name="net_weight" sum="Total Net"/>
                             <field name="total_cbm" column_invisible="gross_column_air_hidden"/>
                             <field name="line_added" column_invisible="1"/>
                             <button name="action_insert_line_service" type="object" string="Add to Service"
                                 icon="fa-plus-square-o" invisible="line_added"/>
                          </tree>
                        ...


I got the error:

UncaughtPromiseError > OwlError
Uncaught Promise > An error occurred in the owl lifecycle (see this Error's "cause" property)
OwlError: An error occurred in the owl lifecycle (see this Error's "cause" property)
    Error: An error occurred in the owl lifecycle (see this Error's "cause" property)
        at handleError (.../web/assets/518164d/web.assets_web.min.js:916:101)
        at App.handleError (.../web/assets/518164d/web.assets_web.min.js:1559:29)
        at Fiber._render (.../web/assets/518164d/web.assets_web.min.js:941 :19)
        at Fiber.render (.../web/assets/518164d/web.assets_web.min.js:939:6)
        at ComponentNode. initiateRender (.../web.assets_web.min.js:1009:47)

Caused by: EvalError: Can not evaluate python expression: (bool(gross_column_air_hidden))
    Error: Name 'gross_column_air_hidden' is not defined
    EvalError: Can not evaluate python expression : (bool(gross_column_air_hidden))
    Error: Name 'gross_column_air_hidden' is not defined
        at evaluateExpr (.../web/assets/518164d/web.assets_web.min.js:3068:54)
        at evaluateBooleanExpr (.../web/assets/518164d/web.assets_web.min.js:3071:8)
        at Object .evalViewModifier (.../web/assets/518164d/web.assets_web.min.js:8599:154)
        at ListRenderer.evalColumnInvisible (.../web/assets/518164d/web.assets_web.min.js:9508:56)
        at .../web/assets/518164d/web.assets_web.min.js:9409:9
        at Array .filter (<anonymous>)
        at ListRenderer.getActiveColumns (.../web/assets/518164d/web.assets_web.min.js:9407:47)
        at ListRenderer.setup (.../web/assets/518164d/web.assets_web.min.js:9401:456)
        at ListRenderer.setup (.../web/assets/518164d/web.assets_web.min.js:17112:861)
        at ListRenderer.setup (.../web/assets/518164d/web.assets_web.min.js:17793:535)


If i used invisible instead of column_invisible, there would be no error, but the column will be shown


How can I fix this?


0
Avatar
Zrušit
Sonny
Autor

I noticed that when I used 'invisible' instead of 'column_invisible', the values under the columns are hidden/not showing but the column is still showing. If I used 'column_invisible', it will prompt an error that the 'gross_column_air_hidden' is undefined even though I have defined it.

Sonny
Autor

Hi Sahar, I cannot comment on your reply since I do not have points. How should I solve this? If I use a field inside the tree from the shipment.package, it would not be recognize. For example, the transport field, it will show Caused by: EvalError: Can not evaluate python expression: (bool(transport == 'air'))
Error: Name 'transport' is not defined
EvalError: Can not evaluate python expression: (bool(transport == 'air'))

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

Hi,

If you're in a nested tree view inside a form, and the visibility of a column depends on a flag set in the parent form (like a boolean field), you must use the' parent.' prefix. Otherwise, Odoo will not find the variable, and the column might not behave as expected.


Use the code column_invisible="parent.gross_column_air_hidden" instead of column_invisible="gross_column_air_hidden" to ensure that the field's visibility is controlled by the parent context variable.


Hope it helps.

0
Avatar
Zrušit
Avatar
Sahar Dagher
Nejlepší odpověď

The field used in the column_invisible must be belong to the shipment.package model not shipment.package.line,
to hide the column if the parent model meets a certain condition.

0
Avatar
Zruš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
How can I add a small dashboard above a tree view in Odoo 17?
views treeview listview dashboard odoo 17
Avatar
Avatar
1
zář 25
809
Send Email after payment creted for invoice
odoo 17
Avatar
Avatar
Avatar
2
zář 25
2454
Why Doesn't the Hamburger Menu Show for My Custom Group User Despite Adding ir_ui_menu Access Right?
odoo 17
Avatar
Avatar
1
kvě 25
2030
How to Align Left [float, integer] Fields in Tree View in Odoo
treeview
Avatar
Avatar
Avatar
Avatar
3
dub 25
5883
Como heredo de un modal en Odoo 17
odoo 17
Avatar
0
led 25
1494
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