Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to hide a Sale Order Line based on "is_delivery"?

Odoberať

Get notified when there's activity on this post

This question has been flagged
attrsdomaintreeviewsale.order.line
4 Replies
9870 Zobrazenia
Avatar
Travis Waelbroeck

I want to update the existing Sales Order Line tree view that is embedded in the default Odoo 9 Sales Order form view to hide a row based on a condition of the sales order line. 


View being modified: sale.view_order_form

<notebook>

<page string="Order Lines">

<field name="order_line" mode="tree,kanban" attrs="{'readonly': [('state', 'in', ('done','cancel'))]}">

...

<tree string="Sales Order Lines" editable="bottom" decoration-info="invoice_status=='to invoice'">

<field name="sequence" widget="handle"/>

<field name="product_id"/>

<field name="name"/>

...

<field name="is_delivery" invisible="1"/>

...


Generally, there is only one item which "is_delivery", so I still want to see the rest of the items for the order.


I have tried using domain and attrs but so far I haven't had any success whatsoever. I think it is because the view is using the sale.order model, but the embedded tree view is using records from sale.order.line?


How can I hide the line item if "is_delivery" is True?


1
Avatar
Zrušiť
Ali Mahmoud

have you found a way to do so?

GORTHI VEKATA LAXMANA SASTRY

I am in the exact same situation, how did you came over this problem?
Thanks in advance

Avatar
Qutechs, Ahmed M.Elmubarak
Best Answer

Hello,

Just as a suggestion: try to add a new field to sale.order.line which is 'active', the active field toggle the global visibility of the record as in the documentation , and you can do some changes that when the order line set to is_delivery toTrue then set the active to False

hope this could helps

1
Avatar
Zrušiť
Avatar
Phong Vy
Best Answer

I resolved it by adding the following function to sale.order, tested on v17, 18 and 19

class SaleOrder(models.Model):

    _inherit = "sale.order"

    def web_read(self, specification: dict[str, dict]) -> list[dict]:

        res = super().web_read(specification)

        for so_data in res:

            if so_data.get('order_line', False):

                order_line = [item for item in so_data['order_line'] if not item['is_delivery']]

                so_data['order_line'] = order_line

        return res

0
Avatar
Zrušiť
Avatar
D Enterprise
Best Answer

Hii,

Inherit the sale.order model and add a computed One2many field:

from odoo import models, fields, api


class SaleOrder(models.Model):

    _inherit = 'sale.order'


    filtered_order_line = fields.One2many(

        comodel_name='sale.order.line',

        compute='_compute_filtered_order_line',

        string='Filtered Order Lines',

        store=False,  # not stored, always computed

    )


    @api.depends('order_line.is_delivery')  

    def _compute_filtered_order_line(self):

        for order in self:

            order.filtered_order_line = order.order_line.filtered(lambda l: not l.is_delivery)


Inherit the original Sales Order form view (sale.view_order_form) and replace the existing order_line field with your new computed field filtered_order_line.


<record id="view_order_form_hide_delivery" model="ir.ui.view">

    <field name="name">sale.order.form.hide.delivery.lines</field>

    <field name="model">sale.order</field>

    <field name="inherit_id" ref="sale.view_order_form"/>

    <field name="arch" type="xml">

        <xpath expr="//page[@string='Order Lines']/field[@name='order_line']" position="replace">

            <field name="filtered_order_line" mode="tree,kanban" attrs="{'readonly': [('state', 'in', ('done','cancel'))]}">

                <tree editable="bottom" string="Sales Order Lines">

                    <field name="sequence" widget="handle"/>

                    <field name="product_id"/>

                    <field name="name"/>

                    <field name="product_uom_qty"/>

                    <field name="price_unit"/>

                    <field name="tax_id"/>

                    <field name="price_subtotal"/>

                    <!-- Optional: include is_delivery as invisible just for context -->

                    <field name="is_delivery" invisible="1"/>

                </tree>

            </field>

        </xpath>

    </field>

</record>


i hope it is usefull



0
Avatar
Zrušiť
Avatar
LoreColon
Best Answer

Interesting question! I've tackled similar visibility issues. One approach is customizing the view definition using XPath expressions based on the 'is_delivery' boolean. Another simpler method might be leveraging computed fields & conditional formatting within Odoo's interface. If you're a fan of puzzles, this is like a code-based  

-1
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
How to access a field of another model in a button with the attrs attribute?
attrs sale.order.line
Avatar
Avatar
1
mar 16
9114
How to use Domain in tree view? Solved
domain treeview
Avatar
Avatar
Avatar
3
mar 15
53314
attrs not working????
attrs treeview
Avatar
Avatar
Avatar
Avatar
Avatar
4
mar 15
12226
How to domain a tree view to make admin show all data but other role only specific?
domain treeview odoo16
Avatar
Avatar
1
jún 24
3158
What is diff between domain, domain filter and attr ?
filter attrs domain
Avatar
1
jan 24
15961
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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