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.

71 lines
2.7 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. @api.multi
  36. def set_values(self):
  37. res = super(ResConfigSettings, self).set_values()
  38. colors = self.env['muk_utils.scss_editor'].get_values(
  39. SCSS_URL, XML_ID, ['o-brand-odoo', 'o-brand-primary']
  40. )
  41. brand_changed = self.theme_color_brand != colors['o-brand-odoo']
  42. primary_changed = self.theme_color_primary != colors['o-brand-primary']
  43. if(brand_changed or primary_changed):
  44. variables = [
  45. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  46. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  47. ]
  48. self.env['muk_utils.scss_editor'].replace_values(
  49. SCSS_URL, XML_ID, variables
  50. )
  51. return res
  52. @api.model
  53. def get_values(self):
  54. res = super(ResConfigSettings, self).get_values()
  55. colors = self.env['muk_utils.scss_editor'].get_values(
  56. SCSS_URL, XML_ID, ['o-brand-odoo', 'o-brand-primary']
  57. )
  58. res.update({
  59. 'theme_color_brand': colors['o-brand-odoo'],
  60. 'theme_color_primary': colors['o-brand-primary'],
  61. })
  62. return res