You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.7 KiB

  1. # Copyright 2019 Eficent Business and IT Consulting Services S.L.
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models, modules
  4. class Users(models.Model):
  5. _inherit = 'res.users'
  6. review_ids = fields.Many2many(
  7. string="Reviews", comodel_name="tier.review"
  8. )
  9. @api.model
  10. def review_user_count(self):
  11. user_reviews = {}
  12. to_review_docs = {}
  13. for review in self.env.user.review_ids.filtered(
  14. lambda r: r.status == 'pending'):
  15. record = review.env[review.model].browse(review.res_id)
  16. if not user_reviews.get(review['model']):
  17. user_reviews[review.model] = {
  18. 'name': record._description,
  19. 'model': review.model,
  20. 'icon': modules.module.get_module_icon(
  21. self.env[review.model]._original_module),
  22. 'pending_count': 0
  23. }
  24. docs = to_review_docs.get(review.model)
  25. if (docs and record not in docs) or not docs:
  26. user_reviews[review.model]['pending_count'] += 1
  27. to_review_docs.setdefault(review.model, []).append(record)
  28. return list(user_reviews.values())
  29. @api.model
  30. def get_reviews(self, data):
  31. review_obj = self.env['tier.review'].with_context(
  32. lang=self.env.user.lang)
  33. res = review_obj.search_read([('id', 'in', data.get('res_ids'))])
  34. for r in res:
  35. # Get the translated status value.
  36. r['display_status'] = dict(
  37. review_obj.fields_get('status')['status']['selection']
  38. ).get(r.get('status'))
  39. return res