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.

136 lines
5.5 KiB

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