Odoo Help


This community 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.


How can i set a default value When creating a new field.?,

on 6/30/16, 11:46 PM 457 views

Add the Ship field as a drop down list field of the Ship object to the order lines next to quantity. and Create a button under ship field 'Update to Order Lines', update the same Ship information to the order lines. When creating a new order line, in the Ship field in order line by default show the Ship information of the SO..!!?

expr="//field[@name='order_line']" position="attributes">

     <attribute name="context">{'default_shipimo':ship}    </attribute>


i need the Python code too..

on 7/1/16, 2:00 AM

Axel Mendoza

--Axel Mendoza--
| 6 7 8
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 an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 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"/>

On 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'))

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 6/30/16, 11:46 PM
Seen: 457 times
Last updated: 8/16/16, 9:35 AM