diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index 927a17817d..3e5a7455b4 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -357,7 +357,7 @@ class Screen(SignalEvent): self.current_record not in self.current_record.group): self.current_record = None fields = self.current_view.get_fields() - if (self.current_record + if (self.current_record and self.current_view.editable and not self.current_record.validate(fields)): self.screen_container.set(self.current_view.widget) self.set_cursor() @@ -439,22 +439,11 @@ class Screen(SignalEvent): self.views.append(view) return view - def editable_get(self): - if hasattr(self.current_view, 'widget_tree'): - if hasattr(self.current_view.widget_tree, 'editable'): - return self.current_view.widget_tree.editable - return False - def new(self, default=True): previous_view = self.current_view if self.current_view.view_type == 'calendar': selected_date = self.current_view.get_selected_date() - if (self.current_view - and ((self.current_view.view_type == 'tree' - and not (hasattr(self.current_view.widget_tree, - 'editable') - and self.current_view.widget_tree.editable)) - or self.current_view.view_type in ('graph', 'calendar'))): + if self.current_view and not self.current_view.editable: self.switch_view('form') if self.current_view.view_type != 'form': return None diff --git a/tryton/gui/window/view_form/view/calendar_.py b/tryton/gui/window/view_form/view/calendar_.py index fce0e097ef..ec56ba2b60 100644 --- a/tryton/gui/window/view_form/view/calendar_.py +++ b/tryton/gui/window/view_form/view/calendar_.py @@ -22,6 +22,7 @@ class ViewCalendar(ParserView): super(ViewCalendar, self).__init__(screen, widget, children, buttons, notebooks, cursor_widget, children_field) self.view_type = 'calendar' + self.editable = False def __getitem__(self, name): return None diff --git a/tryton/gui/window/view_form/view/form.py b/tryton/gui/window/view_form/view/form.py index 6ec6275914..a333b45642 100644 --- a/tryton/gui/window/view_form/view/form.py +++ b/tryton/gui/window/view_form/view/form.py @@ -18,6 +18,7 @@ class ViewForm(ParserView): super(ViewForm, self).__init__(screen, widget, children, state_widgets, notebooks, cursor_widget, children_field) self.view_type = 'form' + self.editable = True for widget in self.state_widgets: if isinstance(widget, gtk.Button): diff --git a/tryton/gui/window/view_form/view/form_gtk/one2many.py b/tryton/gui/window/view_form/view/form_gtk/one2many.py index bb60fd7bb6..36e29a7921 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -328,8 +328,7 @@ class One2Many(WidgetInterface): if sequence: self.screen.group.set_sequence(field=sequence) - if (self.screen.current_view.view_type == 'form') \ - or self.screen.editable_get(): + if self.screen.current_view.editable: self.screen.new() self.screen.current_view.widget.set_sensitive(True) update_sequence() @@ -448,7 +447,7 @@ class One2Many(WidgetInterface): if id(self.screen.group) != id(new_group): self.screen.group = new_group if (self.screen.current_view.view_type == 'tree') \ - and self.screen.editable_get(): + and self.screen.current_view.editable: self.screen.current_record = None readonly = False domain = [] diff --git a/tryton/gui/window/view_form/view/graph.py b/tryton/gui/window/view_form/view/graph.py index 74978dd2e8..c91ff679aa 100644 --- a/tryton/gui/window/view_form/view/graph.py +++ b/tryton/gui/window/view_form/view/graph.py @@ -11,6 +11,7 @@ class ViewGraph(ParserView): state_widgets, notebooks, cursor_widget, children_field) self.view_type = 'graph' self.widgets = children + self.editable = False def __getitem__(self, name): return None diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 1dc85bbc0d..d927d700dc 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -333,6 +333,10 @@ class ViewList(ParserView): def modified(self): return False + @property + def editable(self): + return bool(getattr(self.widget_tree, 'editable', False)) + def get_fields(self): return [col.name for col in self.widget_tree.get_columns() if col.name] @@ -447,8 +451,7 @@ class ViewList(ParserView): return def on_paste(self): - if (not hasattr(self.widget_tree, 'editable') - or not self.widget_tree.editable): + if not self.editable: return def unquote(value): @@ -756,9 +759,7 @@ class ViewList(ParserView): else: self.screen.current_record = None - if (hasattr(self.widget_tree, 'editable') - and self.widget_tree.editable - and previous_record): + if self.editable and previous_record: def go_previous(): self.screen.current_record = previous_record self.set_cursor() @@ -787,8 +788,7 @@ class ViewList(ParserView): self.update_children() def set_value(self): - if hasattr(self.widget_tree, 'editable') \ - and self.widget_tree.editable: + if self.editable: self.widget_tree.set_value() def reset(self): @@ -811,8 +811,7 @@ class ViewList(ParserView): if self.store: self.widget_tree.set_model(self.store) self.widget_tree.queue_draw() - if hasattr(self.widget_tree, 'editable') \ - and self.widget_tree.editable: + if self.editable: self.set_state() self.update_children()