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.

144 lines
5.8 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. module_muk_web_theme_branding = fields.Boolean(
  31. string="Theme Branding",
  32. help="Customize the theme according to your needs.")
  33. module_muk_web_theme_website = fields.Boolean(
  34. string="Theme Website",
  35. help="Add theme styled website navigation.")
  36. theme_background_image = fields.Binary(
  37. related="company_id.background_image",
  38. readonly=False,
  39. required=True)
  40. theme_background_blend_mode = fields.Selection(
  41. related="company_id.background_blend_mode",
  42. readonly=False)
  43. theme_default_sidebar_preference = fields.Selection(
  44. related="company_id.default_sidebar_preference",
  45. readonly=False)
  46. theme_default_chatter_preference = fields.Selection(
  47. related="company_id.default_chatter_preference",
  48. readonly=False)
  49. theme_color_brand = fields.Char(
  50. string="Theme Brand Color")
  51. theme_color_primary = fields.Char(
  52. string="Theme Primary Color")
  53. theme_color_required = fields.Char(
  54. string="Theme Required Color")
  55. theme_color_menu = fields.Char(
  56. string="Theme Menu Color")
  57. theme_color_appbar_color = fields.Char(
  58. string="Theme AppBar Color")
  59. theme_color_appbar_background = fields.Char(
  60. string="Theme AppBar Background")
  61. #----------------------------------------------------------
  62. # Functions
  63. #----------------------------------------------------------
  64. @api.multi
  65. def set_values(self):
  66. res = super(ResConfigSettings, self).set_values()
  67. param = self.env['ir.config_parameter'].sudo()
  68. variables = [
  69. 'o-brand-odoo',
  70. 'o-brand-primary',
  71. 'mk-required-color',
  72. 'mk-apps-color',
  73. 'mk-appbar-color',
  74. 'mk-appbar-background',
  75. ]
  76. colors = self.env['muk_utils.scss_editor'].get_values(
  77. SCSS_URL, XML_ID, variables
  78. )
  79. colors_changed = []
  80. colors_changed.append(self.theme_color_brand != colors['o-brand-odoo'])
  81. colors_changed.append(self.theme_color_primary != colors['o-brand-primary'])
  82. colors_changed.append(self.theme_color_required != colors['mk-required-color'])
  83. colors_changed.append(self.theme_color_menu != colors['mk-apps-color'])
  84. colors_changed.append(self.theme_color_appbar_color != colors['mk-appbar-color'])
  85. colors_changed.append(self.theme_color_appbar_background != colors['mk-appbar-background'])
  86. if(any(colors_changed)):
  87. variables = [
  88. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  89. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  90. {'name': 'mk-required-color', 'value': self.theme_color_required or "#d1dfe6"},
  91. {'name': 'mk-apps-color', 'value': self.theme_color_menu or "#f8f9fa"},
  92. {'name': 'mk-appbar-color', 'value': self.theme_color_appbar_color or "#dee2e6"},
  93. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar_background or "#000000"},
  94. ]
  95. self.env['muk_utils.scss_editor'].replace_values(
  96. SCSS_URL, XML_ID, variables
  97. )
  98. param.set_param('muk_web_theme.background_blend_mode', self.theme_background_blend_mode)
  99. return res
  100. @api.model
  101. def get_values(self):
  102. res = super(ResConfigSettings, self).get_values()
  103. params = self.env['ir.config_parameter'].sudo()
  104. variables = [
  105. 'o-brand-odoo',
  106. 'o-brand-primary',
  107. 'mk-required-color',
  108. 'mk-apps-color',
  109. 'mk-appbar-color',
  110. 'mk-appbar-background',
  111. ]
  112. colors = self.env['muk_utils.scss_editor'].get_values(
  113. SCSS_URL, XML_ID, variables
  114. )
  115. res.update({
  116. 'theme_color_brand': colors['o-brand-odoo'],
  117. 'theme_color_primary': colors['o-brand-primary'],
  118. 'theme_color_required': colors['mk-required-color'],
  119. 'theme_color_menu': colors['mk-apps-color'],
  120. 'theme_color_appbar_color': colors['mk-appbar-color'],
  121. 'theme_color_appbar_background': colors['mk-appbar-background'],
  122. 'theme_background_blend_mode': params.get_param('muk_web_theme.background_blend_mode', 'normal'),
  123. })
  124. return res