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

Testing of computed field in Odoo 18 extension dev

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
developmentdebug
1 Balas
520 Tampilan
Avatar
Alex McColm

Hello,


I have been writing an extension which tracks when users have "marked as read" a given document in Odoo Knowledge. I am working on adding unit testing. I would like to ask what I might be doing wrong and what best practices are for testing in this context.

Here is an example of a unit test that fails, where as the actual behaviour seems to work in manual testing.

    def test_ack_outdated(self):

        """

        When a user acknowledges an article, 2s pass, then the article changes,

        the ack is marked outdated.

        """

        self.article_1.must_acknowledge = True

        self.article_1.with_user(self.user_1).verify_acknowledgement()

        self.article_1.sudo().write({"body": "<h1>Updated Article</h1>"})

        self.env.flush_all() # Flush changes to DB session after writing!

        sleep(2.0)


        ack_record = self.env['knowledge.article.ack'].search([

            ('user_id', '=', self.user_1.id),

            ('article_id', '=', self.article_1.id)

        ])

        self.assertEqual(ack_record.user_id.id, self.user_1.id)

        self.assertEqual(ack_record.article_id.id, self.article_1.id)

        self.assertIsNotNone(ack_record.ack_datetime)

        self.assertTrue(ack_record.is_outdated)


The final assertion fails - the acknowledgment by the user of the article has not been marked as outdated. The field is computed as follows - it is very simple.

    ack_datetime = fields.Datetime(

        string='Acknowledged Date & Time',

        default=fields.Datetime.now

    )


    is_outdated = fields.Boolean(

        compute='_compute_is_outdated',

        store=True,

    )


    @api.depends('ack_datetime', 'article_id.write_date')

    def _compute_is_outdated(self):

        for rec in self:

            rec.is_outdated = all([

                rec.ack_datetime,

                rec.article_id.write_date,

                rec.ack_datetime <= rec.article_id.write_date

            ])


Also, should i be using the Form class from the testing modules provided by Odoo? 

0
Avatar
Buang
Avatar
Alex McColm
Penulis Jawaban Terbai

OK, I might have found an answer to this, and wow it's weird.

So when we write to a model the write_date appears to be set to the time of the start of the database transaction. I present as evidence the following. There are a few other places in the file where cr.now() is used.

https://github.com/odoo/odoo/blob/18.0/odoo/models.py#L4732

My unit test is within one transaction. It's not that the write_date isn't updated when I modify the article. It is set to the same date as before, because we're in the same transaction. Rather than the actual time which includes a few seconds that have passed (I did fix the position of the sleep() call from OP)

Because my computed field checks write_date, it seems there are some barriers to testing it

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
How do I correctly create a calculated field to sum two other field values in Odoo Studio (Odoo Online)? Diselesaikan
development debug
Avatar
Avatar
2
Nov 25
585
How can I make buttons in Odoo 18? Diselesaikan
development debug
Avatar
Avatar
Avatar
3
Sep 25
1604
Problem when creating my first module locally
development debug
Avatar
Avatar
Avatar
Avatar
Avatar
4
Agu 25
2154
Show amount of current users online
development debug
Avatar
Avatar
1
Jun 25
1826
How to override default Contacts form view without DB conflict? Diselesaikan
development debug
Avatar
Avatar
1
Mei 25
1893
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