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

The value of the onchange function shows up in the form but does not save in the database.

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
on_changeodoo8.0
4 Replies
14246 Tampilan
Avatar
Anand Prasanth

I have an age calculation function (onchange) and it calculates and shows up in the form when I enter the data. But the data is not saved in the data base. Please help with the code.


    @api.onchange('dob')

     def onchange_age_calculate(self):

      if not self.dob:

       self.age = 0

     else:

      today_date = datetime.datetime.now().year

      date_split = self.dob.split('-',1)

      birth_year = date_split[0]

      self.age = today_date -int(birth_year)


    _columns = {

                'name': fields.char(string="Name"), 

                'dob' : fields.date('Date of Birth'),

                'age' : fields.float( string='Age')


I have imported date time and the required library files hope so

1
Avatar
Buang
Sehrish

Reference: https://learnopenerp.blogspot.com/2021/10/onchange-method-readonly-field-not-store-database-odoo.html

Avatar
Axel Mendoza
Jawaban Terbai

That could be happening if you declare readonly the field age in the view. The readonly fields are not saved into the database even when they change their value through an onchange. To solve just remove the readonly attr or recalculate it in the create/write method of your model or define it as an computed field. There are solutions to send the readonly fields to the create/write methods but it's not out of the box

3
Avatar
Buang
Avatar
ayman mohammed adam
Jawaban Terbai

hello try this


   @api.onchange('dob')

   @api.depends('dob')

     def onchange_age_calculate(self):

      if not self.dob:

       self.age = 0

     else:

      today_date = datetime.datetime.now().year

      date_split = self.dob.split('-',1)

      birth_year = date_split[0]

      self.age = today_date -int(birth_year)

 

      name=  fields.Char(string="Name"), 

      dob' = fields.Date('Date of Birth'),

      age= fields.Float( string='Age')



then replace your class like this

class your_class_name(models.Model):


Thanks and I hoped i help you.

0
Avatar
Buang
Avatar
Pawan
Jawaban Terbai

Anand,

As axel said you cant store readonly values in DB, i got some workout around it to do that..

To store readonly values also in future, u can have a little modification at your js part:

at wed/static/src/js/views/view_form.js        under FormView class, at method '_process_save()'

approx at line# 873, under "else if (f.name !== 'id' && (!self.datarecord.id || f._dirty_flag))"

replace the code with below one....

else if (f.name !== 'id' && (!self.datarecord.id || f._dirty_flag)){

//commenting below lines to allow sotring readonly values also

// if (!f.get("readonly")) {

               // values[f.name] = f.get_value(true);

    // } else {

            // readonly_values[f.name] = f.get_value(true);

    // }

    values[f.name] = f.get_value();

     if (f.get("readonly"))

            readonly_values[f.name]= f.get_value();

}

Hope this will help you

0
Avatar
Buang
Avatar
Kirubanidhi Rajarathinam
Jawaban Terbai

# Specify below header file in your code:

from datetime import datetime

from dateutil import relativedelta as rdelta

from datetime import date

#create a two field in your py file

staff_dob = fields.Date(string="Date of Birth")

staff_age = fields.Integer(string="Age")

# We can use onchange method in my staff_dob field .

@api.onchange('staff_dob')

def age_cal_fun(self):

if self.staff_dob:

today = date.today()

bdate = datetime.strptime(self.staff_dob, '%Y-%m-%d')

rd = rdelta.relativedelta(today, bdate)

self.staff_age = rd.years

#Above this code is help for you

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: help! Diselesaikan
on_change uppercase odoo8.0
Avatar
Avatar
Avatar
2
Agu 15
4548
how to implement joint piece in odoo 8 in one view
odoo8.0
Avatar
0
Apr 24
2640
what is the reason behind extra move? in stock
odoo8.0
Avatar
Avatar
Avatar
Avatar
4
Nov 23
6814
How to solve fields.function issue in odoo 8
odoo8.0
Avatar
0
Okt 23
2646
how to restrict create and delete access in one2many field tree view
odoo8.0
Avatar
0
Des 22
3362
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