Files
app-odoo/app_users_chart_hierarchy/models/res_users.py
2019-06-10 05:36:45 +08:00

26 lines
895 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
from odoo import api, fields, models, tools, _
class Users(models.Model):
_inherit = "res.users"
# 注意res.partner 有 parent_id 和 child_ids
_parent_name = "user_parent_id"
_parent_store = True
parent_path = fields.Char(index=True)
user_parent_id = fields.Many2one('res.users', string='Parent User', index=True)
user_child_ids = fields.One2many('res.users', 'user_parent_id', string='Sub Users', domain=[('active', '=', True)])
user_child_all_count = fields.Integer(
'Indirect Surbordinates Count',
compute='_compute_user_child_all_count', store=False)
@api.depends('user_child_ids.user_child_all_count')
def _compute_user_child_all_count(self):
for rec in self:
rec.user_child_all_count = len(rec.user_child_ids) + sum(child.user_child_all_count for child in rec.user_child_ids)