[10.0][IMP][website_multi_theme] make customize_show views part of multi-theme - #443
Conversation
yelizariev
left a comment
There was a problem hiding this comment.
Some explanation of the updates
| License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). --> | ||
| <odoo> | ||
| <!-- Default theme. It's basically a workaround for "Multi-customization" | ||
| feature which requires theme be set --> |
There was a problem hiding this comment.
I don't see other solution. At least until we make refactoring discussed #409
| string="Copied from", | ||
| help="View from where this one was copied for multi-website" | ||
| ) | ||
| copy_ids = fields.One2many( |
There was a problem hiding this comment.
Those two fields are left after initial draft of this update, but I think it could useful later
| xmlid, | ||
| self.display_name, | ||
| ), | ||
| "name": '%s (Multi-Website)' % pattern.name, |
There was a problem hiding this comment.
It's renamed, because this name is used in Customize menu (grayed text)
There was a problem hiding this comment.
Maybe, the name can be changed to '%s (Website #%s)' % (pattern.name, self.id) , because Multi-website sounds like the same per different websites
There was a problem hiding this comment.
I don't want to use self.display_name, because website could be renamed
| ), | ||
| "name": '%s (Multi-Website)' % pattern.name, | ||
| "website_id": self.id, | ||
| "origin_view_id": pattern.id, |
There was a problem hiding this comment.
It's kind of replacement to removed data in name
| # used | ||
| copied_parent = self._find_duplicate_view_for_website( | ||
| parent_view, website | ||
| ) |
There was a problem hiding this comment.
It's not directly part of this update, though there is a theoretical situation when several Customized views inherit each other, so they need to use a copied view too. But I need to make real multi-footer in my module website_multi_company to apply some extension to make website.footer_custom copyable too
|
|
||
| if refs or one.asset_ids: | ||
| # add common_refs only for installed themes | ||
| refs += common_refs |
There was a problem hiding this comment.
This is the key idea of the update
There was a problem hiding this comment.
In general I recommend to use |=, to avoid duplicates in the recordsets.
| id="layout_pattern" | ||
| inherit_id="website.layout" | ||
| name="Template for replacing assets_frontend" | ||
| name="Main layout" |
There was a problem hiding this comment.
it's renamed because it's used in Customize menu
| result = pattern.copy({ | ||
| "active": pattern.was_active, | ||
| "arch_fs": False, | ||
| "customize_show": False, |
There was a problem hiding this comment.
@yajo is there any reason why this was set to False? Do you remember the case when it's required?
| * If you install any of the supported themes after installing this addon, you | ||
| will have to press *Reload* in the website config wizard to make it notice | ||
| the change. | ||
| the change. The same is true when you install any module with ``customize_show="True"`` |
There was a problem hiding this comment.
Tests are not passed in travis due to this new requirement: Reload must be done after installing website_blog_category https://github.com/OCA/website/blob/10.0/website_blog_category/templates/website_blog_template.xml#L25
What can we do here? @yajo @pedrobaeza
There was a problem hiding this comment.
What about calling reload from the last demo data file read?
There was a problem hiding this comment.
Do you mean demo file of website_blog_category?
There was a problem hiding this comment.
I'd prefer to Reload after creating new ir.ui.view record with customize_show (via extending create method). What do you think, @pedrobaeza ?
There was a problem hiding this comment.
That would make sense, yes.
I was talking about demo data file included in this addon. Or even maybe a normal data file.
| result = pattern.copy({ | ||
| "active": pattern.was_active, | ||
| "arch_fs": False, | ||
| "customize_show": False, |
There was a problem hiding this comment.
Copied message to don't miss it:
@yajo is there any reason why this was set to False? Do you remember the case when it's required?
There was a problem hiding this comment.
OK, let me know if I understand what you are doing here:
-
Now all websites have a theme, even if it must be the default one. I like this approach, it reduces variability 😊
-
Converted assets inherit the
customize_showattribute independently. -
All views with
customize_show=Trueare considered multiwebsite views. I'm not sure if we should instead duplicate all views belonging to addons that depend onwebsite; after all, a user usually can customize any view in a website... 🤔
Some comments below. Thanks!
| result = pattern.copy({ | ||
| "active": pattern.was_active, | ||
| "arch_fs": False, | ||
| "customize_show": False, |
|
|
||
| parent_view = copied_view.inherit_id | ||
| parent_view_module = parent_view.model_data_id.module | ||
| copied_parent = None |
There was a problem hiding this comment.
This line makes no sense now, isn't it?
| class IrUiView(models.Model): | ||
| _inherit = 'ir.ui.view' | ||
|
|
||
| multi_theme_generated = fields.Boolean( |
There was a problem hiding this comment.
You need a migration script to fill origin_view_id from preexisting views that had this boolean set to true.
| inverse_name="website_id", | ||
| domain=[("multi_theme_generated", "=", True), | ||
| domain=[("origin_view_id", "!=", False), | ||
| "|", ("active", "=", True), ("active", "=", False)], |
There was a problem hiding this comment.
Maybe we should replace this by context={"active_test": True}
There was a problem hiding this comment.
I cannot find an example of using such trick. Are you sure that context is used when we read the field in python via .multi_theme_view_ids and other cases? I'd prefer to keep as it's now
There was a problem hiding this comment.
OK no problem, it was just an idea
|
|
||
| if refs or one.asset_ids: | ||
| # add common_refs only for installed themes | ||
| refs += common_refs |
There was a problem hiding this comment.
In general I recommend to use |=, to avoid duplicates in the recordsets.
| ]) | ||
| existing = frozenset(one.mapped("asset_ids.name")) | ||
|
|
||
| common_refs = self.env["ir.model.data"] |
There was a problem hiding this comment.
This line is not needed; the next sentence will return an empty recordset when nothing is found.
There was a problem hiding this comment.
The idea was to allow in possible next updates don't change git blame much.
For example,
Version1
common_refs = self.env["ir.model.data"]
common_refs |= A
Version 2
common_refs = self.env["ir.model.data"]
common_refs |= A
common_refs |= B
Version 3
common_refs = self.env["ir.model.data"]
common_refs |= A1
common_refs |= B
common_refs |= C
Version 5
common_refs = self.env["ir.model.data"]
common_refs |= B
common_refs |= C
| "website, and disabled otherwise. Usually used to load assets.", | ||
| ) | ||
|
|
||
| auto = fields.Boolean( |
There was a problem hiding this comment.
Do you mean above _sql_constraints? It's actually not explained in the guidelines. It mentions only constrain methods. While _sql_constraints seems to be part of
Private attributes (_name, _description, _inherit, ...)
There was a problem hiding this comment.
Yikes! forget this. I think I didn't expand the diff in between 😆
| <separator string="Copies"/> | ||
| <field name="copy_ids"/> | ||
| </page> | ||
| <page string="Multi-website" attrs="{'invisible': [('origin_view_id', '=', False)]}"> |
There was a problem hiding this comment.
2 pages called the same?
Better 1 page and 2 groups.
Remember to add a name="multiwebsite", to enable possible inheritance.
There was a problem hiding this comment.
The idea is don't pass attributes twice in each node here:
<separator string="Copies"/>
<field name="copy_ids"/>
There was a problem hiding this comment.
I can add different names, if it's the concern
name="multiwebsite_origin_view"
name="multiwebsite_copied_view"
| <label for="multi_theme_id"/> | ||
| <div> | ||
| <field name="multi_theme_id" class="oe_inline"/> | ||
| <field name="multi_theme_id" class="oe_inline" required="1"/> |
There was a problem hiding this comment.
Because we have default website, which doesn't have multi_theme_id on installation and we cannot set it on installation, because Default theme is created after loading python files
There was a problem hiding this comment.
It makes sense. Could you add a note here then please? It's not obvious...
| * Rafael Blasco <rafael.blasco@tecnativa.com> | ||
| * Antonio Espinosa <antonio.espinosa@tecnativa.com> | ||
| * Jairo Llopis <jairo.llopis@tecnativa.com> | ||
| * Ivan Yelizariev <https://it-projects.info/team/yelizariev> |
There was a problem hiding this comment.
I can't believe you weren't here before!
b21031f to
8aa5f94
Compare
|
Rebased and added some fixes. Few comments from @yajo's review are subject to discuss. I'll squash commits once we close all concerns or one can do it on merging (just fist commit message has to be keeped: |
|
About this idea:
The possible problem here is that those changes will be destroyed after switching a website to new theme. So, it's better to share them, than letting user face data lost |
|
I'll do this later
|
|
Thank you @yelizariev for this great contribution! 😄 👏 👏 👏 |
8fb65b0 to
c5836fc
Compare
|
I added migration scripts and squashed the PR Previous history: |
c5836fc to
b97a462
Compare
|
And another commit yelizariev@1984fbf |
b97a462 to
0252aee
Compare
|
One more update from @yajo's review yelizariev@0fd0ad3 and there is still the question about travis tests. Can we do something about it or just left it as is |
|
@yelizariev |
|
I think the error was introduced in a4ed42f#diff-93d51900ef6c23af9b0a13e1278dfad5R45 by @yajo How to reproduce without this updates:
|
|
@yajo could you check and fix? |
|
See #447 |
0252aee to
64c5033
Compare
|
Rebased |
64c5033 to
a3c2d6a
Compare
|
Update for the last question: yelizariev@3b61c5d It took more time than I thought @yajo your review is very needed |
a3c2d6a to
f0bb1c1
Compare
|
Other updates LINT: yelizariev@52b962f |
f0bb1c1 to
e9d2100
Compare
|
Please @yajo could you review here? Thank you! |
yajo
left a comment
There was a problem hiding this comment.
Amazing work, now just minor details
| help="Indicates if the view was originally active before converting " | ||
| "the single website theme that owns it to multi website mode.", | ||
| ) | ||
|
|
| ) | ||
| website.multi_theme_view_ids.unlink() | ||
| continue | ||
| if not default_theme: |
There was a problem hiding this comment.
If I'm not wrong, this if will never pass because the above call to ref() doesn't have a raise_if_not_found=False.
OTOH I'd use the try-except-else option instead.
| ("model", "=", "ir.ui.view"), | ||
| ]) | ||
|
|
||
| common_refs = self.env["ir.model.data"] |
There was a problem hiding this comment.
You can delete this, the search below will return an empty recordset on his own if no results are found.
There was a problem hiding this comment.
My explanation is here: #443 (comment)
You probably miss it. What do you think about it?
|
Tiny updates yelizariev@e028b32 |
e9d2100 to
d6cd84a
Compare
| "version": "10.0.1.2.0", | ||
| "category": "Website", | ||
| "website": "https://www.tecnativa.com", | ||
| "author": "Tecnativa, Odoo Community Association (OCA)", |
d6cd84a to
62eabef
Compare
| def create(self, vals): | ||
| res = super(IrModelData, self).create(vals) | ||
| if vals.get('model') == 'ir.ui.view' \ | ||
| and not self.env.context.get('duplicate_view_for_website'): |
There was a problem hiding this comment.
Incorrect indendation and line split
There was a problem hiding this comment.
Multi-line if-block is my weak side 😞
There was a problem hiding this comment.
The best is to enclose in parenthesis and always indent second line 2 levels more:
if (vals.get('model') == 'ir.ui.view' and
not self.env.context.get('duplicate_view_for_website')):There was a problem hiding this comment.
I'd prefer to put logical operator at the beginning of the line
There was a problem hiding this comment.
Oh, it's W503 requirement. OK
There was a problem hiding this comment.
I'm not the only one who thinks so.
W503 is ignored by default in latest version of pycodestyle.
There was a problem hiding this comment.
I said wrong. W504 is ignored by default
There was a problem hiding this comment.
But people say that W504 is more logical
There was a problem hiding this comment.
Well, we can discuss about that in the issue, but right now it's W503 what is used.
| "origin_view_id", | ||
| string="Copies", | ||
| readonly=True, | ||
| help="Duplicates of this view" |
There was a problem hiding this comment.
I would prefer a more explicit name: multitheme_copy_ids and a longer explanation in help.
| and not self.env.context.get('duplicate_view_for_website'): | ||
| view = self.env['ir.ui.view'].browse(vals.get('res_id')) | ||
| if view.customize_show: | ||
| # Reload theme to make new customize_show available right after |
There was a problem hiding this comment.
Put this explanation in the method docstring instead of here, as it's the purpose of the override.
| views = super(IrUiView, self)._customize_template_get_views( | ||
| key, full=full, bundles=bundles | ||
| ) | ||
|
|
There was a problem hiding this comment.
These empty lines don't add anything useful and PEP8 discourages its use. Better to strip them.
| comodel_name='website.theme', | ||
| domain=[("asset_ids.view_id", "!=", False)], | ||
| help="Multiwebsite-compatible theme for this website", | ||
| require=True, |
There was a problem hiding this comment.
Please don't add require fields in inherited classes, as this will make that tests that create records from this model fail when this dependent module is not loaded. Instead, put the require on the view.
There was a problem hiding this comment.
I believe it's true for existing fields only, while here we create a new field.
There was a problem hiding this comment.
No, it's the same. The sequence is the following in MQT:
- This module is installed along with all the testable ones and its dependencies.
- Then the SQL NOT NULL constrained is added.
- On the second pass, modules are being tested while being loaded.
- Any module adding a website will have the not null error until this module is loaded.
There was a problem hiding this comment.
I got it. You are right.
It seems to be an odoo framework issue. Is there a way to fix it in odoo core?
| ('website_id', '=', False), | ||
| ('customize_show', '=', True), | ||
| ]).mapped('model_data_id') | ||
|
|
There was a problem hiding this comment.
Don't add too much empty lines...
62eabef to
ca86676
Compare
|
New updates: yelizariev@3a24f70 |
ca86676 to
3b9f640
Compare
|
And update about |
|
I suppose this is the last question here: I made an issue in MQT OCA/maintainer-quality-tools#545 |
|
But that's because you haven't put the |
|
Yeah, but if you want this merged before discussing about the change, you have to fix it. If not, we have to wait until the discussion is solved. |
New field "auto" in "website.theme.asset" to distinguish assets created from theme and ones created in xml. It's needed, for example, for non-module themes (like Demo theme) be handled in _convert_assets (before this update such themes were skipped) [REF] field multi_theme_generated is replaced with origin_view_id [IMP] apply default theme after installation [IMP] reload themes on installing new modules with customize_show [CI] Website always have Multi-Theme now. Also, increase default timeout (10 sec) to 60 sec, because it may take more time now
3b9f640 to
73d6a72
Compare
|
I'd prefer to merge it now. |
|
Thanks @yelizariev ! 👏 👏 |



The PR allows making customization independently per website
