Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][18.0] theme*: fix website theme display error #358

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

haumenphai
Copy link

before:
theme_before_1

after:
theme_before

I used a tool to convert theme preview from image file to svg, if you have the original .svg file that would be better.

odoo 18 requires a .svg file (representing the theme) to display to users when selecting on the website, but all current themes lack that file.
function reference:

@staticmethod
    def _process_svg(theme, colors, image_mapping):
        svg = None
        try:
            with tools.file_open(f'{theme}/static/description/{theme}.svg', 'r') as file:
                svg = file.read()
        except FileNotFoundError:
            return False

        default_colors = {
            'color1': '#3AADAA',
            'color2': '#7C6576',
            'color3': '#F6F6F6',
            'color4': '#FFFFFF',
            'color5': '#383E45',
            'menu': '#MENU_COLOR',
            'footer': '#FOOTER_COLOR',
        }
        color_mapping = {default_colors[color_key]: color_value for color_key, color_value in colors.items() if color_key in default_colors.keys()}

        # Replace the default colors by the chosen ones
        for default_color, chosen_color in color_mapping.items():
            svg = svg.replace(default_color, chosen_color)

        # Replace the default images by the one corresponding to the industry
        for default_img, new_img in image_mapping.items():
            svg = svg.replace(default_img, new_img)
        return svg

One more thing: Modules that are not website themes should not have the category "Theme" or "Theme/..."
because it will be displayed on the website when the user creates the website and reaches the selection step.

ref function:

 @api.model
    def configurator_recommended_themes(self, industry_id, palette, result_nbr_max=3):
        Module = request.env['ir.module.module']
        domain = Module.get_themes_domain()
        domain = AND([[('name', '!=', 'theme_default')], domain])
        client_themes = Module.search(domain).mapped('name')
        client_themes_img = {t: get_manifest(t).get('images_preview_theme', {}) for t in client_themes if get_manifest(t)}
        themes_suggested = self._website_api_rpc(
            '/api/website/2/configurator/recommended_themes/%s' % (industry_id if industry_id > 0 else ''),
            {
                'client_themes': client_themes_img,
                'result_nbr_max': result_nbr_max,
            }
        )
        process_svg = self.env['website.configurator.feature']._process_svg
        for theme in themes_suggested:
            theme['svg'] = process_svg(theme['name'], palette, theme.pop('image_urls'))
        return themes_suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant