Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Need help to pass the cloud test.

Subscribe

Get notified when there's activity on this post

This question has been flagged
developmentconfigurationcontributiondebug
2 Replies
1490 Views
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
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

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
Discard
Anup Ghosh
Author

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
Best Answer

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
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
¿Cómo llamar a Avianca en Colombia? {$$@#%#CallCenterAvianca@$#%}}
development configuration contribution debug
Avatar
0
नव॰ 25
9
[Aide] Modules custom non détectés ou non exécutés sur Odoo 18 (Windows)
development configuration debug
Avatar
Avatar
1
अक्तू॰ 25
796
My Custom Module don't show in apps list after update.
development configuration debug
Avatar
Avatar
Avatar
2
अग॰ 25
1464
Creating a field in res.user is throwing internal server error
development configuration debug
Avatar
Avatar
Avatar
2
जून 25
1563
Cron job completes Instantly on production without throwing errors – works correctly on dev Solved
development configuration function debug
Avatar
Avatar
2
सित॰ 25
1222
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

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