我有员工表
EMPID | EMPNAME
1 | A
2 | B
我有[经理表]
MNGID | EMPID
2 | 1
以上MNGID指员工表表示B是A的经理。
我想查询显示管理员名称和员工姓名。请注意结果
答案 0 :(得分:0)
这应该适合你:
class my_tasks(models.Model):
_inherit ='project.task'
identify_manager = fields.Boolean(compute='check_user')
@api.model
def check_user(self):
data = {}
# search current user id
user_id = self.env['res.users'].search([('id', '=', self.env.user.id)])
# search the module category which called as My module
user_my_category_id = self.env['ir.module.category'].search([('name', '=', 'My Module')])
# search the manager id which belongs to my module category
user_new_id = self.env['res.groups'].search(
[('category_id', '=', user_my_category_id.id), ('name', '=', "Manager")]).id
# search using count whether the current user has a role of manager for my project module
query = """select COUNT(*) from res_groups_users_rel where uid=%d and gid=%d """ % (user_id.id, user_tiq_id)
self.env.cr.execute(query)
result = self.env.cr.fetchall()
# convert the string count into a integer
json_result = json.dumps(result, ensure_ascii=False)
count = json_result.strip('\' \" [] ')
str_count = str(count)
int_count = int(str_count)
if int_count != 0:
self.identify_manager = True
else:
self.identify_manager = False
答案 1 :(得分:0)
试试这个[更新的查询]:
SELECT
m1.empname as manager,
e.empname as employee
FROM
Manager m
JOIN
Employee e
ON
m.empid = e.empid
JOIN
Employee m1
ON
m1.empid = m.mngid
=====