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

how to create a foreign key and update the column once saved

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
many2onerelationshipproduct.product
2 Replies
3865 Tampilan
Avatar
random_mai

I have this scenario: I have a new field in product.product and it's a Many2one field. The many2one field has a product_id column. Here's the sample code:


class MyMany2one():

​_name = "my.manytoone"


​name = fields.Char()

​product_id = fields.Many2one(

​ ​comodel_name = "product.product"

​)



class ProductProduct():

​_inherit = "product.product"


​# in the product view, this will be a selection

​mymany2one = fields.Many2one(

​ ​comodel_name = "my.manytoone"

​)


My issue is it does not populate the product_id in the many2one class after saving

0
Avatar
Buang
Avatar
shubham shiroya
Jawaban Terbai

you can try this way:

class MyMany2one(models.Model):
_name = "my.manytoone"
name = fields.Char()
product_id = fields.Many2one(
comodel_name="product.product",
inverse_name="mymany2one",
)


class ProductProduct(models.Model):
_inherit = "product.product"

# In the product view, this will be a selection
mymany2one = fields.Many2one(
comodel_name="my.manytoone",
inverse_name="product_id",
)

By adding the inverse_name parameter to the product_id field in the my.manytoone class and the mymany2one field in the product.product class, you establish a two-way relationship between the two fields. This ensures that the product_id field in the my.manytoone class gets populated when a value is selected in the mymany2one field of product.product.

After making these modifications, update the module containing this code and restart the Odoo server. Then, when you create or edit a product.product record, select a value in the mymany2one field, and the corresponding product_id field in the my.manytoone class should populate correctly.

0
Avatar
Buang
Avatar
Niyas Raphy (Walnut Software Solutions)
Jawaban Terbai

Hi,

Am not sure about your design, if you need  product_id as Many2one inside your model, you have to write code for updating the product_id field inside your custom model.

Inherit the write method of product.product model, and if the mymany2one field has a value, update the product id into it.

But what if the same record is selected inside multiple products ?

Lets say, you have a record My Record 1 in your table and 2 products in products table P1 and P2, which value you will store inside the My Record 1 if for both P1 and P2, if user choose My Record 1 ?


If its possible to change it one2many field inside your model, you can achieve this without any extra coding. Remove many2one from your model and define a one2many field as follows:


product_ids = fields.One2many('product.product', 'mymany2one', string="Test")

Thanks

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
Display another field in many2one instead of name Diselesaikan
many2one relationship search
Avatar
Avatar
Avatar
3
Feb 25
37194
Show related objects of the same model. Diselesaikan
many2one one2many relationship
Avatar
Avatar
2
Agu 15
5884
Can i eliminate the option to create and edit?
many2one creation relationship
Avatar
Avatar
Avatar
2
Mar 15
5023
Change display field in popup from related Module
many2one relationship popup Studio
Avatar
Avatar
1
Jul 23
3197
how to delete one2many if many2one is deleted Diselesaikan
many2one one2many relationship unlink
Avatar
Avatar
1
Mei 23
3740
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