forked from OCA/server-ux
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathres_users.py
57 lines (51 loc) · 2.14 KB
/
res_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, modules
class Users(models.Model):
_inherit = 'res.users'
review_ids = fields.Many2many(
string="Reviews", comodel_name="tier.review"
)
@api.model
def review_user_count(self):
user_reviews = {}
domain = [
("status", "=", "pending"),
("can_review", "=", True),
("id", "in", self.env.user.review_ids.ids),
]
review_groups = self.env["tier.review"].read_group(domain, ["model"], ["model"])
for review_group in review_groups:
model = review_group["model"]
reviews = self.env["tier.review"].search(review_group.get("__domain"))
if reviews:
records = (
self.env[model]
.sudo(self.env.user)
.search([("id", "in", reviews.mapped("res_id"))])
.filtered(lambda x: not x.rejected and x.can_review)
)
if len(records):
record = self.env[model]
user_reviews[model] = {
"name": record._description,
"model": model,
"icon": modules.module.get_module_icon(record._original_module),
"pending_count": len(records),
}
return list(user_reviews.values())
@api.model
def get_reviews(self, data):
review_obj = self.env['tier.review'].with_context(
lang=self.env.user.lang)
res = review_obj.search_read([('id', 'in', data.get('res_ids'))])
for r in res:
# Get the translated status value.
r['display_status'] = dict(
review_obj.fields_get('status')['status']['selection']
).get(r.get('status'))
# Convert to datetime timezone
if r['reviewed_date']:
r['reviewed_date'] = \
fields.Datetime.context_timestamp(self, r['reviewed_date'])
return res