How to show the name of 3rd ref class in UI?

I have 3 level of class dependency, the 1st is (Staff) below:

class Staff(ModelSQL, ModelView):
    'Staff'
    __name__ = 'ltl.staff'
    _rec_name = 'name'

    name = fields.Char('Name', required=True)
    gender = fields.Selection([
        (None, 'Select..'),
        ('Male', 'Male'),
        ('Female', 'Female')
    ], 'Gender')

This Staff class is called from the 2nd class (EmploymentStaff) as below:

class EmploymentStaff(ModelSQL, ModelView):
    'Staff'
    __name__ = 'ltl.employment.staff'
    _rec_name = 'staff.name'

    staff = fields.Many2One('ltl.staff', 'Employee', required=True)

    role = fields.Selection('get_roles', 'Position', sort=False, required=True)

This EmploymentStaff is called from the 3rd class (ProjectMember) as below:

class ProjectMember(ModelSQL, ModelView):
    'Project Member'
    __name__ = 'ltl.project.member'
    _rec_name = 'member.staff'

    project = fields.Many2One('ltl.project', 'Project', required=True)

    member = fields.Many2One('ltl.employment.staff', 'Member', required=True)

I try to render the name of the staff in ProjectMember list UI, but I got ProjectMember ID instead, see below screenshot:

How to render the staff’s name.. if the real object is at 3rd level?

Note: in the EmploymentStaff list UI, I can show the staff’s name.. this problem only appears on the 3rd level call

Bromo

It is not possible to use dot notation int the _rec_name attribute as you did here:

As tryton does not find a field which such name it just shows the ID.

You should override the get_rec_name function to return the text you want.

In your case, if you want to show the rec_name of the staff it should be something like this:

def get_rec_name(self, name):
    return self.staff.rec_name
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.