Odoo Help


4 Answers

Axel Mendoza Cuba

--Axel Mendoza--
| 8 8 10
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza Cuba
7/1/16, 1:13 AM

There are mostly 2 ways of setting a default value for the fields in Odoo(there are more, but this are the most used ones).

1- Setting the default value in the Python model that contains the field

#old api
    _defaults = {
        'ship': 'ship_value1',

#new api

    ship = fields.Selection([('ship_value1', 'Value1'),('ship_value2', 'Value2')], default='ship_value1')

2- Setting the value in xml view field or action of the form that contains the field, using context ('default_ship') like:

#the content of the field lines is not necessary, i put it for the sake of the example

<field name='lines' context="{'default_ship': 'ship_value1'}">
    <form string="Line">
        <field name="ship"/>
        <field name="ship"/>

Herve GUERIN France
10/18/17, 12:25 PM

I tried this syntax to modify an existing view but it doesn't work :

<field name='group_by_name' position="attributes">

<attribute name="string" eval="'dummy_title'"/>

<attribute name="context" eval="{default_group_by_name': 1}"/>


The syntax is globally good because the "dummy_title" appears,

but the {context...} don't

I tried several other things in the eval clause ('group_by_name': 'True', 'group_by_name': True, etc...) and nothing works.

Can you help me ?

Herve GUERIN France
10/18/17, 12:29 PM

a complementary info : the field group_by_name is of type boolean

Axel Mendoza Cuba
10/18/17, 3:34 PM

The thing is that you need to put that context where it's belong to, like in an action, many2one, one2many or many2many field where the call to default_get to get the default values for the form create of the model record could take the context into account. Summary: don't put it on the field that needs the default, set it to the superior level so it could be taken into account as a default for the form values


kirubanidhi India


| 6 2 8
pondicherry, India

kirubanidhi India
7/4/16, 2:48 AM

In odoo 9 we use 

ship = fields.Selection([('ship_value1', 'Value1'),('ship_value2', 'Value2')], default=lambda self: self._context.get('ship', 'ship_value1'))


In module file

<<field name>>= fields.<<datatype>>(default=<<value>>)

in views.xml

<field name="start_date"/>

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now