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.

87 lines
3.2 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. theme_background_image = fields.Binary(
  28. related="company_id.background_image",
  29. readonly=False,
  30. required=True)
  31. theme_color_brand = fields.Char(
  32. string="Theme Brand Color")
  33. theme_color_primary = fields.Char(
  34. string="Theme Primary Color")
  35. theme_color_appbar = fields.Char(
  36. string="Theme AppBar Color")
  37. @api.multi
  38. def set_values(self):
  39. res = super(ResConfigSettings, self).set_values()
  40. variables = [
  41. 'o-brand-odoo',
  42. 'o-brand-primary',
  43. 'mk-appbar-background'
  44. ]
  45. colors = self.env['muk_utils.scss_editor'].get_values(
  46. SCSS_URL, XML_ID, variables
  47. )
  48. brand_changed = self.theme_color_brand != colors['o-brand-odoo']
  49. primary_changed = self.theme_color_primary != colors['o-brand-primary']
  50. appbar_changed = self.theme_color_appbar != colors['mk-appbar-background']
  51. if(brand_changed or primary_changed or appbar_changed):
  52. variables = [
  53. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  54. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  55. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar or "#000000"},
  56. ]
  57. self.env['muk_utils.scss_editor'].replace_values(
  58. SCSS_URL, XML_ID, variables
  59. )
  60. return res
  61. @api.model
  62. def get_values(self):
  63. res = super(ResConfigSettings, self).get_values()
  64. variables = [
  65. 'o-brand-odoo',
  66. 'o-brand-primary',
  67. 'mk-appbar-background'
  68. ]
  69. colors = self.env['muk_utils.scss_editor'].get_values(
  70. SCSS_URL, XML_ID, variables
  71. )
  72. res.update({
  73. 'theme_color_brand': colors['o-brand-odoo'],
  74. 'theme_color_primary': colors['o-brand-primary'],
  75. 'theme_color_appbar': colors['mk-appbar-background'],
  76. })
  77. return res