Odoo Help


How to make field one2many required based on parent field ?

Ajeng Shilvie
on 2/3/15, 7:42 AM 1,129 views

i have custom class like this ,


#for parent class

class wtc_proses_birojasa(osv.osv):
    _name = "wtc.proses.birojasa"

    _columns = {
        'type' : fields.selection([('reg', 'REG'), ('adv','ADV')], 'Type'),

        'proses_birojasa_line': fields.one2many('wtc.proses.birojasa.line','proses_birojasa_id',string="Table Biro Jasa"), 


# for one2many

class wtc_proses_birojasa_line(osv.osv):
    _name = "wtc.proses.birojasa.line"

    _columns = {

                'no_notice' : fields.char('No Notice'),



i want to make 'no_notice' required when user choose 'REG' in 'type' selection, i already use this xml code but it didn't work

<field name="no_notice" attrs="{'required': [('parent.type','=','reg')]}"/>    


anyone know how to solve it ?

sorry for my bad english , thanks in advance




| 5 3 6
Jakarta, Indonesia
On 2/3/15, 10:28 AM

Make type to be a related field in the wtc.proses.birojasa.line model, include it in the view, and set the attrs based on this related field.

@ivan , so i have 2 make another 'type' fields related to parent line like this ? 'type' : fields.related('proses_birojasa_id','type',type='selection',string='Type') ?

Ajeng Shilvie
on 2/3/15, 10:37 AM

Yes, don't forget to put in the selection= parameter in the definition.

on 2/3/15, 10:54 AM

@Ivan , i use this code 'type' : fields.related('proses_birojasa_id','type',type='selection',selection=[('reg', 'REG'),('adv', 'ADV')],string='Type', store=True) but it didn't work .. is there anything wrong ?

Ajeng Shilvie
on 2/3/15, 10:30 PM

You need to be more elaborate on what you mean by didn't work, e.g. does it still be not required if wtc.proses.birojasa's type is 'reg'? At which point? Now, have you included the field in the view? Have you updated the attrs for no_notice field? Could you post the complete view in which you put the no_notice attrs in so that it can be examined more closely?

on 2/4/15, 2:59 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: 2/3/15, 7:42 AM
Seen: 1129 times
Last updated: 3/16/15, 8:10 AM