中国本土应用
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.0KB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-today MuK IT GmbH.
  4. #
  5. # This file is part of MuK Backend Theme
  6. # (see https://mukit.at).
  7. #
  8. # MuK Proprietary License v1.0
  9. #
  10. # This software and associated files (the "Software") may only be used
  11. # (executed, modified, executed after modifications) if you have
  12. # purchased a valid license from MuK IT GmbH.
  13. #
  14. # The above permissions are granted for a single database per purchased
  15. # license. Furthermore, with a valid license it is permitted to use the
  16. # software on other databases as long as the usage is limited to a testing
  17. # or development environment.
  18. #
  19. # You may develop modules based on the Software or that use the Software
  20. # as a library (typically by depending on it, importing it and using its
  21. # resources), but without copying any source code or material from the
  22. # Software. You may distribute those modules under the license of your
  23. # choice, provided that this license is compatible with the terms of the
  24. # MuK Proprietary License (For example: LGPL, MIT, or proprietary licenses
  25. # similar to this one).
  26. #
  27. # It is forbidden to publish, distribute, sublicense, or sell copies of
  28. # the Software or modified copies of the Software.
  29. #
  30. # The above copyright notice and this permission notice must be included
  31. # in all copies or substantial portions of the Software.
  32. #
  33. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  34. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  36. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  37. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  38. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  39. # DEALINGS IN THE SOFTWARE.
  40. #
  41. ###################################################################################
  42. import re
  43. import uuid
  44. import base64
  45. from odoo import api, fields, models
  46. class ResConfigSettings(models.TransientModel):
  47. _inherit = 'res.config.settings'
  48. #----------------------------------------------------------
  49. # Fields
  50. #----------------------------------------------------------
  51. theme_favicon = fields.Binary(
  52. related='company_id.favicon',
  53. readonly=False
  54. )
  55. theme_background_image = fields.Binary(
  56. related='company_id.background_image',
  57. readonly=False
  58. )
  59. theme_color_brand = fields.Char(
  60. string='Theme Brand Color'
  61. )
  62. theme_color_primary = fields.Char(
  63. string='Theme Primary Color'
  64. )
  65. theme_color_menu = fields.Char(
  66. string='Theme Menu Color'
  67. )
  68. theme_color_appbar_color = fields.Char(
  69. string='Theme AppBar Color'
  70. )
  71. theme_color_appbar_background = fields.Char(
  72. string='Theme AppBar Background'
  73. )
  74. #----------------------------------------------------------
  75. # Action
  76. #----------------------------------------------------------
  77. def action_reset_theme_assets(self):
  78. self.env['web_editor.assets'].reset_asset(
  79. '/muk_web_theme/static/src/colors.scss', 'web._assets_primary_variables',
  80. )
  81. return {
  82. 'type': 'ir.actions.client',
  83. 'tag': 'reload',
  84. }
  85. #----------------------------------------------------------
  86. # Functions
  87. #----------------------------------------------------------
  88. def set_values(self):
  89. res = super(ResConfigSettings, self).set_values()
  90. variables = [
  91. 'o-brand-odoo',
  92. 'o-brand-primary',
  93. 'mk-menu-color',
  94. 'mk-appbar-color',
  95. 'mk-appbar-background',
  96. ]
  97. colors = self.env['web_editor.assets'].get_theme_variables_values(
  98. '/muk_web_theme/static/src/colors.scss', 'web._assets_primary_variables', variables
  99. )
  100. colors_changed = []
  101. colors_changed.append(self.theme_color_brand != colors['o-brand-odoo'])
  102. colors_changed.append(self.theme_color_primary != colors['o-brand-primary'])
  103. colors_changed.append(self.theme_color_menu != colors['mk-menu-color'])
  104. colors_changed.append(self.theme_color_appbar_color != colors['mk-appbar-color'])
  105. colors_changed.append(self.theme_color_appbar_background != colors['mk-appbar-background'])
  106. if(any(colors_changed)):
  107. variables = [
  108. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  109. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  110. {'name': 'mk-menu-color', 'value': self.theme_color_menu or "#f8f9fa"},
  111. {'name': 'mk-appbar-color', 'value': self.theme_color_appbar_color or "#dee2e6"},
  112. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar_background or "#000000"},
  113. ]
  114. self.env['web_editor.assets'].replace_theme_variables_values(
  115. '/muk_web_theme/static/src/colors.scss', 'web._assets_primary_variables', variables
  116. )
  117. return res
  118. @api.model
  119. def get_values(self):
  120. res = super(ResConfigSettings, self).get_values()
  121. variables = [
  122. 'o-brand-odoo',
  123. 'o-brand-primary',
  124. 'mk-menu-color',
  125. 'mk-appbar-color',
  126. 'mk-appbar-background',
  127. ]
  128. colors = self.env['web_editor.assets'].get_theme_variables_values(
  129. '/muk_web_theme/static/src/colors.scss', 'web._assets_primary_variables', variables
  130. )
  131. res.update({
  132. 'theme_color_brand': colors['o-brand-odoo'],
  133. 'theme_color_primary': colors['o-brand-primary'],
  134. 'theme_color_menu': colors['mk-menu-color'],
  135. 'theme_color_appbar_color': colors['mk-appbar-color'],
  136. 'theme_color_appbar_background': colors['mk-appbar-background'],
  137. })
  138. return res
上海开阖软件有限公司 沪ICP备12045867号-1