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.

120 lines
4.6 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_default_sidebar_preference = fields.Selection(
  35. related="company_id.default_sidebar_preference",
  36. readonly=False)
  37. theme_default_chatter_preference = fields.Selection(
  38. related="company_id.default_chatter_preference",
  39. readonly=False)
  40. theme_color_brand = fields.Char(
  41. string="Theme Brand Color")
  42. theme_color_primary = fields.Char(
  43. string="Theme Primary Color")
  44. theme_color_menu = fields.Char(
  45. string="Theme Menu Color")
  46. theme_color_appbar_color = fields.Char(
  47. string="Theme AppBar Color")
  48. theme_color_appbar_background = fields.Char(
  49. string="Theme AppBar Background")
  50. #----------------------------------------------------------
  51. # Functions
  52. #----------------------------------------------------------
  53. @api.multi
  54. def set_values(self):
  55. res = super(ResConfigSettings, self).set_values()
  56. variables = [
  57. 'o-brand-odoo',
  58. 'o-brand-primary',
  59. 'mk-apps-color',
  60. 'mk-appbar-color',
  61. 'mk-appbar-background',
  62. ]
  63. colors = self.env['muk_utils.scss_editor'].get_values(
  64. SCSS_URL, XML_ID, variables
  65. )
  66. colors_changed = []
  67. colors_changed.append(self.theme_color_brand != colors['o-brand-odoo'])
  68. colors_changed.append(self.theme_color_primary != colors['o-brand-primary'])
  69. colors_changed.append(self.theme_color_menu != colors['mk-apps-color'])
  70. colors_changed.append(self.theme_color_appbar_color != colors['mk-appbar-color'])
  71. colors_changed.append(self.theme_color_appbar_background != colors['mk-appbar-background'])
  72. if(any(colors_changed)):
  73. variables = [
  74. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  75. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  76. {'name': 'mk-apps-color', 'value': self.theme_color_menu or "#f8f9fa"},
  77. {'name': 'mk-appbar-color', 'value': self.theme_color_appbar_color or "#dee2e6"},
  78. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar_background or "#000000"},
  79. ]
  80. self.env['muk_utils.scss_editor'].replace_values(
  81. SCSS_URL, XML_ID, variables
  82. )
  83. return res
  84. @api.model
  85. def get_values(self):
  86. res = super(ResConfigSettings, self).get_values()
  87. variables = [
  88. 'o-brand-odoo',
  89. 'o-brand-primary',
  90. 'mk-apps-color',
  91. 'mk-appbar-color',
  92. 'mk-appbar-background',
  93. ]
  94. colors = self.env['muk_utils.scss_editor'].get_values(
  95. SCSS_URL, XML_ID, variables
  96. )
  97. res.update({
  98. 'theme_color_brand': colors['o-brand-odoo'],
  99. 'theme_color_primary': colors['o-brand-primary'],
  100. 'theme_color_menu': colors['mk-apps-color'],
  101. 'theme_color_appbar_color': colors['mk-appbar-color'],
  102. 'theme_color_appbar_background': colors['mk-appbar-background'],
  103. })
  104. return res