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

Combined name for a record - Odoo 8

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
record_name
6 Replies
5308 Tampilan
Avatar
Alejandro Perez Cosio

Hello, 
I'm triying to set a default record name as a combination of 2 fields: 
I have a table with 3 columns (just for the example): 

  • name
  • start_date
  • end_date


And I would want to have the name calculated with the following:

def _get_name(...):
    element = self.browse(cr, uid, ids, context=context)
    return '%s -> %s' % (element.start_date, element.end_date)

_columns = {
    'name': fields.function(_get_name, type='char'...)
    ...
}

How can I get that?

Thank you in advance

0
Avatar
Buang
Alejandro Perez Cosio
Penulis

The problem here is I wasn't iterating on the element (which should be elements). A res list should also be declared as empty and append the custom name to this list with the record id.

Avatar
Alejandro Perez Cosio
Penulis Jawaban Terbai

This is how I finally got my combined name:

def _get_name(self, cr, uid, ids, name, arg, context=None):
        reads = self.read(cr, uid, ids, ['start_date','end_date'], context=context)
        res = []
        for record in reads:
            name = '%s -> %s' % (record['start_date'], record['end_date'])
            res.append((record['id'], name))
        return res

And for the field:

'name': fields.function(_get_name, type='char', store=True)

0
Avatar
Buang
Avatar
Jeff Beidler
Jawaban Terbai

Hi Alejandro,

Here is the function I used recently to retrieve a combination of two fields as the name:

   @api.multi
    def name_get(self):
        
        retvals = []
        
        for record in self:
            if self.env.context.get('prod_form', False):
                catstring =  "[" + record.name + "] " + record.description
                retvals.append((record.id,catstring))
            else:
                retvals.append((record.id,record.name))
       
        return retvals

In this case, it returns the combination of 'name' and 'description' only when the 'prod_form' context is true.  It should steer you in the right direction, though, as it uses the new v8 API form.  Notice that the function only needs 'self' as a parameter.  All the other variables (cr, uid, ids, context, etc.) are wrapped up in the environment, which is part of 'self'. 

In this post, Marvin helped me understand what (I hope) I explained above.  My original question also contains a link to the API documentation, if you haven't found that already.

I think you also want to declare your field like this:

name = fields.Char(compute='yourFunction_name')

1
Avatar
Buang
Alejandro Perez Cosio
Penulis

Thank you Jeff, your answer helps me to understand a little more how odoo works, I'm always building modules with a dictionary for _columns but I will try this on my next module.

Jeff Beidler

That still works. You'll find that Odoo still has a mix of old and new API stuff. That tripped me up for a while, until Marvin pointed out (see linked post) that I needed the @api.multi decorator on my name_get function.

Avatar
Dr Obx
Jawaban Terbai

I was looking for something like this recently and suddenly found it but would anyone tell me, I need it for product so if possible to make some changes to make it work with product please?

I need combine 3/4 fields together so as a result the product name should contain brand, model, size,  ...

Can anyone show me exactly how should it look like for product module ?

0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

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

Daftar
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