中国本土应用
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.

74 lines
2.5KB

  1. # -*- coding: utf-8 -*-
  2. import json
  3. from odoo import api, fields, models, tools, _
  4. from odoo.addons.base.models.res_users import check_identity
  5. class ResUsers(models.Model):
  6. _inherit = "res.users"
  7. lock_screen = fields.Boolean(string="Lock Screen", default=False)
  8. theme_id = fields.Many2one(
  9. "res.theme", string="Theme", store=True, domain="[('user_id', '=', id)]"
  10. )
  11. # ------------------------------------------------------------
  12. # main
  13. # ------------------------------------------------------------
  14. main_menu_mode = fields.Selection(related="theme_id.main_menu_mode", readonly=False)
  15. main_submenu_position = fields.Selection(
  16. related="theme_id.main_submenu_position",
  17. readonly=False,
  18. )
  19. # ------------------------------------------------------------
  20. # SideNavbar
  21. # ------------------------------------------------------------
  22. sidebar_display_number_of_submenus = fields.Boolean(
  23. related="theme_id.sidebar_display_number_of_submenus", readonly=False
  24. )
  25. sidebar_fixed = fields.Boolean(related="theme_id.sidebar_fixed", readonly=False)
  26. sidebar_show_minimize_button = fields.Boolean(related="theme_id.sidebar_show_minimize_button", readonly=False)
  27. sidebar_default_minimized = fields.Boolean(
  28. related="theme_id.sidebar_default_minimized", readonly=False
  29. )
  30. sidebar_hover_maximize = fields.Boolean(
  31. related="theme_id.sidebar_hover_maximize", readonly=False
  32. )
  33. @api.model
  34. def set_user_theme(self, uid, theme):
  35. """
  36. 为当前用户设置主题。
  37. """
  38. result ={}
  39. try:
  40. user = self.browse(uid)
  41. user.theme_id.write(theme)
  42. except Exception as e:
  43. result = {
  44. "state":False,
  45. "title":_("Theme setting failed!"),
  46. "message":str(e)
  47. }
  48. else:
  49. result = {
  50. "state":True,
  51. "title":_("Theme set successfully!"),
  52. "message": _("The theme is set successfully, Click the 'Refresh' button to load the new theme.")
  53. }
  54. finally:
  55. return result
  56. @api.model_create_multi
  57. def create(self, vals_list):
  58. """
  59. 创建新用户时,创建主题
  60. """
  61. users = super(ResUsers, self).create(vals_list)
  62. for new_user in users:
  63. new_user.theme_id = self.env["res.theme"].sudo()._get_or_create_theme(new_user.id, "user")
  64. return users
上海开阖软件有限公司 沪ICP备12045867号-1