Skip to content

Commit

Permalink
[14.0][ADD] Module web_responsive_company_color
Browse files Browse the repository at this point in the history
  • Loading branch information
anusriNPS committed Jul 17, 2024
1 parent 64aac3f commit c4f326b
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 9 deletions.
6 changes: 6 additions & 0 deletions setup/web_responsive_company_color/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
13 changes: 4 additions & 9 deletions web_company_color/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ResCompany(models.Model):
_inherit = "res.company"

def _get_scss_template(self):
return """
return """
.o_main_navbar {
background-color: %(color_navbar_bg)s !important;
color: %(color_navbar_text)s !important;
Expand Down Expand Up @@ -201,26 +201,21 @@ def _scss_get_sanitized_values(self):
)
return values

def _scss_generate_content(self, uninstall=False):
def _scss_generate_content(self):
self.ensure_one()
# ir.attachment need files with content to work
if not self.company_colors:
return "// No Web Company Color SCSS Content\n"
if uninstall:
return self._get_scss_template_uninstall() % self._scss_get_sanitized_values()
return self._get_scss_template() % self._scss_get_sanitized_values()

def scss_get_url(self):
self.ensure_one()
return URL_SCSS_GEN_TEMPLATE % self.id

def scss_create_or_update_attachment(self, uninstall=False):
def scss_create_or_update_attachment(self):
IrAttachmentObj = self.env["ir.attachment"]
for record in self:
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().encode("utf-8"))
custom_url = record.scss_get_url()
custom_attachment = IrAttachmentObj.sudo().search(
[("url", "=", custom_url), ("company_id", "=", record.id)]
Expand Down
87 changes: 87 additions & 0 deletions web_responsive_company_color/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
============================
Web Responsive Company Color
============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:95f3f27e763cdc5439f6171ba4f43af70f47d1cac864b762727d1e64dda9cc69
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/14.0/web_responsive_company_color
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_responsive_company_color
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module bridges web_company_color with web_responsive.

With this module, elements introduced or modified by web_responsive can be styled with the same logic as web_company_color.

**Table of contents**

.. contents::
:local:

Usage
=====

Simply install the app. See web_company_color for instructions on how to customize colors.

If new elements are included for customization under scss_template, one needs to reinstall the app to view customized colors.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_responsive_company_color%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Anusri Veerappan Prakasam

Contributors
~~~~~~~~~~~~

* PyTech SRL
* Alessandro Uffreduzzi <[email protected]>
* Anusri Veerappan Prakasam <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_responsive_company_color>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions web_responsive_company_color/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook, uninstall_hook
18 changes: 18 additions & 0 deletions web_responsive_company_color/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Web Responsive Company Color",
"summary": "Styling hooks for web_responsive elements",
"license": "AGPL-3",
"author": "Anusri Veerappan Prakasam, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"category": "Web",
"version": "14.0.1.0.0",
"depends": [
"web_company_color",
"web_responsive",
],
"data": [],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
"installable": True,
"application": False,
}
11 changes: 11 additions & 0 deletions web_responsive_company_color/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import SUPERUSER_ID, api


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["res.company"].search([]).scss_create_or_update_attachment()


def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {"uninstall_scss": True})
env["res.company"].search([]).scss_create_or_update_attachment()
1 change: 1 addition & 0 deletions web_responsive_company_color/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_company
27 changes: 27 additions & 0 deletions web_responsive_company_color/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import models


class ResCompany(models.Model):
_inherit = "res.company"

# 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):
uninstall_scss = self._context.get("uninstall_scss")
if not uninstall_scss:
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)
);
}
"""
)
else:
return super()._get_scss_template()
3 changes: 3 additions & 0 deletions web_responsive_company_color/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* PyTech SRL
* Alessandro Uffreduzzi <[email protected]>
* Anusri Veerappan Prakasam <[email protected]>
3 changes: 3 additions & 0 deletions web_responsive_company_color/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module bridges web_company_color with web_responsive.

With this module, elements introduced or modified by web_responsive can be styled with the same logic as web_company_color.
Empty file.
3 changes: 3 additions & 0 deletions web_responsive_company_color/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Simply install the app. See web_company_color for instructions on how to customize colors.

If new elements are included for customization under scss_template, one needs to reinstall the app to view customized colors.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c4f326b

Please sign in to comment.