mirror of https://github.com/OCA/web.git
[FIX] web_company_color: Recalculated color when we do not want
If we change something with base.document.layout wizard, this will launch the colors computing even without changing the logo. This procedure will change the value of the colors if they were set by hand. This change forces the user to press a button to recompute the colors and avoid possible undesired changes. TT34902pull/2157/head
parent
d10acbacef
commit
5f1894bc6a
|
@ -6,21 +6,23 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Odoo Server 13.0\n"
|
"Project-Id-Version: Odoo Server 13.0\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"PO-Revision-Date: 2021-02-17 14:45+0000\n"
|
"POT-Creation-Date: 2022-03-02 15:55+0000\n"
|
||||||
|
"PO-Revision-Date: 2022-03-02 16:56+0100\n"
|
||||||
"Last-Translator: claudiagn <claudia.gargallo@qubiq.es>\n"
|
"Last-Translator: claudiagn <claudia.gargallo@qubiq.es>\n"
|
||||||
"Language-Team: none\n"
|
"Language-Team: none\n"
|
||||||
"Language: es\n"
|
"Language: es\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: \n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
||||||
"X-Generator: Weblate 4.3.2\n"
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
|
||||||
#. module: web_company_color
|
#. module: web_company_color
|
||||||
#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form
|
#: model_terms:ir.ui.view,arch_db:web_company_color.view_company_form
|
||||||
msgid ""
|
msgid ""
|
||||||
"<span class=\"fa fa-info fa-2x\"/>\n"
|
"<span class=\"fa fa-info fa-2x\"/>\n"
|
||||||
" In order for the changes to take effect, please refresh\n"
|
" In order for the changes to take effect, please "
|
||||||
|
"refresh\n"
|
||||||
" the page."
|
" the page."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"<span class = \"fa fa-info fa-2x\" />\n"
|
"<span class = \"fa fa-info fa-2x\" />\n"
|
||||||
|
@ -42,6 +44,11 @@ msgstr "Colores de la compañía"
|
||||||
msgid "Company Styles"
|
msgid "Company Styles"
|
||||||
msgstr "Estilos de compañía"
|
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
|
#. module: web_company_color
|
||||||
#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_bg
|
#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_bg
|
||||||
msgid "Navbar Background Color"
|
msgid "Navbar Background Color"
|
||||||
|
|
|
@ -6,6 +6,8 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Odoo Server 13.0\n"
|
"Project-Id-Version: Odoo Server 13.0\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
|
@ -36,6 +38,11 @@ msgstr ""
|
||||||
msgid "Company Styles"
|
msgid "Company Styles"
|
||||||
msgstr ""
|
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
|
#. module: web_company_color
|
||||||
#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_bg
|
#: model:ir.model.fields,field_description:web_company_color.field_res_company__color_navbar_bg
|
||||||
msgid "Navbar Background Color"
|
msgid "Navbar Background Color"
|
||||||
|
|
|
@ -74,34 +74,36 @@ class ResCompany(models.Model):
|
||||||
"color_navbar_bg_hover",
|
"color_navbar_bg_hover",
|
||||||
"color_navbar_text",
|
"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)
|
result = super().write(values)
|
||||||
|
|
||||||
if any([field in values for field in fields_to_check]):
|
if any([field in values for field in fields_to_check]):
|
||||||
self.scss_create_or_update_attachment()
|
self.scss_create_or_update_attachment()
|
||||||
else:
|
else:
|
||||||
result = super().write(values)
|
result = super().write(values)
|
||||||
return result
|
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):
|
def _scss_get_sanitized_values(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
# Clone company_color as dictionary to avoid ORM operations
|
# Clone company_color as dictionary to avoid ORM operations
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com> (ForgeFlow)
|
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com> (ForgeFlow)
|
||||||
* Lois Rilo <lois.rilo@forgefloww.com> (ForgeFlow)
|
* Lois Rilo <lois.rilo@forgefloww.com> (ForgeFlow)
|
||||||
* Simone Orsi <simone.orsi@camptocamp.com>
|
* Simone Orsi <simone.orsi@camptocamp.com>
|
||||||
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||||
|
|
||||||
|
* Jairo Llopis
|
||||||
|
* Alexandre Díaz
|
||||||
|
* Carlos Roca
|
||||||
|
|
|
@ -25,6 +25,7 @@ class TestResCompany(common.TransactionCase):
|
||||||
)
|
)
|
||||||
self._test_scss_attachment()
|
self._test_scss_attachment()
|
||||||
company_id.sudo().write({"logo": self.IMG_GREEN})
|
company_id.sudo().write({"logo": self.IMG_GREEN})
|
||||||
|
company_id.button_compute_color()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
company_id.color_navbar_bg, "#00ff00", "Invalid Navbar Background Color"
|
company_id.color_navbar_bg, "#00ff00", "Invalid Navbar Background Color"
|
||||||
)
|
)
|
||||||
|
@ -36,6 +37,7 @@ class TestResCompany(common.TransactionCase):
|
||||||
def test_change_logo(self):
|
def test_change_logo(self):
|
||||||
company_id = self.env["res.company"].search([], limit=1)
|
company_id = self.env["res.company"].search([], limit=1)
|
||||||
company_id.sudo().write({"logo": self.IMG_GREEN})
|
company_id.sudo().write({"logo": self.IMG_GREEN})
|
||||||
|
company_id.button_compute_color()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
company_id.color_navbar_bg, "#00ff00", "Invalid Navbar Background Color"
|
company_id.color_navbar_bg, "#00ff00", "Invalid Navbar Background Color"
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
<field name="color_navbar_bg" widget="color" />
|
<field name="color_navbar_bg" widget="color" />
|
||||||
<field name="color_navbar_bg_hover" widget="color" />
|
<field name="color_navbar_bg_hover" widget="color" />
|
||||||
<field name="color_navbar_text" widget="color" />
|
<field name="color_navbar_text" widget="color" />
|
||||||
|
<button
|
||||||
|
class="btn-primary"
|
||||||
|
name="button_compute_color"
|
||||||
|
type="object"
|
||||||
|
string="Compute colors from logo"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
<div class="alert alert-info info_icon" role="alert">
|
<div class="alert alert-info info_icon" role="alert">
|
||||||
<span class="fa fa-info fa-2x" />
|
<span class="fa fa-info fa-2x" />
|
||||||
|
|
Loading…
Reference in New Issue