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

Private functions and public functions in odoo python

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
pythonodoo
3 Replies
4787 Tampilan
Avatar
user

I need to know what is the difference between private functions and public functions in odoo python with example, and the usage.

0
Avatar
Buang
Avatar
Ray Carnes (ray)
Jawaban Terbai

Methods and Functions can be categorized as Public or Private based on their intended usage and access control. 


PUBLIC METHODS / FUNCTIONS

  • intended to be called from external sources, such as Other Odoo models, Controllers (web APIs), Scheduled Actions, Other business logic
  • do not start with an underscore (_)
  • are accessible from the Odoo framework and RPC (Remote Procedure Call) APIs
  • are meant for external use and are part of the model’s intended functionality
  • can be overridden and extended in custom modules

PRIVATE METHODS / FUNCTIONS

  • intended only for internal use within the model and should not be accessed externally
  • start with an underscore (_), like _compute_total() OR are marked with the decorator @api.private
  • are not accessible via XML-RPC or JSON-RPC
  • are mainly used as helpers to encapsulate internal logic
  • can be overridden in custom modules

See also https://www.odoo.com/documentation/master/developer/reference/backend/security.html#unsafe-public-methods


Unsafe Public Methods - Any public method can be executed via a RPC call with the chosen parameters. The methods starting with a _ are not callable from an action button or external API.

On public methods, the record on which a method is executed and the parameters can not be trusted, ACL being only verified during CRUD operations.

# this method is public and its arguments can not be trusted
def action_done(self):
    if self.state == "draft" and self.user_has_groups('base.manager'):
        self._set_state("done")

# this method is private and can only be called from other python methods
def _set_state(self, new_state):
    self.sudo().write({"state": new_state})

Making a method private is obviously not enough and care must be taken to use it properly.


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

Hi,

1)Public Functions  in Odoo

Public functions in Odoo classes (which typically represent Odoo models) are denoted by the absence of a leading underscore (_) in their names.These functions can be called directly from Odoo's user interface (UI) elements like buttons, menus, or workflows, as well as from other Python code within your custom Odoo modules.

Example:

class SaleOrder(models.Model):

    _name = 'sale.order'


    def confirm_sale(self):

        # Public function to confirm a sale order

        # This function can be called from buttons or workflows

        # ... (implementation logic)

2)Private Functions in Odoo


Private functions in Odoo are identified by a leading underscore (_) in their names.

While technically accessible from anywhere in your code, private functions are generally intended for internal use within the class. They're not directly callable from the Odoo UI or other modules.

Example:


class SaleOrder(models.Model):

    _name = 'sale.order'


    def _check_stock_availability(self):

        # Private function to check stock availability before confirming a sale

        # This function is used internally by the confirm_sale method

        # ... (implementation logic)


    def confirm_sale(self):

        if self._check_stock_availability():

            # Logic to confirm sale if stock is available

            # ...

        else:

            # Handle insufficient stock scenario

            # ...


Hope it helps

0
Avatar
Buang
Avatar
Utsav Malviya
Jawaban Terbai

class TestClass:

    def PublicFunc(self):

        print("This is a public function")

        self.__Privatefunc() # this is good practice


    def _Privatefunc(self):

        print("This is a private function")


o = MyClass()

o.Publicfunc()  

o._PrivateFunc()  #This is bad practice

0
Avatar
Buang
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
Save filtered tree view to load as it is at another time Diselesaikan
python odoo
Avatar
Avatar
Avatar
2
Agu 25
3368
odoo ghost module
python odoo
Avatar
0
Mei 24
46
Call python method from inherit_id attribute
python odoo
Avatar
Avatar
1
Apr 24
4165
how Restrict users to see only his own invoice ?
python odoo
Avatar
Avatar
Avatar
Avatar
Avatar
4
Sep 23
6102
Dynamic selection field
python odoo
Avatar
Avatar
Avatar
2
Sep 23
7879
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