From 51a815b31de1af87f3c31e6b4856d2bcc388d41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 20 Feb 2014 23:35:58 +0100 Subject: [PATCH] Fix action button sensibility Allow to run action if no record is selected. issue3685 review3611003 --- tryton/action/main.py | 2 +- tryton/gui/window/form.py | 9 ++++++--- tryton/gui/window/view_form/screen/screen.py | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tryton/action/main.py b/tryton/action/main.py index 108572f6b4..9179a945e6 100644 --- a/tryton/action/main.py +++ b/tryton/action/main.py @@ -95,7 +95,7 @@ class Action(object): action.setdefault('pyson_domain', '[]') ctx = { 'active_model': data.get('res_model'), - 'active_id': data.get('id', False), + 'active_id': data.get('id'), 'active_ids': data.get('ids', []), } ctx.update(rpc.CONTEXT) diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index a39e169577..5d43657c2f 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -415,7 +415,7 @@ class Form(SignalEvent, TabContent): name = '_' if signal_data[0]: name = str(signal_data[0]) - for button_id in ('print', 'action', 'relate', 'email', 'open', 'save', + for button_id in ('print', 'relate', 'email', 'open', 'save', 'attach'): button = self.buttons[button_id] can_be_sensitive = getattr(button, '_can_be_sensitive', True) @@ -465,7 +465,8 @@ class Form(SignalEvent, TabContent): action = action.copy() if not self.screen.save_current(): return - record_id = self.screen.id_get() + record_id = (self.screen.current_record.id + if self.screen.current_record else None) record_ids = [r.id for r in self.screen.selected_records] action = Action.evaluate(action, atype, self.screen.current_record) data = { @@ -507,7 +508,9 @@ class Form(SignalEvent, TabContent): tbutton.connect('toggled', self.action_popup) self.tooltips.set_tip(tbutton, tooltip) self.buttons[special_action] = tbutton - tbutton._can_be_sensitive = bool(tbutton._menu.get_children()) + if action_type != 'action': + tbutton._can_be_sensitive = bool( + tbutton._menu.get_children()) else: tbutton = gtk.SeparatorToolItem() gtktoolbar.insert(tbutton, -1) diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 85fc1bb4c9..3708f49c0d 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -858,6 +858,9 @@ class Screen(SignalEvent): states = record.expr_eval(button.attrs.get('states', {})) return not (states.get('invisible') or states.get('readonly')) + if not self.selected_records: + return [] + buttons = self.current_view.get_buttons() for record in self.selected_records: