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.

390 lines
14 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. from odoo import api, fields, models
  20. PRIMARY_XML_ID = "muk_web_branding._assets_primary_variables"
  21. PRIMARY_SCSS_URL = "/muk_web_branding/static/src/scss/primary_colors.scss"
  22. SECONDARY_XML_ID = "muk_web_branding._assets_secondary_variables"
  23. SECONDARY_SCSS_URL = "/muk_web_branding/static/src/scss/secondary_colors.scss"
  24. BOOTSTRAP_XML_ID = "muk_web_branding._assets_backend_helpers"
  25. BOOTSTRAP_SCSS_URL = "/muk_web_branding/static/src/scss/bootstrap_colors.scss"
  26. class ResConfigSettings(models.TransientModel):
  27. _inherit = 'res.config.settings'
  28. #----------------------------------------------------------
  29. # Database
  30. #----------------------------------------------------------
  31. branding_color_brand = fields.Char(
  32. string="Brand Color")
  33. branding_color_primary = fields.Char(
  34. string="Primary Color")
  35. branding_color_secondary = fields.Char(
  36. string="Secondary Color")
  37. branding_color_lightsecondary = fields.Char(
  38. string="Light Secondary Color")
  39. branding_color_text = fields.Char(
  40. string="Text Color")
  41. branding_color_muted = fields.Char(
  42. string="Muted Color")
  43. branding_color_view = fields.Char(
  44. string="View Color")
  45. branding_color_background = fields.Char(
  46. string="Form Color")
  47. branding_color_notification_error = fields.Char(
  48. string="Notification Error Color")
  49. branding_color_notification_info = fields.Char(
  50. string="Notification Info Color")
  51. branding_color_01 = fields.Char(
  52. string="Color 01")
  53. branding_color_02 = fields.Char(
  54. string="Color 02")
  55. branding_color_03 = fields.Char(
  56. string="Color 03")
  57. branding_color_04 = fields.Char(
  58. string="Color 04")
  59. branding_color_05 = fields.Char(
  60. string="Color 05")
  61. branding_color_06 = fields.Char(
  62. string="Color 06")
  63. branding_color_07 = fields.Char(
  64. string="Color 07")
  65. branding_color_08 = fields.Char(
  66. string="Color 08")
  67. branding_color_09 = fields.Char(
  68. string="Color 09")
  69. branding_color_10 = fields.Char(
  70. string="Color 10")
  71. branding_color_11 = fields.Char(
  72. string="Color 11")
  73. branding_color_12 = fields.Char(
  74. string="Color 12")
  75. branding_color_success = fields.Char(
  76. string="Success Color")
  77. branding_color_info = fields.Char(
  78. string="Info Color")
  79. branding_color_warning = fields.Char(
  80. string="Warning Color")
  81. branding_color_danger = fields.Char(
  82. string="Danger Color")
  83. branding_color_light = fields.Char(
  84. string="Light Color")
  85. branding_color_dark = fields.Char(
  86. string="Dark Color")
  87. #----------------------------------------------------------
  88. # Helper
  89. #----------------------------------------------------------
  90. def _get_branding_primary_colors(self):
  91. variables = [
  92. 'o-community-color',
  93. 'o-enterprise-color',
  94. 'o-enterprise-primary-color',
  95. 'o-brand-odoo',
  96. 'o-brand-primary',
  97. 'o-gray',
  98. 'o-brand-secondary',
  99. 'o-brand-lightsecondary',
  100. 'o-main-text-color',
  101. 'o-main-color-muted',
  102. 'o-view-background-color',
  103. 'o-notification-error-bg-color',
  104. 'o-notification-info-bg-color',
  105. ]
  106. colors = self.env['muk_utils.scss_editor'].get_values(
  107. PRIMARY_SCSS_URL, PRIMARY_XML_ID, variables
  108. )
  109. if colors['o-brand-odoo'] == '$o-community-color':
  110. colors['o-brand-odoo'] = colors['o-community-color']
  111. if colors['o-brand-odoo'] == '$o-enterprise-color':
  112. colors['o-brand-odoo'] = colors['o-enterprise-color']
  113. if colors['o-brand-primary'] == '$o-community-color':
  114. colors['o-brand-primary'] = colors['o-community-color']
  115. if colors['o-brand-primary'] == '$o-enterprise-primary-color':
  116. colors['o-brand-primary'] = colors['o-enterprise-primary-color']
  117. if colors['o-brand-secondary'] == '$o-gray-100':
  118. colors['o-brand-secondary'] = colors['o-gray-100']
  119. if colors['o-brand-lightsecondary'] == '$o-gray-100':
  120. colors['o-brand-lightsecondary'] = colors['o-gray-100']
  121. if colors['o-brand-lightsecondary'] == '$o-gray-100':
  122. colors['o-brand-lightsecondary'] = colors['o-gray-100']
  123. return {
  124. 'branding_color_brand': colors['o-brand-odoo'],
  125. 'branding_color_primary': colors['o-brand-primary'],
  126. 'branding_color_secondary': colors['o-brand-secondary'],
  127. 'branding_color_lightsecondary': colors['o-brand-lightsecondary'],
  128. 'branding_color_text': colors['o-main-text-color'],
  129. 'branding_color_muted': colors['o-main-color-muted'],
  130. 'branding_color_view': colors['o-view-background-color'],
  131. 'branding_color_notification_error': colors['o-notification-error-bg-color'],
  132. 'branding_color_notification_info': colors['o-notification-info-bg-color'],
  133. }
  134. def _get_branding_secondary_colors(self):
  135. variables = [
  136. 'o-webclient-background-color',
  137. 'mk-color-01',
  138. 'mk-color-02',
  139. 'mk-color-03',
  140. 'mk-color-04',
  141. 'mk-color-05',
  142. 'mk-color-06',
  143. 'mk-color-07',
  144. 'mk-color-08',
  145. 'mk-color-09',
  146. 'mk-color-10',
  147. 'mk-color-11',
  148. 'mk-color-12',
  149. ]
  150. colors = self.env['muk_utils.scss_editor'].get_values(
  151. SECONDARY_SCSS_URL, SECONDARY_XML_ID, variables
  152. )
  153. return {
  154. 'branding_color_background': colors['o-webclient-background-color'],
  155. 'branding_color_01': colors['mk-color-01'],
  156. 'branding_color_02': colors['mk-color-02'],
  157. 'branding_color_03': colors['mk-color-03'],
  158. 'branding_color_04': colors['mk-color-04'],
  159. 'branding_color_05': colors['mk-color-05'],
  160. 'branding_color_06': colors['mk-color-06'],
  161. 'branding_color_07': colors['mk-color-07'],
  162. 'branding_color_08': colors['mk-color-08'],
  163. 'branding_color_09': colors['mk-color-09'],
  164. 'branding_color_10': colors['mk-color-10'],
  165. 'branding_color_11': colors['mk-color-11'],
  166. 'branding_color_12': colors['mk-color-12'],
  167. }
  168. def _get_branding_bootstrap_colors(self):
  169. variables = [
  170. 'success',
  171. 'info',
  172. 'warning',
  173. 'danger',
  174. 'light',
  175. 'dark',
  176. ]
  177. colors = self.env['muk_utils.scss_editor'].get_values(
  178. BOOTSTRAP_SCSS_URL, BOOTSTRAP_XML_ID, variables
  179. )
  180. return {
  181. 'branding_color_success': colors['success'],
  182. 'branding_color_info': colors['info'],
  183. 'branding_color_warning': colors['warning'],
  184. 'branding_color_danger': colors['danger'],
  185. 'branding_color_light': colors['light'],
  186. 'branding_color_dark': colors['dark'],
  187. }
  188. def _check_branding_colors(self, colors, variables):
  189. for values in variables:
  190. if colors[values['field']] != values['value']:
  191. return True
  192. return False
  193. def _set_branding_primary_colors(self):
  194. variables = [{
  195. 'name': 'o-brand-odoo',
  196. 'field': 'branding_color_brand',
  197. 'value': self.branding_color_brand or "#7C7BAD"
  198. }, {
  199. 'name': 'o-brand-primary',
  200. 'field': 'branding_color_primary',
  201. 'value': self.branding_color_primary or "#7C7BAD"
  202. }, {
  203. 'name': 'o-brand-secondary',
  204. 'field': 'branding_color_secondary',
  205. 'value': self.branding_color_secondary or "#f0eeee"
  206. }, {
  207. 'name': 'o-brand-lightsecondary',
  208. 'field': 'branding_color_lightsecondary',
  209. 'value': self.branding_color_lightsecondary or "#e2e2e0"
  210. }, {
  211. 'name': 'o-main-text-color',
  212. 'field': 'branding_color_text',
  213. 'value': self.branding_color_text or "#4c4c4c"
  214. }, {
  215. 'name': 'o-main-color-muted',
  216. 'field': 'branding_color_muted',
  217. 'value': self.branding_color_muted or "#a8a8a8"
  218. }, {
  219. 'name': 'o-view-background-color',
  220. 'field': 'branding_color_view',
  221. 'value': self.branding_color_view or "#ffffff"
  222. }, {
  223. 'name': 'o-notification-error-bg-color',
  224. 'field': 'branding_color_notification_error',
  225. 'value': self.branding_color_notification_error or "#F16567"
  226. }, {
  227. 'name': 'o-notification-info-bg-color',
  228. 'field': 'branding_color_notification_info',
  229. 'value': self.branding_color_notification_info or "#FCFBEA"
  230. }]
  231. colors = self._get_branding_primary_colors()
  232. if self._check_branding_colors(colors, variables):
  233. self.env['muk_utils.scss_editor'].replace_values(
  234. PRIMARY_SCSS_URL, PRIMARY_XML_ID, variables
  235. )
  236. def _set_branding_secondary_colors(self):
  237. variables = [{
  238. 'name': 'o-webclient-background-color',
  239. 'field': 'branding_color_background',
  240. 'value': self.branding_color_background or "#f9f9f9"
  241. }, {
  242. 'name': 'mk-color-01',
  243. 'field': 'branding_color_01',
  244. 'value': self.branding_color_01 or "#757575"
  245. }, {
  246. 'name': 'mk-color-02',
  247. 'field': 'branding_color_02',
  248. 'value': self.branding_color_02 or "#F06050"
  249. }, {
  250. 'name': 'mk-color-03',
  251. 'field': 'branding_color_03',
  252. 'value': self.branding_color_03 or "#F4A460"
  253. }, {
  254. 'name': 'mk-color-04',
  255. 'field': 'branding_color_04',
  256. 'value': self.branding_color_04 or "#F7CD1F"
  257. }, {
  258. 'name': 'mk-color-05',
  259. 'field': 'branding_color_05',
  260. 'value': self.branding_color_05 or "#6CC1ED"
  261. }, {
  262. 'name': 'mk-color-06',
  263. 'field': 'branding_color_06',
  264. 'value': self.branding_color_06 or "#814968"
  265. }, {
  266. 'name': 'mk-color-07',
  267. 'field': 'branding_color_07',
  268. 'value': self.branding_color_07 or "#EB7E7F"
  269. }, {
  270. 'name': 'mk-color-08',
  271. 'field': 'branding_color_08',
  272. 'value': self.branding_color_08 or "#2C8397"
  273. }, {
  274. 'name': 'mk-color-09',
  275. 'field': 'branding_color_09',
  276. 'value': self.branding_color_09 or "#475577"
  277. }, {
  278. 'name': 'mk-color-10',
  279. 'field': 'branding_color_10',
  280. 'value': self.branding_color_10 or "#D6145F"
  281. }, {
  282. 'name': 'mk-color-11',
  283. 'field': 'branding_color_11',
  284. 'value': self.branding_color_11 or "#30C381"
  285. }, {
  286. 'name': 'mk-color-12',
  287. 'field': 'branding_color_12',
  288. 'value': self.branding_color_12 or "#9365B8"
  289. }]
  290. colors = self._get_branding_secondary_colors()
  291. if self._check_branding_colors(colors, variables):
  292. self.env['muk_utils.scss_editor'].replace_values(
  293. SECONDARY_SCSS_URL, SECONDARY_XML_ID, variables
  294. )
  295. def _set_branding_bootstrap_colors(self):
  296. variables = [{
  297. 'name': 'success',
  298. 'field': 'branding_color_success',
  299. 'value': self.branding_color_success or "#28a745"
  300. }, {
  301. 'name': 'info',
  302. 'field': 'branding_color_info',
  303. 'value': self.branding_color_info or "#17a2b8"
  304. }, {
  305. 'name': 'warning',
  306. 'field': 'branding_color_warning',
  307. 'value': self.branding_color_warning or "#ffc107"
  308. }, {
  309. 'name': 'danger',
  310. 'field': 'branding_color_danger',
  311. 'value': self.branding_color_danger or "#dc3545"
  312. }, {
  313. 'name': 'light',
  314. 'field': 'branding_color_light',
  315. 'value': self.branding_color_light or "#f8f9fa"
  316. }, {
  317. 'name': 'dark',
  318. 'field': 'branding_color_dark',
  319. 'value': self.branding_color_dark or "#343a40"
  320. }]
  321. colors = self._get_branding_bootstrap_colors()
  322. if self._check_branding_colors(colors, variables):
  323. self.env['muk_utils.scss_editor'].replace_values(
  324. BOOTSTRAP_SCSS_URL, BOOTSTRAP_XML_ID, variables
  325. )
  326. #----------------------------------------------------------
  327. # Functions
  328. #----------------------------------------------------------
  329. @api.model
  330. def get_values(self):
  331. res = super(ResConfigSettings, self).get_values()
  332. res.update(self._get_branding_primary_colors())
  333. res.update(self._get_branding_secondary_colors())
  334. res.update(self._get_branding_bootstrap_colors())
  335. return res
  336. @api.multi
  337. def set_values(self):
  338. res = super(ResConfigSettings, self).set_values()
  339. self._set_branding_primary_colors()
  340. self._set_branding_secondary_colors()
  341. self._set_branding_bootstrap_colors()
  342. return res