-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[14.0] [ADD] Module web_responsive_company_color #2861
base: 14.0
Are you sure you want to change the base?
Conversation
9a82e07
to
7badcf2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review
if not uninstall: | ||
datas = base64.b64encode(record._scss_generate_content().encode("utf-8")) | ||
else: | ||
datas = base64.b64encode(record._scss_generate_content(uninstall).encode("utf-8")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: in the method _scss_generate_content
uninstall is already handled. We could just call the method without checking if uninstall is falsy
if not uninstall: | |
datas = base64.b64encode(record._scss_generate_content().encode("utf-8")) | |
else: | |
datas = base64.b64encode(record._scss_generate_content(uninstall).encode("utf-8")) | |
datas = base64.b64encode(record._scss_generate_content(uninstall).encode("utf-8"))``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented suggested change
def _get_scss_template_uninstall(self): | ||
return super()._get_scss_template() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: What does this method do?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method tries to remove web elements introduced by the module for customization during uninstall, so that when this module is uninstalled customization related to its web elements are removed.
During uninstall, web_company_color module tries to return self._get_scss_template() % self._scss_get_sanitized_values() using _scss_generate_content() method.
Whenever, self._get_scss_template() is called, it provides the entire scss_template including web element which has be removed for the module for which uninstalled is performed.
In order to avoid including web elements of module which are about to uninstall, calling a scss_template_uninstall method in the module which tries uninstall. As only parent of scss_template is called in this method, I am able to remove customized web elements of module for which uninstall is performed.
If not, though module is uninstalled, customization of web element introduced by the uninstalled module remains.
be1290d
to
dd1436e
Compare
custom_attachment.sudo().write(values) | ||
else: | ||
values.update({"type": "binary", "mimetype": "text/scss"}) | ||
IrAttachmentObj.sudo().create(values) | ||
values.update({"type": "binary", "mimetype": "text/scss"}) | ||
IrAttachmentObj.sudo().create(values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: we lost the indentation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is restored
dd1436e
to
c488ead
Compare
return self.SCSS_TEMPLATE % self._scss_get_sanitized_values() | ||
if uninstall: | ||
return ( | ||
self._get_scss_template_uninstall() % self._scss_get_sanitized_values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: _get_scss_template_uninstall
does not exist in this module and it would raise an error on the module uninstall.
suggestion: instead of creating a new method you could add a parameter inside the context in the "uninstall_hook", check for that inside this method and call super()
instead of self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to uninstall web_company_color but did not see any error. However, you are right, it might raise error without _get_scss_template_uninstall function here
I also tried to update context from uninstall_hook and use super() instead of self, but uninstall fails saying super has no attribute
It is trying to call the parent of web_company_color instead of the parent which needs to be called for module which is uninstalled
# One need to reinstall web_responsive_company_color module | ||
# to see customization takes effect when new elements added | ||
# to _get_scss_template | ||
def _get_scss_template(self): | ||
return ( | ||
super()._get_scss_template() | ||
+ """ | ||
.o_menu_apps .dropdown-menu { | ||
background: url('/web_responsive/static/img/home-menu-bg-overlay.svg'), | ||
linear-gradient( | ||
to bottom, | ||
%(color_navbar_bg)s, | ||
desaturate(lighten(%(color_navbar_bg)s, 20%%), 15) | ||
); | ||
} | ||
""" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: In my opinion you should:
- Delete
_get_scss_template_uninstall
, could only cause issues, not needed - Add a context variable in the uninstall hook (something like:
uninstall_scss=True
) before executingscss_create_or_update_attachment
- Check inside
_get_scss_template
if there is the variable in the context:- If yes: just return
super
, you only need the basic scss template - If not: call
super
and add your customizations
- If yes: just return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for misunderstanding the suggestion. Thank your for detailed response. Updated solution as suggested
78af2a9
to
afc3d92
Compare
|
||
|
||
def uninstall_hook(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {"uninstall": True}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: just uninstall
could lead to conflicts / misunderstandings, could we make it more specific? Something like uninstall_scss
would be enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to uninstall_scss in the context
def _scss_generate_content(self, uninstall=False): | ||
self.ensure_one() | ||
# ir.attachment need files with content to work | ||
if not self.company_colors: | ||
return "// No Web Company Color SCSS Content\n" | ||
return self.SCSS_TEMPLATE % self._scss_get_sanitized_values() | ||
if uninstall: | ||
return ( | ||
self._get_scss_template_uninstall() % self._scss_get_sanitized_values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: now that _get_scss_template_uninstall
doesn't actually exist, you could remove it (also from the method's parameters) and check for the context variable instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed to push the changes for scss_generate as testing was handled in different repo.
Not checking context variable inside _scss_generate_content and it is checked only inside _get_scss_template
def scss_create_or_update_attachment(self, uninstall=False): | ||
IrAttachmentObj = self.env["ir.attachment"] | ||
for record in self: | ||
datas = base64.b64encode(record._scss_generate_content().encode("utf-8")) | ||
datas = base64.b64encode( | ||
record._scss_generate_content(uninstall).encode("utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: you can get uninstall
directly from the context inside the _scss_generate_content
method, these changes could be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed these changes
c4f326b
to
3499f08
Compare
3499f08
to
fab4cf0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code and functional review, LGTM
fab4cf0
to
4969e25
Compare
4969e25
to
f729039
Compare
Module web_responsive_company_color is introduced for customizing web elements that are part of web_responsive that needs customization
Limitations: If new web elements are included in module, one needs to reinstall web_responsive_company_color for customization to take effect