From 5bc628aa936a4664b22e8e9c7653b27e76bf6770 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Thu, 29 Nov 2018 02:48:41 +0000 Subject: [PATCH] publish muk_web_theme - 12.0 --- muk_web_theme/__manifest__.py | 2 +- muk_web_theme/doc/changelog.rst | 5 + muk_web_theme/models/res_config_settings.py | 107 +++++++++++++++++- .../views/res_config_settings_view.xml | 19 ++++ 4 files changed, 131 insertions(+), 2 deletions(-) diff --git a/muk_web_theme/__manifest__.py b/muk_web_theme/__manifest__.py index 49ade47..f36d45a 100644 --- a/muk_web_theme/__manifest__.py +++ b/muk_web_theme/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Backend Theme", "summary": "Odoo 12.0 community backend theme", - "version": "12.0.1.0.0", + "version": "12.0.1.1.0", "category": "Themes/Backend", "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_web_theme/doc/changelog.rst b/muk_web_theme/doc/changelog.rst index d62cbe4..c1d809d 100644 --- a/muk_web_theme/doc/changelog.rst +++ b/muk_web_theme/doc/changelog.rst @@ -1,3 +1,8 @@ +`1.1.0` +------- + +- Added Color Customize Options + `1.0.0` ------- diff --git a/muk_web_theme/models/res_config_settings.py b/muk_web_theme/models/res_config_settings.py index ada2544..eb4abda 100644 --- a/muk_web_theme/models/res_config_settings.py +++ b/muk_web_theme/models/res_config_settings.py @@ -17,12 +17,117 @@ # ################################################################################### +import re +import uuid +import base64 + from odoo import api, fields, models +XML_ID = "muk_web_theme._assets_primary_variables" +SCSS_URL = "/muk_web_theme/static/src/scss/colors.scss" + +TEMPLATE = """ + $o-brand-odoo: {0}; + $o-brand-primary: {1}; + + $mk-brand-gradient-start: lighten($o-brand-odoo, 10%); + $mk-brand-gradient-end: lighten($o-brand-odoo, 20%); +""" + class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' theme_background_image = fields.Binary( related="company_id.background_image", - readonly=False) \ No newline at end of file + readonly=False, + required=True) + + theme_color_brand = fields.Char( + string="Brand Color") + + theme_color_primary = fields.Char( + string="Primary Color") + + @api.multi + def set_values(self): + res = super(ResConfigSettings, self).set_values() + self._save_scss_values() + return res + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + res.update(self._get_scss_values()) + return res + + def _get_custom_scss_url(self, url, xmlid): + return self._build_custom_scss_url(url.rsplit(".", 1), xmlid) + + def _build_custom_scss_url(self, url_parts, xmlid): + return "%s.custom.%s.%s" % (url_parts[0], xmlid, url_parts[1]) + + def _get_custom_attachment(self, url): + return self.env["ir.attachment"].search([("url", '=', url)]) + + def _get_scss_values(self): + custom_url = self._get_custom_scss_url(SCSS_URL, XML_ID) + custom_attachment = self._get_custom_attachment(custom_url) + if custom_attachment.exists(): + content = str(base64.b64decode(custom_attachment.datas)) + brand = re.match( r'o-brand-odoo\:?\s(.*?);', content) + primary = re.match( r'o-brand-primary\:?\s(.*?);', content) + return { + 'theme_color_brand': brand and brand.group(1) or "#243742", + 'theme_color_primary': primary and primary.group(1) or "#5D8DA8", + } + else: + return { + 'theme_color_brand': "#243742", + 'theme_color_primary': "#5D8DA8", + } + + def _build_custom_scss_template(self): + return TEMPLATE.format( + self.theme_color_brand or "#243742", + self.theme_color_primary or "#5D8DA8" + ) + + def _save_scss_values(self): + custom_url = self._get_custom_scss_url(SCSS_URL, XML_ID) + custom_attachment = self._get_custom_attachment(custom_url) + custom_content = self._build_custom_scss_template() + datas = base64.b64encode((custom_content).encode("utf-8")) + if custom_attachment: + custom_attachment.write({"datas": datas}) + else: + self.env["ir.attachment"].create({ + 'name': custom_url, + 'type': "binary", + 'mimetype': "text/scss", + 'datas': datas, + 'datas_fname': SCSS_URL.split("/")[-1], + 'url': custom_url, + }) + view_to_xpath = self.env["ir.ui.view"].get_related_views( + XML_ID, bundles=True + ).filtered(lambda v: v.arch.find(url) >= 0) + self.env["ir.ui.view"].create({ + 'name': custom_url, + 'key': 'web_editor.scss_%s' % str(uuid.uuid4())[:6], + 'mode': "extension", + 'inherit_id': view_to_xpath.id, + 'arch': """ + + + %(new_url)s + + + """ % { + 'inherit_xml_id': view_to_xpath.xml_id, + 'name': custom_url, + 'url_to_replace': url, + 'new_url': custom_url, + } + }) + self.env["ir.qweb"].clear_caches() \ No newline at end of file diff --git a/muk_web_theme/views/res_config_settings_view.xml b/muk_web_theme/views/res_config_settings_view.xml index 7e4841e..ec4db53 100644 --- a/muk_web_theme/views/res_config_settings_view.xml +++ b/muk_web_theme/views/res_config_settings_view.xml @@ -43,6 +43,25 @@ +
+
+
+
+ Theme Colors +
+ Set the main theme colors +
+
+
+
+
+
+