Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

Show or hide a server action button based on a field value on odoo V17 CE

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
actiondevelopementvisibilityserver_actions17.0
3 Replies
2178 Tampilan
Avatar
Master

Hi,

How can I show or hide a server action button based on a field value in my model?

For example, if the state field is 'closed', I want the "Open" button to be visible.

And if the state is 'open', I want the "Close" button to be displayed instead.

Is there a way to conditionally show or hide these server actions depending on the record's state?


<record id="mymodel_open_action_server" model="ir.actions.server">

<field name="name">Open mymodel</field>

<field name="model_id" ref="model_mymodel"/>

<field name="binding_model_id" ref="model_mymodel"/>

<field name="binding_view_types">form</field>

<field name="state">code</field>

<field name="code">

action = records.open_action()

</field>

0
Avatar
Buang
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Jawaban Terbai

Hi,

Please refer to the solved forum:

1. https://www.odoo.com/id_ID/forum/help-1/how-to-hide-action-button-based-on-condition-246523

2. https://www.odoo.com/id_ID/forum/help-1/hide-a-menu-inside-action-button-based-on-condition-168198


Hope it helps.

0
Avatar
Buang
Avatar
slckatav
Jawaban Terbai

Hey, could you share your open_action() function as well? Since you’d prefer not to use a button seeing that code will help me suggest the right approach. In general you can add an attrs to your XML to toggle visibility. For example:

attrs="{'invisible': [('state', 'in', ['sale'])]}"

This will hide the element when state is not in the “sale” stage. Of course, you can adjust the domain or use different attribute just a quick example to get you started.

0
Avatar
Buang
Master
Penulis

Hi, you can see my code below for more details:

<!-- Server Action -->
<record id="mymodel_closed_action_server" model="ir.actions.server">
<field name="name">Close</field>
<field name="model_id" ref="model_mymodel"/>
<field name="binding_model_id" ref="model_mymodel"/>
<field name="state">code</field>
<field name="code">action = records._action_close()</field>
</record>

def _action_close(self):
for rec in self:
if rec.state != "closed":
print("My logic goes here!")
rec.state = "closed"

slckatav

I once hid some action buttons by finding their generated names. Odoo assigns its own names to action buttons like button name="356". In your case, after you add your action button find the name that Odoo generated and then add XML like this:

<xpath expr="//button[@name='466']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>

I hope this helps!

Avatar
D Enterprise
Jawaban Terbai

Hiii,

To show/hide buttons based on the state field in Odoo 17 Community Edition , you must use button elements inside the form view , not ir.actions.server bindings, because ir.actions.server buttons do not support dynamic visibility using attrs .

Here's the correct and clean implementation :

Model: mymodel.py

Define state , action_open , and action_close :

from odoo import models, fields class MyModel (models.Model): _name = 'mymodel' _description = 'My Model' state = fields.Selection([ ( 'open' , 'Open' ), ( 'closed' , 'Closed' ) ], default= 'open' , string= 'State' ) def action_open ( self ): for record in self: record.state = 'open' def action_close ( self ): for record in self: record.state = 'closed'

View: mymodel_form_view.xml

Inherit or define your form view and add two buttons, conditionally shown using attrs .

<record id ="view_form_mymodel" model="ir.ui.view"> <field name = "name" >mymodel.form </field> <field name = "model" >mymodel </field> <field name = "arch" type = "xml"> <form string = "My Model"> <header> <button name="action_open"

​ ​ ​ ​ ​        type="object"

​ ​ ​ ​​        string="Open"

        ​ ​ ​ ​ ​invisible="state != 'closed'"/> <button name="action_close"

​ ​ ​ ​ ​        type="object"

​ ​ ​ ​ ​        string="Close"

​ ​ ​ ​ ​        invisible="state != 'open'"/> </header> <sheet> <group> <field name = "state"/> <!-- other fields --> </group> </sheet> </form > </field > </record>

i hope it is use full

0
Avatar
Buang
Master
Penulis

This works with a normal <button> tag. However, in my case, I need to show or hide my custom choices Close/Open in the default server action, similar to the behavior of the Archive/Unarchive button in

D Enterprise

Use the binding_filter_domain field (Best Practice)
From Odoo 15+, ir.actions.server supports a field called binding_filter_domain, which defines when a server action appears in the action dropdown.

Example: Show “Open” action only if state == 'closed'
<record id="mymodel_open_action_server" model="ir.actions.server">
<field name="name">Open</field>
<field name="model_id" ref="model_mymodel"/>
<field name="binding_model_id" ref="model_mymodel"/>
<field name="binding_view_types">form</field>
<field name="binding_filter_domain">[('state', '=', 'closed')]</field>
<field name="state">code</field>
<field name="code">
action = records.action_open()
</field>
</record>
Example: Show “Close” action only if state == 'open'
<record id="mymodel_close_action_server" model="ir.actions.server">
<field name="name">Close</field>
<field name="model_id" ref="model_mymodel"/>
<field name="binding_model_id" ref="model_mymodel"/>
<field name="binding_view_types">form</field>
<field name="binding_filter_domain">[('state', '=', 'open')]</field>
<field name="state">code</field>
<field name="code">
action = records.action_close()
</field>
</record>
please try this
i hoe it is use full

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
¿how to create planned actions? Diselesaikan
action actions server_actions
Avatar
Avatar
2
Mar 23
3274
(!!copair~rápido!!) Cómo puedo hablar con una persona real en Copa?
action
Avatar
0
Nov 25
4
Notification Email Alias – What Emails Are Sent?
action
Avatar
0
Nov 25
5
odoo 19, Enterprise version odoo on - premise.
action
Avatar
Avatar
2
Nov 25
153
in POS orderline is it possible to add background color to the discounted product line
17.0
Avatar
Avatar
1
Nov 25
96
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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