diff --git a/muk_web_theme/__manifest__.py b/muk_web_theme/__manifest__.py index 31b4fdd..e2e7a5a 100644 --- a/muk_web_theme/__manifest__.py +++ b/muk_web_theme/__manifest__.py @@ -19,7 +19,7 @@ { "name": "MuK Backend Theme", "summary": "Odoo 12.0 community backend theme", - "version": "12.0.1.1.13", + "version": "12.0.1.1.14", "category": "Themes/Backend", "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_web_theme/models/res_config_settings.py b/muk_web_theme/models/res_config_settings.py index d9b4444..6f0100f 100644 --- a/muk_web_theme/models/res_config_settings.py +++ b/muk_web_theme/models/res_config_settings.py @@ -61,31 +61,14 @@ class ResConfigSettings(models.TransientModel): 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.search( r'o-brand-odoo\:?\s(.*?);', content) - primary = re.search( 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", - } + colors = self.env['muk_utils.scss_editor'].get_value( + SCSS_URL, XML_ID, ['o-brand-odoo', 'o-brand-primary'] + ) + return { + 'theme_color_brand': colors['o-brand-odoo'], + 'theme_color_primary': colors['o-brand-primary'], + } def _build_custom_scss_template(self): return TEMPLATE.format( @@ -94,40 +77,6 @@ class ResConfigSettings(models.TransientModel): ) 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(SCSS_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': SCSS_URL, - 'new_url': custom_url, - } - }) - self.env["ir.qweb"].clear_caches() \ No newline at end of file + self.env['muk_utils.scss_editor'].replace_content( + SCSS_URL, XML_ID, self._build_custom_scss_template() + ) \ No newline at end of file