Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

How to add a field conditional to tree view of customer?

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
treeviewviewres.partnerhideinherit
4 Risposte
40155 Visualizzazioni
Avatar
Anabela Damas

Hi,

I've added a supplier number and a customer number, and now I need to add this number in the tree view but I just want that the "Supplier number " appears if there is a partner is a supplier or in the view. I'll try to explain with images.

In this case when a partner is both(supplier and a costumer), it's ok to look like this: both

In this case I didn't want to show the Supplier Number: image description

And in this case I didn't want to show the Client Number: image description

I'm using this code:

<record id="view_partner_tree_inherit" model="ir.ui.view">
    <field name="name">res.partner.tree.inherit</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_tree" />
    <field name="arch" type="xml">
    <xpath expr="/tree/field[@name='name']" position="after">
        <field name="supplier" invisible="1"/>
        <field name="customer" invisible="1"/>
        <field name="n_client" attrs="{'invisible':[('customer','!=',True)]}"/>
        <field name="n_supplier" attrs="{'invisible':[('supplier','!=',True)]}"/>
        </xpath>
    </field>
</record>

Someone know how to hide the columns depending on if it is a Suppliers tree view or a Customers tree view ?

Thanks

2
Avatar
Abbandona
Avatar
vim24
Risposta migliore

Having just scoured the internet looking for an answer to a similar problem myself I can tell you how I finally got something similar working:

Instinct told me to try the

attrs="{'invisible':[('customer','!=',True)]}"

approach too. But, I believe attrs don't work to stop the column name itself from appearing in a tree view (works only on the values of each row).

Instead, you need to overwrite the fields_view_get method from within your res_partner python code, which will allow you to change the viability of each column by checking the context. In my case I was looking at Supplier vs Customer invoices, so I checked for the context 'type' being 'out_invoice'/'in_invoice'. In your case I believe customers vs suppliers are given a context value, something like "default_customer" and "default_supplier".

Anyway, in the end you want to remove the attrs element from you xml view and then add something like this to the python code:

  from lxml import etree

  def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):

    if context is None:
        context = {}

    res = super(res_partner,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

    doc = etree.XML(res['arch'])

    if view_type == 'tree':
        if context.get('default_customer', '0') in ('1'):
            for node in doc.xpath("//field[@name='n_supplier']"):
                doc.remove(node)
        if context.get('default_supplier', '0') in ('1'):
            for node in doc.xpath("//field[@name='n_client']"):
                doc.remove(node)

        res['arch'] = etree.tostring(doc)
    return res

I can't guarantee this will work straight off as I havn't tested it for your case, you might need to tweak some values above. Nor can I guarantee this is the best way to achieve this. But I can say very similar code is working perfectly for me in my situation.

Hope that helps :)

2
Avatar
Abbandona
Avatar
Mohamad Chamra
Risposta migliore

in tree view, you should use  column_invisible instead of invisible:

attrs="{'column_invisible ':[('customer','!=',True)]}"


1
Avatar
Abbandona
Andres Brigard

Thanks, worked great in Odoo 12

Avatar
Tintumon
Risposta migliore

For other view like "form view" it works fine

attrs="{'invisible':[('customer','!=',True)]}"

If you use this attrs in Tree view it just hide the data/content which shown in that column. Not the complete column.


So I just tried using this instead of above code:

invisible = "context.get('customer') != True"

And it helped me to hide the complete column from Tree view.

1
Avatar
Abbandona
Avatar
Gustavo
Risposta migliore

Using the attrs XML attributes to set the invisible attribute of an element is not working. In fact, this attrs will only show or hide the content of the tree view, not the entire column. After searching for some solutions from google, i found this one is working. As an example, i add two new fields on invoice model (called ref_partner_id and sales_inv) and it will shows on the invoice tree view only if the type is out_invoice (supplier invoice):

<field name=”ref_partner_id” string=”Customer (name)” invisible=”context.get(‘type’) == ‘out_invoice’ “/>
<field name=”sales_inv”  invisible=”context.get(‘type’) == ‘out_invoice’ “/>

This will work because we got the context variable that inform us the type of invoices currently being displayed on the tree. This comes from the account module (account_invoice_view.xml), for example on the action_invoice_tree2:

<record id=”action_invoice_tree2″ model=”ir.actions.act_window”>
<field name=”name”>Supplier Invoices</field>
<field name=”res_model”>account.invoice</field>
<field name=”view_type”>form</field>
<field name=”view_mode”>tree,form,calendar,graph</field>
<field eval=”False” name=”view_id”/>
<field name=”domain”>[('type','=','in_invoice')]</field>
    <field name=”context”>{‘default_type’: ‘in_invoice’, ‘type’: ‘in_invoice’, ‘journal_type’: ‘purchase’}</field>
</record>

Source: http://vitraining.com/show-hide-columns-in-openerp-tree-view-xml/

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Creating new view from a old view Risolto
view res.partner inherit
Avatar
Avatar
11
gen 24
14467
inherit res.partner view
view res.partner inherit
Avatar
Avatar
1
mar 15
12025
Hide the misc group in res.partner view in sale & purchases page
view res.partner hide group odoo18
Avatar
Avatar
1
mag 25
1526
How to inherit list (tree) view? Risolto
treeview inherit
Avatar
Avatar
Avatar
3
gen 24
16007
Why is my Custom TreeView showing only one record, instead of a list of records? Risolto
treeview view
Avatar
Avatar
2
mag 18
4892
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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