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.

157 lines
6.3 KiB

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