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

Need help to pass the cloud test.

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
developmentconfigurationcontributiondebug
2 Replies
1485 Tampilan
Avatar
Anup Ghosh

I have developed a custom module by inherited the product template. There I have added some custom required field. It works perfectly in local.
But when I pushed the code it fails on test case and build also failed. 
Because of the required field doesn't set while testing.

0
Avatar
Buang
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Jawaban Terbai

Hi,


This is a common issue when you add a required field to a core model like 'product.template'  everything works locally because you're manually filling in the required field, but in automated tests (like Odoo.sh builds or CI pipelines), test records and demo data that create products don't set your new field, causing the tests to fail.

Solution

* Provide a Default Value (Recommended)

Add a default value or compute method so that the field doesn't break existing logic:

from odoo import fields, models

class ProductTemplate(models.Model):
_inherit = 'product.template'

my_required_field = fields.Char(
string="My Required Field",
required=True,
default='Default Value'
)


Hope it helps

0
Avatar
Buang
Anup Ghosh
Penulis

If I set a default value for the field, there's a possibility that someone could inadvertently create a product without altering that default value, which would allow them to submit the product entity. How can this issue be addressed?

Avatar
Piyush H
Jawaban Terbai

Hello Anup,

Okay, I understand. You've added required fields to the product.template model in a custom module, and your Odoo Cloud tests are failing because these fields aren't being populated during the automated testing process. Here's a breakdown of how to address this, focusing on making your module cloud-test-friendly:

Understanding the Problem

Odoo Cloud tests run automatically when you push code to platforms like Odoo.sh. These tests are designed to ensure your module doesn't break existing functionality. Because your new fields are required, the tests are likely failing when Odoo tries to create or modify product templates without those fields being filled in.

Solutions

Here's a multi-pronged approach to solve this:

  1. Provide Default Values in Tests:
    • Data Files (XML): The best practice is to create XML data files within your module's data/ directory (e.g., data/test_data.xml). These files will be loaded during testing and can be used to create or update product templates, ensuring your required fields are populated.
    <!-- data/test_data.xml -->
    <odoo>
        <data noupdate="1">
            <record id="product_template_test_1" model="product.template">
                <field name="name">Test Product</field>
                <!-- Fill in your required fields here -->
                <field name="your_required_field_1">Some Value</field>
                <field name="your_required_field_2">Another Value</field>
                <field name="type">product</field>
            </record>
        </data>
    </odoo>
    
    • noupdate="1": This is important! It ensures that the data is loaded only during module installation/testing and won't be overwritten during upgrades.
    • Manifest File: Make sure your __manifest__.py file includes the data file:
    # __manifest__.py
    {
        'name': 'Your Module Name',
        'version': '1.0',
        'depends': ['product'],
        'data': [
            'data/test_data.xml',
        ],
    }
    
  2. Test Case Modifications (If Necessary):
    • If your module includes Python-based test cases (in the tests/ directory), you might need to modify those tests to create or update product templates, again ensuring your required fields are set.
    # tests/test_your_module.py
    from odoo.tests import common
    
    class TestYourModule(common.TransactionCase):
    
        def test_product_creation(self):
            product = self.env['product.template'].create({
                'name': 'Test Product',
                'your_required_field_1': 'Value for Test',
                'your_required_field_2': 'Another Test Value',
                'type': 'product',
            })
            self.assertEqual(product.name, 'Test Product')
            # Add more assertions to validate your logic
    
  3. Conditional Requirements (Less Ideal, but Sometimes Necessary):
    • As a last resort (and generally not recommended if you can avoid it), you could make the fields conditionally required. For example, only required if a specific setting is enabled. This adds complexity and might not be the best design.
    from odoo import models, fields, api
    
    class ProductTemplate(models.Model):
        _inherit = 'product.template'
    
        your_required_field_1 = fields.Char(string="Required Field 1")
        your_required_field_2 = fields.Char(string="Required Field 2")
    
        @api.constrains('your_required_field_1', 'your_required_field_2')
        def _check_required_fields(self):
            # Example: Only require the fields if a specific company setting is enabled
            if self.env.company.some_setting:
                for record in self:
                    if not record.your_required_field_1 or not record.your_required_field_2:
                        raise ValidationError("Required fields must be filled in when the setting is enabled.")
    
    • Important: If you use conditional requirements, make sure your tests cover both scenarios (setting enabled and disabled).

Example Scenario

Let's say you added a required field called manufacturer (a Char field) to product.template.

  1. data/test_data.xml:
    <odoo>
        <data noupdate="1">
            <record id="product_template_test_1" model="product.template">
                <field name="name">Test Product</field>
                <field name="manufacturer">Acme Corp</field>
                <field name="type">product</field>
            </record>
        </data>
    </odoo>
    
  2. __manifest__.py:
    {
        'name': 'Product Manufacturer',
        'version': '1.0',
        'depends': ['product'],
        'data': [
            'data/test_data.xml',
        ],
    }
    

Key Considerations

  • Data Consistency: Ensure the data you provide in your test files is valid and consistent with your module's logic.
  • Test Coverage: Write comprehensive tests to cover all possible scenarios and edge cases related to your new fields.
  • Odoo.sh Logs: Carefully examine the Odoo.sh build logs to understand the exact error messages and traceback. This will help you pinpoint the cause of the test failures.
  • Dependencies: Double-check that your module correctly declares its dependency on the product module.
  • Upgradeability: Think about how your module will behave during upgrades. The noupdate="1" attribute in your data files is crucial for this.

By providing default values for your required fields in your test data, you should be able to resolve the test failures and get your module building successfully on the Odoo Cloud platform. Remember to test thoroughly!

🚀 Did This Solve Your Problem?

If this answer helped you save time, money, or frustration, consider:

✅ Upvoting (👍) to help others find it faster

✅ Marking as "Best Answer" if it resolved your issue

Your feedback keeps the Odoo community strong! 💪

(Need further customization? Drop a comment—I’m happy to refine the solution!)

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
[Aide] Modules custom non détectés ou non exécutés sur Odoo 18 (Windows)
development configuration debug
Avatar
Avatar
1
Okt 25
794
My Custom Module don't show in apps list after update.
development configuration debug
Avatar
Avatar
Avatar
2
Agu 25
1462
Creating a field in res.user is throwing internal server error
development configuration debug
Avatar
Avatar
Avatar
2
Jun 25
1559
Cron job completes Instantly on production without throwing errors – works correctly on dev Diselesaikan
development configuration function debug
Avatar
Avatar
2
Sep 25
1215
Hide invoice header and footer in odoo v17 Enterprise
development configuration accounting debug
Avatar
Avatar
1
Jun 25
1603
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