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

how to format mapped() result

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
many2manymappingodoo11
2 Replies
12259 Tampilan
Avatar
andy

How to format mapped() result?

mapped() output like ['name1','name2','name3'] and related float field [100, 200, 300]

would like to add that value to fields.Text so that it goes fields.Text: name1, name2, name3

and also add currency like $100, $200, $300

can this be done? any example?

thank you

0
Avatar
Buang
Avatar
andy
Penulis Jawaban Terbai

okey i'm partly solve:
This is my custom modules
that have this fields

report = fields.Many2many(comodel_name="my.report", string="Report")
tprod = fields.Text(string="Product", compute="_tprod")
tprice = fields.Text(string="Prices", compute="_tprice")
tcost = fields.Text(string="Cost", compute="_tcost")


@api.multi
@api.depends('report')
def _tprod(self):
        for rec in self:
            rec.tprod = str(rec.report.mapped('name')).strip("[]").strip("''")

this result is: name1', 'name2
expected : name1, name2 - with out ( ' )

@api.multi
@api.depends('report')
    def _tprice(self):
        for rec in self:
            rec.tprice = str(rec.report.mapped(lambda record: '$ ' + str(record.price))).strip("[]")

this result is : '$100', '$200'
expected: $100, $200
if i put .strip("[]").strip("''") then the result would like $100', '$200 which is not good to look at 

tcost the same as tprice

so for all of you who does not know, mapped() is a list so you cannot add .replace or .strip without turning it to str first that's why must convert str(rec.report.mapped('name')) and also record.price is Float for my part and have to change that as well to str(record.price)

if anyone have more solution to finalize my code please, thank you

Solved with:

@api.multi
@api.depends('report')
def _tprod(self):
        for rec in self:
            rec.tprod = str(rec.report.mapped('name')).strip("[]").replace("'", "")

or if it's not working, you can do this:

    rec.tprod = str(rec.report.mapped('name')).strip("[]")
    rec.tprod = rec.tprod.replace("'", "")

anyway other tips is if you use store=True then you have to delete the value first or if there is already a value in your field, then either delete the value or delete it from database (just be cautions if you are deleting from database, always have backups), or maybe just use "@api.onchange" for testing.

My problem was using store=True i did not see the .replace() because it's already saved values in database (was testing using @api.depends thought that it will change just by refreshing), choose hard way delete field from postgresql and upgrade my module - but you can also create new field and delete old ones

0
Avatar
Buang
Avatar
Travis Waelbroeck
Jawaban Terbai

When you use `mapped`, it is going to result in a list. Afterwards, you can use standard Python to manage how you want to format that list. This isn't the prettiest example, but you can do something like this:


>>> ", ".join(["${}".format(price) for price in ['100', '200']])
'$100, $200'


1
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
Add column to a many2many rel table Diselesaikan
many2many odoo11
Avatar
Avatar
1
Nov 19
5914
Problem with M2M Fields Diselesaikan
many2many problem odoo11
Avatar
Avatar
Avatar
2
Nov 18
6860
Many2Many and One2Many Field in Odoo Studio Diselesaikan
one2many many2many studio odoo11
Avatar
Avatar
Avatar
2
Des 19
7331
Getting TypeError: Cannot read property 'documentElement' of null with fields_view_get() ODOO 11
many2many domain_filter fields_view_get odoo11
Avatar
Avatar
2
Sep 18
10256
access files from many2many-field which is passed from context
many2many context files odoo11
Avatar
0
Sep 18
4387
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