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.

65 lines
2.3 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="Brand Color")
  33. theme_color_primary = fields.Char(
  34. string="Primary Color")
  35. @api.multi
  36. def set_values(self):
  37. res = super(ResConfigSettings, self).set_values()
  38. variables = [
  39. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  40. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  41. ]
  42. self.env['muk_utils.scss_editor'].replace_values(
  43. SCSS_URL, XML_ID, variables
  44. )
  45. return res
  46. @api.model
  47. def get_values(self):
  48. res = super(ResConfigSettings, self).get_values()
  49. colors = self.env['muk_utils.scss_editor'].get_values(
  50. SCSS_URL, XML_ID, ['o-brand-odoo', 'o-brand-primary']
  51. )
  52. res.update({
  53. 'theme_color_brand': colors['o-brand-odoo'],
  54. 'theme_color_primary': colors['o-brand-primary'],
  55. })
  56. return res