res_users.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request as r
  3. def get_users():
  4. domain = [('active', '=', True)]
  5. current_user = r.env.user
  6. manager_id = None
  7. if 'Gerente' not in current_user.groups_id.filtered(lambda g: g.category_id.name == 'Eiru POS').mapped(lambda g: g.name):
  8. domain += [('store_id', '=', current_user.store_id.id)]
  9. else:
  10. manager_id = current_user.id
  11. return [
  12. {
  13. 'id': u.id,
  14. 'name': u.display_name,
  15. 'company': {
  16. 'id': u.company_id.id,
  17. 'name': u.company_id.display_name,
  18. 'phone': u.company_id.phone or None,
  19. 'city': u.company_id.city or None,
  20. 'street': u.company_id.street or None,
  21. 'city': u.company_id.city or None,
  22. 'country': (u.company_id.country_id and u.company_id.country_id.name) or None,
  23. 'currencyId': u.company_id.currency_id.id or None
  24. },
  25. 'isManager': u.id == manager_id,
  26. 'currentUser': u.id == current_user.id
  27. } for u in r.env['res.users'].search(domain)
  28. ]
  29. def get_current_user():
  30. user = r.env.user
  31. return {
  32. 'id': user.id,
  33. 'name': user.display_name,
  34. 'company': {
  35. 'id': user.company_id.id,
  36. 'name': user.company_id.display_name,
  37. 'phone': user.company_id.phone or None,
  38. 'city': user.company_id.city or None,
  39. 'street': user.company_id.street or None,
  40. 'city': user.company_id.city or None,
  41. 'country': (user.company_id.country_id and user.company_id.country_id.name) or None,
  42. 'currencyId': user.company_id.currency_id.id or None
  43. },
  44. 'isManager': 'Gerente' in user.groups_id.filtered(lambda g: g.category_id.name == 'Eiru POS').mapped(lambda g: g.name)
  45. }