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.

154 lines
6.0 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_background_image = fields.Binary(
  46. related="company_id.background_image",
  47. readonly=False)
  48. theme_background_blend_mode = fields.Selection(
  49. related="company_id.background_blend_mode",
  50. readonly=False)
  51. theme_default_sidebar_preference = fields.Selection(
  52. related="company_id.default_sidebar_preference",
  53. readonly=False)
  54. theme_default_chatter_preference = fields.Selection(
  55. related="company_id.default_chatter_preference",
  56. readonly=False)
  57. theme_color_brand = fields.Char(
  58. string="Theme Brand Color")
  59. theme_color_primary = fields.Char(
  60. string="Theme Primary Color")
  61. theme_color_required = fields.Char(
  62. string="Theme Required Color")
  63. theme_color_menu = fields.Char(
  64. string="Theme Menu Color")
  65. theme_color_appbar_color = fields.Char(
  66. string="Theme AppBar Color")
  67. theme_color_appbar_background = fields.Char(
  68. string="Theme AppBar Background")
  69. #----------------------------------------------------------
  70. # Functions
  71. #----------------------------------------------------------
  72. @api.multi
  73. def set_values(self):
  74. res = super(ResConfigSettings, self).set_values()
  75. param = self.env['ir.config_parameter'].sudo()
  76. variables = [
  77. 'o-brand-odoo',
  78. 'o-brand-primary',
  79. 'mk-required-color',
  80. 'mk-apps-color',
  81. 'mk-appbar-color',
  82. 'mk-appbar-background',
  83. ]
  84. colors = self.env['muk_utils.scss_editor'].get_values(
  85. SCSS_URL, XML_ID, variables
  86. )
  87. colors_changed = []
  88. colors_changed.append(self.theme_color_brand != colors['o-brand-odoo'])
  89. colors_changed.append(self.theme_color_primary != colors['o-brand-primary'])
  90. colors_changed.append(self.theme_color_required != colors['mk-required-color'])
  91. colors_changed.append(self.theme_color_menu != colors['mk-apps-color'])
  92. colors_changed.append(self.theme_color_appbar_color != colors['mk-appbar-color'])
  93. colors_changed.append(self.theme_color_appbar_background != colors['mk-appbar-background'])
  94. if(any(colors_changed)):
  95. variables = [
  96. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  97. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  98. {'name': 'mk-required-color', 'value': self.theme_color_required or "#d1dfe6"},
  99. {'name': 'mk-apps-color', 'value': self.theme_color_menu or "#f8f9fa"},
  100. {'name': 'mk-appbar-color', 'value': self.theme_color_appbar_color or "#dee2e6"},
  101. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar_background or "#000000"},
  102. ]
  103. self.env['muk_utils.scss_editor'].replace_values(
  104. SCSS_URL, XML_ID, variables
  105. )
  106. param.set_param('muk_web_theme.background_blend_mode', self.theme_background_blend_mode)
  107. return res
  108. @api.model
  109. def get_values(self):
  110. res = super(ResConfigSettings, self).get_values()
  111. params = self.env['ir.config_parameter'].sudo()
  112. variables = [
  113. 'o-brand-odoo',
  114. 'o-brand-primary',
  115. 'mk-required-color',
  116. 'mk-apps-color',
  117. 'mk-appbar-color',
  118. 'mk-appbar-background',
  119. ]
  120. colors = self.env['muk_utils.scss_editor'].get_values(
  121. SCSS_URL, XML_ID, variables
  122. )
  123. res.update({
  124. 'theme_color_brand': colors['o-brand-odoo'],
  125. 'theme_color_primary': colors['o-brand-primary'],
  126. 'theme_color_required': colors['mk-required-color'],
  127. 'theme_color_menu': colors['mk-apps-color'],
  128. 'theme_color_appbar_color': colors['mk-appbar-color'],
  129. 'theme_color_appbar_background': colors['mk-appbar-background'],
  130. 'theme_background_blend_mode': params.get_param('muk_web_theme.background_blend_mode', 'normal'),
  131. })
  132. return res