From 7c7e825591aeaf3143b84de10faadff191722fc5 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 6 Dec 2016 12:09:46 +0100 Subject: [PATCH] [IMP] base: allow to set an icon on ir.ui.menu Before this commit, the field `web_icon_data` was a computed field that depended on `web_icon` (which either specify a path to an image or an icon). We can now directly set the image binary value on the field. The previous behaviour in which the binary is computed based on the path is kept at the menu creation/edition, but the field is not `compute` anymore. --- odoo/addons/base/ir/ir_ui_menu.py | 28 +++++++++++++------------ odoo/addons/base/ir/ir_ui_menu_view.xml | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/odoo/addons/base/ir/ir_ui_menu.py b/odoo/addons/base/ir/ir_ui_menu.py index f37281e5773..b319f77f909 100644 --- a/odoo/addons/base/ir/ir_ui_menu.py +++ b/odoo/addons/base/ir/ir_ui_menu.py @@ -43,7 +43,7 @@ class IrUiMenu(models.Model): ('ir.actions.server', 'ir.actions.server'), ('ir.actions.client', 'ir.actions.client')]) - web_icon_data = fields.Binary(string='Web Icon Image', compute="_compute_web_icon", store=True, attachment=True) + web_icon_data = fields.Binary(string='Web Icon Image', attachment=True) @api.depends('name', 'parent_id.complete_name') def _compute_complete_name(self): @@ -59,18 +59,6 @@ class IrUiMenu(models.Model): else: return self.name - @api.depends('web_icon') - def _compute_web_icon(self): - """ Returns the image associated to `web_icon`. - `web_icon` can either be: - - an image icon [module, path] - - a built icon [icon_class, icon_color, background_color] - and it only has to call `read_image` if it's an image. - """ - for menu in self: - if menu.web_icon and len(menu.web_icon.split(',')) == 2: - menu.web_icon_data = self.read_image(menu.web_icon) - def read_image(self, path): if not path: return False @@ -157,13 +145,27 @@ class IrUiMenu(models.Model): @api.model def create(self, values): self.clear_caches() + if 'web_icon' in values: + values['web_icon_data'] = self._compute_web_icon_data(values.get('web_icon')) return super(IrUiMenu, self).create(values) @api.multi def write(self, values): self.clear_caches() + if 'web_icon' in values: + values['web_icon_data'] = self._compute_web_icon_data(values.get('web_icon')) return super(IrUiMenu, self).write(values) + def _compute_web_icon_data(self, web_icon): + """ Returns the image associated to `web_icon`. + `web_icon` can either be: + - an image icon [module, path] + - a built icon [icon_class, icon_color, background_color] + and it only has to call `read_image` if it's an image. + """ + if web_icon and len(web_icon.split(',')) == 2: + return self.read_image(web_icon) + @api.multi def unlink(self): # Detach children and promote them to top-level, because it would be unwise to diff --git a/odoo/addons/base/ir/ir_ui_menu_view.xml b/odoo/addons/base/ir/ir_ui_menu_view.xml index 1d6075085cf..8a42b511e66 100644 --- a/odoo/addons/base/ir/ir_ui_menu_view.xml +++ b/odoo/addons/base/ir/ir_ui_menu_view.xml @@ -16,6 +16,7 @@ +