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

[v13] Update one2many field after a change in its parent

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
one2manyonchangeparentOdoo13.0v13
2 Replies
9029 Tampilan
Avatar
Víctor

I'm trying to apply a global discount to invoices (v13). I don't want to modify the way Odoo calculates the invoice amount, so all I'm doing is change the discount field for every account.move.line of the invoice.

I create the global_discount field in account.move:​

class AccountMove(models.Model):
_inherit = 'account.move'

global_discount = fields.Float(string='Global Discount (%)', digits='Discount', default=0.0)
​

Now, I want to change the discount field when global_discount is modified, but @api.onchange is not being called when doing so. It doesn't work adding either the parent reference or a related field to the decorator:

class AccountMoveLine(models.Model):
_inherit = 'account.move.line'

global_discount = fields.Float(related='move_id.global_discount')

# This method is not being called when changing global_discount
@api.onchange('move_id.global_discount', 'global_discount')
def _compute_discount(self):
for line in self:
# Simplified for easy reading, I'm not actually doing this
line.discount = line.global_discount

Even if I make discount a computed field and use @api.depends, its onchange methods won't be called.
If I modify the lines from an onchange method in the parent, the discount onchange methods won't be called and  price_subtotal will not change:

class AccountMove(models.Model):
_inherit = 'account.move'

@api.onchange('global_discount')
def _compute_discount(self):
for invoice in self:
for line in invoice.invoice_line_ids:
line._compute_discount()

I have also tried calling the onchange methods manually, but I'm definitely doing something wrong because nothing new happens:

@api.onchange('global_discount')
def _compute_discount(self):
for invoice in self:
for line in invoice.invoice_line_ids:
line._compute_discount()
spec = line._onchange_spec()
values = dict(line._cache)

# onchange returns and empty dict {}
updates = line.onchange(values, 'discount', spec)

value = updates.get('value', {})

for name, val in value.items():
if isinstance(val, tuple):
value[name] = val[0]

values.update(value)
line.update(values)

I'm missing something on how Odoo calls onchange methods from python, but I can't figure it out.

0
Avatar
Buang
Avatar
Víctor
Penulis Jawaban Terbai

I had to call _move_autocomplete_invoice_lines_values() in the parent move after updating the discount for the changes to be propagated.

0
Avatar
Buang
Avatar
Ibrahim ALdaw
Jawaban Terbai

 in account.move  use this Methods Instead:

    @api.onchange('global_discount')
def _compute_discount(self):
for line in self.invoice_line_ids:
line.update({'discount':self.global_discount})
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
On change is not triggered Diselesaikan
one2many onchange Odoo13.0
Avatar
Avatar
1
Jan 21
6259
Many2one dependant booleans Diselesaikan
onchange Odoo13.0 v13
Avatar
Avatar
1
Des 19
3574
fill a field up based on domain condition Diselesaikan
onchange Odoo13.0
Avatar
Avatar
Avatar
5
Des 22
6380
One2many-field based on value in many2one-field Diselesaikan
one2many Odoo13.0
Avatar
Avatar
1
Jan 21
4190
How to update two levels o2m fileds relation
one2many onchange
Avatar
0
Sep 20
3762
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