Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Need help to pass the cloud test.

Subscriure's

Get notified when there's activity on this post

This question has been flagged
developmentconfigurationcontributiondebug
2 Respostes
1442 Vistes
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
Descartar
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
Descartar
Anup Ghosh
Autor

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
[LATAM~BOGOTA~telefono@COL]¿Cómo llamar a Latam Bogotá desde celular?
development configuration contribution debug attrs
Avatar
0
de nov. 25
21
[Latam@Bogota~Telefono]¿Cómo llamar a Latam en Bogotá?
development configuration debug
Avatar
0
de nov. 25
5
[Aide] Modules custom non détectés ou non exécutés sur Odoo 18 (Windows)
development configuration debug
Avatar
Avatar
1
d’oct. 25
712
My Custom Module don't show in apps list after update.
development configuration debug
Avatar
Avatar
Avatar
2
d’ag. 25
1358
Creating a field in res.user is throwing internal server error
development configuration debug
Avatar
Avatar
Avatar
2
de juny 25
1535
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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