请问怎么把 hr.employee 这张表里的人名在自己 model 的 tree 视图里显示?
-
请告诉我们你具体做了哪些尝试,谢谢!
-
把你的代码贴出来,我们更方便帮助你。
-
employee = fields.Char(string=u"姓名", compute="_get_employee_name", required=True) passive_employee_line = fields.Many2one("employee.passive.evaluate", string=u"Passive Employee Line", required=True) def _get_employee_name(self): for record in self.passive_employee_line: for employee in self: employee.employee = record.passive_evaluate.name_related print employee.employee class EmployeePassiveEvaluate(models.Model): _name = "employee.passive.evaluate" passive_evaluate_id = fields.Many2one("employee.start.evaluate", string=u"Passive Evaluate Id") passive_evaluate = fields.Many2one("hr.employee", string=u"被评价人", required=True)
这就是用到的代码
-
可以把
_get_employee_name
函数改成:@api.depends('passive_employee_line') def _get_employee_name(self): self.employee = self.passive_employee_line.passive_evalute.name_related
或者,更简单点,把employee定义为一个related字段:
employee = fields.Char(related='passive_employee_line.passive_evalute.name_related')