diff --git a/web_company_color/i18n/es.po b/web_company_color/i18n/es.po new file mode 100644 index 000000000..8e95c26bb --- /dev/null +++ b/web_company_color/i18n/es.po @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_company_color +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-03-02 15:55+0000\n" +"PO-Revision-Date: 2022-03-02 16:56+0100\n" +"Last-Translator: claudiagn \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Poedit 2.3\n" + +#. module: web_company_color +#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form +msgid "" +"\n" +" In order for the changes to take effect, please " +"refresh\n" +" the page." +msgstr "" +"\n" +" Para que los cambios surtan efecto, actualice\n" +" la página." + +#. module: web_company_color +#: model:ir.model,name:web_company_color.model_res_company +msgid "Companies" +msgstr "Compañías" + +#. module: web_company_color +#: model:ir.model.fields,field_description:web_company_color.field_res_company__company_colors +msgid "Company Colors" +msgstr "Colores de la compañía" + +#. module: web_company_color +#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form +msgid "Company Styles" +msgstr "Estilos de compañía" + +#. module: web_company_color +#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form +msgid "Compute colors from logo" +msgstr "Calcular colores a partir del logo" + +#. module: web_company_color +#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_bg +msgid "Navbar Background Color" +msgstr "Color de fondo de la barra de navegación" + +#. module: web_company_color +#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_bg_hover +msgid "Navbar Background Color Hover" +msgstr "Desplazamiento del color de fondo de la barra de navegación" + +#. module: web_company_color +#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form +msgid "Navbar Colors" +msgstr "Colores de la barra de navegación" + +#. module: web_company_color +#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_text +msgid "Navbar Text Color" +msgstr "Color de texto de la barra de navegación" + +#. module: web_company_color +#: model:ir.model,name:web_company_color.model_ir_qweb +msgid "Qweb" +msgstr "Qweb" diff --git a/web_company_color/i18n/web_company_color.pot b/web_company_color/i18n/web_company_color.pot index 826901d2d..d589c468b 100644 --- a/web_company_color/i18n/web_company_color.pot +++ b/web_company_color/i18n/web_company_color.pot @@ -6,6 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-03-02 15:55+0000\n" +"PO-Revision-Date: 2022-03-02 15:55+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -36,6 +38,11 @@ msgstr "" msgid "Company Styles" msgstr "" +#. module: web_company_color +#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form +msgid "Compute colors from logo" +msgstr "" + #. module: web_company_color #: model:ir.model.fields,field_description:web_company_color.field_ir_qweb__display_name #: model:ir.model.fields,field_description:web_company_color.field_res_company__display_name diff --git a/web_company_color/models/res_company.py b/web_company_color/models/res_company.py index a458b25f1..6f07d12ed 100644 --- a/web_company_color/models/res_company.py +++ b/web_company_color/models/res_company.py @@ -74,34 +74,36 @@ class ResCompany(models.Model): "color_navbar_bg_hover", "color_navbar_text", ) - if "logo" in values: - if values["logo"]: - _r, _g, _b = image_to_rgb(convert_to_image(values["logo"])) - # Make color 10% darker - _h, _l, _s = rgb_to_hls(_r, _g, _b) - _l = max(0, _l - 0.1) - _rd, _gd, _bd = hls_to_rgb(_h, _l, _s) - # Calc. optimal text color (b/w) - # Grayscale human vision perception (Rec. 709 values) - _a = 1 - (0.2126 * _r + 0.7152 * _g + 0.0722 * _b) - values.update( - { - "color_navbar_bg": n_rgb_to_hex(_r, _g, _b), - "color_navbar_bg_hover": n_rgb_to_hex(_rd, _gd, _bd), - "color_navbar_text": "#000" if _a < 0.5 else "#fff", - } - ) - else: - values.update(self.default_get(fields_to_check)) - result = super().write(values) - if any([field in values for field in fields_to_check]): self.scss_create_or_update_attachment() else: result = super().write(values) return result + def button_compute_color(self): + self.ensure_one() + values = self.default_get( + ["color_navbar_bg", "color_navbar_bg_hover", "color_navbar_text"] + ) + if self.logo: + _r, _g, _b = image_to_rgb(convert_to_image(self.logo)) + # Make color 10% darker + _h, _l, _s = rgb_to_hls(_r, _g, _b) + _l = max(0, _l - 0.1) + _rd, _gd, _bd = hls_to_rgb(_h, _l, _s) + # Calc. optimal text color (b/w) + # Grayscale human vision perception (Rec. 709 values) + _a = 1 - (0.2126 * _r + 0.7152 * _g + 0.0722 * _b) + values.update( + { + "color_navbar_bg": n_rgb_to_hex(_r, _g, _b), + "color_navbar_bg_hover": n_rgb_to_hex(_rd, _gd, _bd), + "color_navbar_text": "#000" if _a < 0.5 else "#fff", + } + ) + self.write(values) + def _scss_get_sanitized_values(self): self.ensure_one() # Clone company_color as dictionary to avoid ORM operations diff --git a/web_company_color/readme/CONTRIBUTORS.rst b/web_company_color/readme/CONTRIBUTORS.rst index 71df9a76b..b64318c8f 100644 --- a/web_company_color/readme/CONTRIBUTORS.rst +++ b/web_company_color/readme/CONTRIBUTORS.rst @@ -1,5 +1,9 @@ * Jordi Ballester Alomar (ForgeFlow) * Lois Rilo (ForgeFlow) * Simone Orsi -* Jairo Llopis * Iván Antón +* `Tecnativa `_: + + * Jairo Llopis + * Alexandre Díaz + * Carlos Roca diff --git a/web_company_color/tests/test_res_company.py b/web_company_color/tests/test_res_company.py index 8234b6f44..06a780cb1 100644 --- a/web_company_color/tests/test_res_company.py +++ b/web_company_color/tests/test_res_company.py @@ -25,6 +25,7 @@ class TestResCompany(common.TransactionCase): ) self._test_scss_attachment() company_id.sudo().write({"logo": self.IMG_GREEN}) + company_id.button_compute_color() self.assertEqual( company_id.color_navbar_bg, "#00ff00", "Invalid Navbar Background Color" ) @@ -36,6 +37,7 @@ class TestResCompany(common.TransactionCase): def test_change_logo(self): company_id = self.env["res.company"].search([], limit=1) company_id.sudo().write({"logo": self.IMG_GREEN}) + company_id.button_compute_color() self.assertEqual( company_id.color_navbar_bg, "#00ff00", "Invalid Navbar Background Color" ) diff --git a/web_company_color/view/res_company.xml b/web_company_color/view/res_company.xml index 3f3bcc49f..25265f90c 100644 --- a/web_company_color/view/res_company.xml +++ b/web_company_color/view/res_company.xml @@ -19,6 +19,12 @@ +