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.

153 lines
5.7 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-today MuK IT GmbH.
  4. #
  5. # This file is part of MuK Grid Snippets
  6. # (see https://mukit.at).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###################################################################################
  22. import re
  23. import uuid
  24. import base64
  25. from odoo import api, fields, models
  26. XML_ID = "muk_web_theme._assets_primary_variables"
  27. SCSS_URL = "/muk_web_theme/static/src/scss/colors.scss"
  28. class ResConfigSettings(models.TransientModel):
  29. _inherit = 'res.config.settings'
  30. #----------------------------------------------------------
  31. # Database
  32. #----------------------------------------------------------
  33. theme_favicon = fields.Binary(
  34. related="company_id.favicon",
  35. readonly=False
  36. )
  37. theme_background_image = fields.Binary(
  38. related="company_id.background_image",
  39. readonly=False
  40. )
  41. theme_background_blend_mode = fields.Selection(
  42. related="company_id.background_blend_mode",
  43. readonly=False
  44. )
  45. theme_default_sidebar_preference = fields.Selection(
  46. related="company_id.default_sidebar_preference",
  47. readonly=False
  48. )
  49. theme_default_chatter_preference = fields.Selection(
  50. related="company_id.default_chatter_preference",
  51. readonly=False
  52. )
  53. theme_color_brand = fields.Char(
  54. string="Theme Brand Color"
  55. )
  56. theme_color_primary = fields.Char(
  57. string="Theme Primary Color"
  58. )
  59. theme_color_required = fields.Char(
  60. string="Theme Required Color"
  61. )
  62. theme_color_menu = fields.Char(
  63. string="Theme Menu Color"
  64. )
  65. theme_color_appbar_color = fields.Char(
  66. string="Theme AppBar Color"
  67. )
  68. theme_color_appbar_background = fields.Char(
  69. string="Theme AppBar Background"
  70. )
  71. #----------------------------------------------------------
  72. # Functions
  73. #----------------------------------------------------------
  74. def set_values(self):
  75. res = super(ResConfigSettings, self).set_values()
  76. param = self.env['ir.config_parameter'].sudo()
  77. variables = [
  78. 'o-brand-odoo',
  79. 'o-brand-primary',
  80. 'mk-required-color',
  81. 'mk-apps-color',
  82. 'mk-appbar-color',
  83. 'mk-appbar-background',
  84. ]
  85. colors = self.env['muk_web_theme.scss_editor'].get_values(
  86. SCSS_URL, XML_ID, variables
  87. )
  88. colors_changed = []
  89. colors_changed.append(self.theme_color_brand != colors['o-brand-odoo'])
  90. colors_changed.append(self.theme_color_primary != colors['o-brand-primary'])
  91. colors_changed.append(self.theme_color_required != colors['mk-required-color'])
  92. colors_changed.append(self.theme_color_menu != colors['mk-apps-color'])
  93. colors_changed.append(self.theme_color_appbar_color != colors['mk-appbar-color'])
  94. colors_changed.append(self.theme_color_appbar_background != colors['mk-appbar-background'])
  95. if(any(colors_changed)):
  96. variables = [
  97. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  98. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  99. {'name': 'mk-required-color', 'value': self.theme_color_required or "#d1dfe6"},
  100. {'name': 'mk-apps-color', 'value': self.theme_color_menu or "#f8f9fa"},
  101. {'name': 'mk-appbar-color', 'value': self.theme_color_appbar_color or "#dee2e6"},
  102. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar_background or "#000000"},
  103. ]
  104. self.env['muk_web_theme.scss_editor'].replace_values(
  105. SCSS_URL, XML_ID, variables
  106. )
  107. param.set_param('muk_web_theme.background_blend_mode', self.theme_background_blend_mode)
  108. return res
  109. @api.model
  110. def get_values(self):
  111. res = super(ResConfigSettings, self).get_values()
  112. params = self.env['ir.config_parameter'].sudo()
  113. variables = [
  114. 'o-brand-odoo',
  115. 'o-brand-primary',
  116. 'mk-required-color',
  117. 'mk-apps-color',
  118. 'mk-appbar-color',
  119. 'mk-appbar-background',
  120. ]
  121. colors = self.env['muk_web_theme.scss_editor'].get_values(
  122. SCSS_URL, XML_ID, variables
  123. )
  124. res.update({
  125. 'theme_color_brand': colors['o-brand-odoo'],
  126. 'theme_color_primary': colors['o-brand-primary'],
  127. 'theme_color_required': colors['mk-required-color'],
  128. 'theme_color_menu': colors['mk-apps-color'],
  129. 'theme_color_appbar_color': colors['mk-appbar-color'],
  130. 'theme_color_appbar_background': colors['mk-appbar-background'],
  131. 'theme_background_blend_mode': params.get_param('muk_web_theme.background_blend_mode', 'normal'),
  132. })
  133. return res