Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3244 มุมมอง

Hello everyone, can someone please throw some light on the following issue:

I have got a requirement where I need to have a many2one field in a one2many (editable tree). I successfully managed to add the many2one field in the one2many editable tree. However the issue that I have at the moment is the value of the selected item in the drop down (i.e. many2one field) is displaying as hr.x.y, 1 and not the actual value.

KInd Regards

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Issue Solved

That was silly me.

class x_y_z(osv.osv):
    _name = 'x.y.z'
    _description = 'xyz description'
    _columns = {
        'name': fields.char('abcd field name', required=True),

         'pqrs': fields.char('pqrs field name', required=True),
       }

class e_f_g(osv.osv):
    _name = 'e.f.g'
    _description = 'efg description'
    _columns = {

x_y_z: fields.many2one(x.y.z, "xyz many2one")

}

here the field 'name' in x_y_z class is required to display the value properly, which i did not use initially and that was causing poblems

 

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for correcting me ivan

คำตอบที่ดีที่สุด

Responding to @Narender's answer: No, column "name" is not mandatory, although it is helpful.  But, you do have to designate a column with different name to be the "name" column (which, if not specified will default to column "name").  You can specify it in the _rec_name = "x_y_z", for example in the class e_f_g().  Another way to override the behaviour is to override the name_get() method of the class.  Here you can even combine several column's content as the name.  The original behaviour (if "name" column does not exist and is not specified in _rec_name attribute and name_get() is not overridden) is to display model_name,database_id pair.

อวตาร
ละทิ้ง