Odoo Help


How can I set a field as required if another field is selected?

Kit Sunde
on 9/9/14, 2:50 PM 754 views

I have a field email and a field starting_day. I would like starting_day to be required if email has been selected. My model:

class sales_order_line_item_email(osv.Model):
    _name = 'sale.order.line'
    _inherit = 'sale.order.line'
    _columns = {
        'email_chain': fields.many2one(
            'Email Chain',
        'starting_day': fields.date('Starting Day', required=False),


Hi Kit,

You can achieve your goal using the attrs into view where you have put those fields. You have to put your fields like below into inherited view.

<field name="email_chain" />

<field name="starting_day" attrs="{'required':[('email_chain','!=',False)]}" />

thats it.

Deviprasad V
On 9/10/14, 1:18 AM

Use attrs in your view.

attrs="{'required':[('email_chain', '!=', False)]}"

add this code inside your starting day filed

Hello Deviprasad, Why are you copied my answer ?

Emipro Technologies Pvt. Ltd.
on 9/10/14, 1:29 AM

OMG by mistake both of us posted same time. To be honest i didn't saw your answer. Sorry

Deviprasad V
on 9/10/14, 2:22 AM

@Deviprasad: Its ok no problem. :) I give you up vote for your answer. You can also do it. Thanks. @Kit : If you feel that my answer is ok for you then accept my answer and give me up vote. Thanks for that.

Emipro Technologies Pvt. Ltd.
on 9/10/14, 2:26 AM

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

Question tools

1 follower(s)


Asked: 9/9/14, 2:50 PM
Seen: 754 times
Last updated: 3/16/15, 8:10 AM