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

Related two Many2one fields in the same line

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
many2onecomputerelationstock.move.line
1 Balas
3222 Tampilan
Avatar
Mohamad Ali Chamas

I created 2 fields inside the stock.move.line inside transfers : The first one is many2one field and I need to populate it automatically if the second customized boolean field is checked. The field I need to populate with is the product_id which is already found in the lines. Any Ideas? Here is my code: 


@api.onchange('product_id')
def relate_alternatives(self):
for rec in self:
if rec.alternative_delivery_item==True:
rec.product_alternative=rec.product_id


I don't need an onchange function, I need when checking the box, I need the new many2one field to be filled automatically, at the same time I need when changing the product_id again not affect the other many2one field I created. Thanks

0
Avatar
Buang
Avatar
Mateus Vitor
Jawaban Terbai

You need a computed field mechanism. A computed field is a way of calculating the information dynamically. For example:


product_alternative = fields.Many2one('product.product', string='Product', compute="_computed_product_id")


The "compute" attribute execute a method from your class where calculate what you need in instance. Try this method:


@api.depends('alternative_delivery_item')
def _computed_product_id(self):
for rec in self:
if rec.alternative_delivery_item == True:
rec.product_alternative = rec.product_id


The "computed" field is calculated in execution time so it's important understand if you wish stored this data, so you'll need add a attribute called stored=True. In this case, you can be get this data from your database.

You can found more references in Cybrosys blog post about computed fields.

0
Avatar
Buang
Mohamad Ali Chamas
Penulis

Thank you, I tried this code but I got this error when I enter a transfer: Something went wrong !
×
stock.move.line(142974,).product_alternative

Mateus Vitor

You can send a log return here to we analyse easily. Or send the user error return completely

Mohamad Ali Chamas
Penulis

That's the error: 'stock.move.line(142974,).product_alternative', None and the one I sent before

Mateus Vitor

Try remove the depends decorator

Mateus Vitor

I done a little correction in api.depends decorator. I expect this is the solution. Try this:

@api.depends('alternative_delivery_item')

Mohamad Ali Chamas
Penulis

@api.onchange('product_id')
def _computed_product_id(self):
# self.ensure_one()
for rec in self:
if rec.alternative_delivery_item == True:
rec.product_alternative = rec.product_id

That is the new update and its working fine. But I need the onchange function to execute only once. Is there any condition that can help me limit this?

Mateus Vitor

You will can create a field where be created a execution condition to method. For example:

product_alternative_processed = fields.Boolean(string='Processed Product Alternative', deafult=False)

Every time you run this method check if the field has been calculated. Otherwise, you will edit the field.

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
Relating 2 many2one fields
many2one stock.move.line
Avatar
Avatar
1
Mar 23
2758
why I can't delete records of another module by the compute function in a field?
many2one compute
Avatar
0
Agu 19
4325
Get integer values from Many2one field, and then compute it all Diselesaikan
many2one compute
Avatar
1
Des 15
7036
Relate sale.order.lines to stock.picking Diselesaikan
sale.order.line relation stock.move.line
Avatar
Avatar
1
Des 24
5321
compute many2one from custom model's Diselesaikan
many2one compute 13.0
Avatar
1
Okt 20
8664
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