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
    • Discuss
    • 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

Upgrade custom module, convert Many2one field into Many2many field

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
fieldsfieldfields.many2onecustom_moduleodoo10.0
4 Replies
11956 Tampilan
Avatar
Ilusoria

I have a Many2one field already works in a lot of records in a production instance, now is needed that this field accepts more than 1 relation link to the other model, is possible just change the field type from Many2one to Many2many without losing any data?

If yes, what's the correct way to do it? if not, how to do it?

2
Avatar
Buang
Yenthe Van Ginneken (Mainframe Monkey)

Why would you want to change from a many2one to a many2many though?You're most likely better off to create a one2many that links to a many2one - it'll behave the same as a many2many but it has benefits. On a many2many you cannot filter by default and if you export the data you won't get everything out automatically. With a one2many you can. Just a tip. :-)

Ilusoria
Penulis

@Yenthe Your approach it's helpful, I've not even though, so, can I take your answer as If I can change the field from Many2one to One2many or Many2many and the data persist?

Ilusoria
Penulis

I can't use the One2many field because 1 a.object can have N b.object and 1 b.object can be in N a.object, so I should use the Many2many field, but I need to know if the information persists after changing the field type from one2Many to (Many2many or One2many).

Avatar
Ilusoria
Penulis Jawaban Terbai

I did it this way:

first I created a new field type Many2many:

objectA_ids = fields.Many2many('res.partner')

then a function that gets the value of the old Many2one field:

@api.model
    def _fill_objects(self):
        products = self.env['module.name'].search(
            ['&', ('objectA_id', '!=', False), ('objectA_ids', '=', False)])
        for r in products:
            if not r.objectA_ids and r.objectA_id:
                r.objectA_ids = [(4, r.objectA_id.id)]
            else:
                r.objectA_ids = False


and in the last step, i did make an XML call to the function when the module it's installing:


<odoo>
   <data noupdate="1">
    <function model="module.name" name="_fill_objects"/>
  </data>
</odoo>


after installing the module the new field has the values of the old field, there's no way for change the field type without lost data, so we have to create a new field, copy data from the old field, and make the old field invisible on view.


<odoo>
  <data>
    <record id="view_module_name_adjustment" model="ir.ui.view">
      <field name="name">module.name.view.form</field>
      <field name="model">module.name</field>
      <field name="inherit_id" ref="module_view_external_id"/>
      <field name="arch" type="xml">
        <field name="objectA_id" position="after">
          <field name="objectA_ids" widget="many2many_tags"/>
        </field>
        <field name="objectA_id" position="attributes">
          <attribute name="invisible">True</attribute>
        </field>
      </field>
    </record>
   </data>
</odoo>
4
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
Concatenate two fields in a third one Diselesaikan
fields field
Avatar
Avatar
Avatar
2
Agu 24
3353
Link a field with a node in invoice
fields field node
Avatar
0
Jan 24
1800
Calculated field not working
fields field calculated
Avatar
Avatar
Avatar
Avatar
3
Sep 23
3166
Explain fields.property() Diselesaikan
fields field orm
Avatar
Avatar
Avatar
2
Mar 18
33915
Adding custom field to sales order product lines? Diselesaikan
fields field sale.order.line
Avatar
Avatar
Avatar
Avatar
Avatar
10
Jan 24
18301
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