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

Is it possible to hide delete button for some rows in a tree view ?

Iscriviti

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

La domanda è stata contrassegnata
xmlviewdelete
5 Risposte
30527 Visualizzazioni
Avatar
user0780987

Hi,

I have a view like this :

    <field name="product_line_ids" nolabel="1">
      <tree version="7.0">
        <field name="product_id" context="{'product_name_display': 'short'}" />
        <field name="name" />
        <field name="price_unit" />
        <field name="product_qty" />
        <field name="uom_id" />
        <field name="total" />
        <field name="is_included" />
        <field name="avg_price" />
        <field name="is_bought" />
        <field name="origin" />
        <field name="budget_line_id" />
        <field name="purchase_order_id" />
        <field name="type" invisible="1" />
      </tree>
      <form version="7.0">
        <group col="4">
          ...
        </group>
      </form>
    </field>

Depending if purchase_order_id is False or not, I would like to enable / disable the delete button on my view.

How can I achieve this ?

Thank you very much

0
Avatar
Abbandona
user0780987
Autore

Thank you Bole, This is an acceptable workaround, indeed. Too bad it's not possible to have this behaviour because with your solution, an error will appear on screen. I prefer to restrict user's actions instead of having error messages. Do you know if it's possible to create some function in javascript or jquery to realize client-side validation?

Avatar
Aksana Ivanova
Risposta migliore

You always can do:

<tree string="XX" editable="top"  delete="false">

...

    <button name="unlink" icon="gtk-cancel" type="object" string="Delete"

                                        attrs="{'invisible': [('your_condition', '=', 0)]}"/>

1
Avatar
Abbandona
Avatar
Bole
Risposta migliore

Normaly if you need to restrict deletion on objects you would define a view like:
<field name="product_line_ids" nolabel="1">
      <tree version="7.0" delete="false">.....

This will disable delete option completly on view 

There is no way of putting condition on delete function, it is enabled or disabled....

Workaround is...

If you need to check for some value and accordingly allow or not deletion....
You need to define an unlink method in your .py file for that class like:
 

def unlink(self, cr, uid, ids, context=None):
    for line in self.browse(cr, uid, ids):
        if line.purchase_order_id:
            raise osv.except_osv('error!', 'not allowed to delete record with purchase_line_id')
    return super(name_of_class, self).unlink(cr, uid, ids)

This way delete function is enabled, but before actual deletion some data check is made, and if certain condition is met 
(in this case existing purchase_order_id) system will raise error and will not allow deletion of selected records
Instead of raising error you may also remove id wich contains purchase_order_id from ids list and continue with unlinking (deleting) other records that are ok to be deleted... 

hope this helps...
p.s. the syntax of unlink method if for v7, but should work in v8 also 

look for other examles of unlink methods in some classes and expand to your needs

3
Avatar
Abbandona
Avatar
Agile
Risposta migliore

You can use this function this is working for me.
def unlink(self, cr, uid, ids, context=None):
    for line in self.browse(cr, uid, ids):
        if line.purchase_order_id:
            raise osv.except_osv('error!', 'not allowed to delete record with purchase_line_id')
    return super(name_of_class, self).unlink(cr, uid, ids)

0
Avatar
Abbandona
Avatar
caterjohn1@gmail.com
Risposta migliore
def unlink ( self ): 
"" "
Purpose: to prevent deleting of a YOUR_OBJECT in status NAME_OF_YOUR_STATUS
" ""
for order in self : if order.YOUR_CONDTION in ( ' NAME_OF_YOUR_STATUS_1','NAME_OF_YOUR_STATUS_2', 'CAN_HAVE_MULITPLE_CONDITIONS_OR_YOU_CAN_JUST_HAVE_ONE):raiseUserError ('TYPE_YOUR_ERROR_MESSAGE_HERE_FOR_USER_TO_SEE')returnsuper(YOUR_CLASS_NAME,self) .unlink ()



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à
How do I remove a button from the sale.order.form? Risolto
xml view
Avatar
Avatar
Avatar
Avatar
Avatar
6
set 17
9362
How do I change default text from a module view?
xml view
Avatar
Avatar
1
mar 15
6849
XML from module not loaded after changes.
xml view
Avatar
Avatar
2
mar 15
10789
display view if user is anonymous
xml view
Avatar
Avatar
1
mar 15
5139
view xml, attrs use variable with attribute Risolto
attrs xml view
Avatar
Avatar
1
mar 24
11380
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