Odoo Help

Welcome!

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.

0

How to make field one2many required based on parent field ?

By
Ajeng Shilvie
on 2/3/15, 7:42 AM 623 views

i have custom class like this ,

.py

#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

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
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.

Ivan
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?

Ivan
on 2/4/15, 2:59 AM

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)

Stats

Asked: 2/3/15, 7:42 AM
Seen: 623 times
Last updated: 3/16/15, 8:10 AM