我们如何计算odoo10中One2many和many2one关系模型的内容。 例如:一个学院部门有很多部门。而且系有许多院系
每个部门负责人如何取得他/她的教授指派或教学。下面列出的型号
这是我的代码
*。PY
_name = 'faculty.of.departments'
department_ids = fields.One2many('departments','dept_faculty_id', readonly=True)
_name = 'departments'
dept_faculty_id = fields.Many2one('faculty.of.departments','Faculty of Department', required=True, select=True)
_name = 'faculty'
department_id = fields.One2many('departments','faculty_id')
答案 0 :(得分:0)
您只需要在要计算的字段上调用len
即可。例如,要计算教师中的部门,您可以这样做:
@api.model
def count_departments(self, faculty_id):
return len(self.search([('id', '=', faculty_id)]).department_id)
或
@api.one
def count_departments(self):
return len(self.department_id)
您可以查看文档以了解记录集的工作原理:https://www.odoo.com/documentation/10.0/reference/orm.html