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.

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