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

[14.0] [ADD] Module web_responsive_company_color #2861

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from

Conversation

anusriNPS
Copy link

@anusriNPS anusriNPS commented Jun 25, 2024

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

@anusriNPS anusriNPS marked this pull request as draft June 25, 2024 06:42
@pedrobaeza pedrobaeza added this to the 14.0 milestone Jun 25, 2024
@anusriNPS anusriNPS force-pushed the 14.0-scss-styling branch 2 times, most recently from 9a82e07 to 7badcf2 Compare June 28, 2024 10:23
@anusriNPS anusriNPS marked this pull request as ready for review July 1, 2024 15:17
Copy link

@PicchiSeba PicchiSeba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Comment on lines 220 to 223
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"))

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

Suggested change
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"))```

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented suggested change

Comment on lines 21 to 22
def _get_scss_template_uninstall(self):
return super()._get_scss_template()

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?.

Copy link
Author

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.

@anusriNPS anusriNPS force-pushed the 14.0-scss-styling branch 2 times, most recently from be1290d to dd1436e Compare July 5, 2024 07:51
Comment on lines 233 to 236
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)

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is restored

return self.SCSS_TEMPLATE % self._scss_get_sanitized_values()
if uninstall:
return (
self._get_scss_template_uninstall() % self._scss_get_sanitized_values()
Copy link

@renda-dev renda-dev Jul 12, 2024

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

Copy link
Author

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
image
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

Comment on lines 7 to 23
# 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)
);
}
"""
)

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 executing scss_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

Copy link
Author

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

@anusriNPS anusriNPS force-pushed the 14.0-scss-styling branch 2 times, most recently from 78af2a9 to afc3d92 Compare July 15, 2024 08:50


def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {"uninstall": True})

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

Copy link
Author

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

Comment on lines 204 to 211
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()

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

Copy link
Author

@anusriNPS anusriNPS Jul 17, 2024

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

Comment on lines 219 to 223
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")

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed these changes

@anusriNPS anusriNPS force-pushed the 14.0-scss-styling branch 2 times, most recently from c4f326b to 3499f08 Compare July 17, 2024 14:06
@anusriNPS anusriNPS requested a review from renda-dev July 17, 2024 14:34
Copy link

@renda-dev renda-dev left a 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

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.

4 participants