This question has been flagged
2 Replies
6109 Views

Hi everyone,i modify the module rh and now i want to add a field many2one in an other module from employee who have a job professor but i have this error:

ValueError: Invalid field u'job_id.name' in leaf "<osv.extendedleaf: (u'job_id.name',="" u'=", u" prof')="" on="" hr_job="" (ctx:="" )&gt;"<="" p="">

code of the file.py

enter code hereclass school_matiere(osv.osv):
''' matiere '''
_description ='Information sur les matieres'
_name = 'school.matiere'

_columns = {
    'name': fields.char('libelle matiere', size=64, required=True, select=1),
    'code': fields.char('Code matiere', size=20, required=True, select=1),
    'coef_mat': fields.integer('coefficient matiere'),
    'teacher_id': fields.many2one('hr.employee', 'Professeur responsable',required=True),
}

school_matiere()

code of file.xml

enter code here<record model="ir.ui.view" id="view_school_matiere_form">
        <field name="name">school.matiere.form</field>
        <field name="model">school.matiere</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Matiere" version="7.0">
            <sheet>
                <group col="6" colspan="4">
                <field name="teacher_id" domain="[('job_id.name','=','prof')]"/>
                    <field name="name" />
                    <field name="code" />
                    <field name="coef_mat" />
                </group>
                 </sheet>
            </form>
        </field>
    </record>
Avatar
Discard
Best Answer

Hi

your Domain expr... is wrong as .. you are searching in hr.jobs, there is no field name "job_id" that's why you are getting this error

try this ...

<field name="teacher_id" domain="[('job_id.name','=','prof')]"/>

the above example only for those records which contents value 'prof' in name field means those records will be displayed where name='prof' you can use according to you....

Avatar
Discard
Author

Hi it worked at the beginning but now i find the value "prof" and not the employee who i want to select...any idea please

in the module hr.job which records contents value 'prof' in the name field , those records will be display ... can you tell what actually you want , what kind of employee you want in search

Author

I want to display employees who have the job 'teacher (in the HR module) in another module that I developed via the field many2one (the code above)

where you want to display , this is an example of , when you select teacher_id in employee

here in school.matiere module you are not display employee you are display hr.job means job position .. where name='prof'

Author

exactly but teacher_id is in another class

ok now , do one think , 'teacher_id': fields.many2one('hr.employee', 'Professeur responsable',required=True), not hr.job ... and then in domain add your previous think means ... ....... &lt;field name="teacher_id" domain="[('job_id.name','=','prof')]"/&gt; ... then it will run perfectly as you want

i updated your code in your Q you can copy this code now it will run perfectaly

Author

i have this error: ValueError: Invalid field u'job_id.name' in leaf "<osv.ExtendedLeaf: (u'job_id.name', u'=', u'prof') on hr_job (ctx: )>"

Author

yes thank you it work's now...I had to create a new database and restart service

Author Best Answer

it work's now i just modify hr.employee by hr.job in the field

'teacher_id': fields.many2one('**hr.job**', 'Professeur responsable',required=True),
Avatar
Discard