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

104 lines
3.1KB

  1. # -*- coding: utf-8 -*-
  2. from odoo import models, fields, api, _
  3. class ResTheme(models.Model):
  4. _name = "res.theme"
  5. _description = "Theme"
  6. name = fields.Char(
  7. string="Name",
  8. copy=False,
  9. compute="_compute_name",
  10. store=True,
  11. index=True,
  12. ) # 企业应用名称
  13. company_id = fields.Many2one(
  14. string="Company", comodel_name="res.company", ondelete="cascade", readonly=True
  15. )
  16. user_id = fields.Many2one(
  17. string="User", comodel_name="res.users", ondelete="cascade", readonly=True
  18. )
  19. type = fields.Selection(
  20. string="Type",
  21. selection=[("user", "User"), ("company", "Company")],
  22. # compute="_compute_company_type",
  23. # inverse="_write_company_type",
  24. )
  25. disable_theme_customizer = fields.Boolean(
  26. string="Disable theme customizer", default=False
  27. )
  28. # ------------------------------------------------------------
  29. # main
  30. # ------------------------------------------------------------
  31. main_menu_mode = fields.Selection(
  32. string="Menu mode",
  33. selection=[
  34. ("1", "Sidebar"),
  35. ],
  36. default="1",
  37. readonly=False,
  38. ) # ("2", "Favorites"), ("3", "Drawer")
  39. main_submenu_position = fields.Selection(
  40. string="Submenu location",
  41. selection=[
  42. ("1", "Navbar menu"),
  43. ("2", "Sidebar menu"),
  44. ("3", "Navbar menu and Sidebar menu"),
  45. ],
  46. default="3",
  47. readonly=False,
  48. )
  49. # ------------------------------------------------------------
  50. # SideNavbar
  51. # ------------------------------------------------------------
  52. sidebar_display_number_of_submenus = fields.Boolean(
  53. string="Display Number Of Submenus", default=True
  54. )
  55. sidebar_fixed = fields.Boolean(string="Fixed SideNavbar", default=True)
  56. sidebar_show_minimize_button = fields.Boolean(
  57. string="Show minimize button", default=True
  58. )
  59. sidebar_default_minimized = fields.Boolean(
  60. string="Default minimize", default=False
  61. )
  62. sidebar_hover_maximize = fields.Boolean(
  63. "Hover maximize", default=True
  64. )
  65. @api.depends("company_id", "user_id", "type")
  66. def _compute_name(self):
  67. for theme in self:
  68. labels = dict(self.fields_get(allfields=["type"])["type"]["selection"])[
  69. theme.type
  70. ]
  71. if theme.company_id:
  72. theme.name = "%s:%s" % (labels, theme.company_id.name)
  73. else:
  74. theme.name = "%s:%s" % (labels, theme.user_id.name)
  75. def _get_or_create_theme(self, id, type):
  76. """
  77. 通过id和type获取或者创建theme
  78. """
  79. domain = []
  80. vals = {}
  81. if type == "company":
  82. domain = [("company_id", "=", id), ("type", "=", "company")]
  83. vals = {"company_id": id, "type": "company"}
  84. elif type == "user":
  85. domain = [("user_id", "=", id), ("type", "=", "user")]
  86. vals = {"user_id": id, "type": "user"}
  87. theme = self.search(domain, limit=1)
  88. if not theme:
  89. theme = self.create(vals)
  90. return theme
上海开阖软件有限公司 沪ICP备12045867号-1