diff --git a/CHANGELOG b/CHANGELOG index 8b86818ba5..e7306c9002 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Manage creatable attribute of view + Version 6.2.0 - 2021-11-01 * Bug fixes (see mercurial logs for details) * Support grouping attribute diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index b7feb90103..e824d4f73a 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -509,7 +509,8 @@ class Screen(SignalEvent): def number_of_views(self): return len(self.views) + len(self.view_to_load) - def switch_view(self, view_type=None, view_id=None, display=True): + def switch_view( + self, view_type=None, view_id=None, creatable=None, display=True): if view_id is not None: view_id = int(view_id) if self.current_view: @@ -528,13 +529,15 @@ class Screen(SignalEvent): def found(): if not self.current_view: return False - elif not view_type and view_id is None: - return False - elif view_id is not None: - return self.current_view.view_id == view_id - else: - return self.current_view.view_type == view_type - while not found(): + result = True + if view_type is not None: + result &= self.current_view.view_type == view_type + if view_id is not None: + result &= self.current_view.view_id == view_id + if creatable is not None: + result &= self.current_view.creatable == creatable + return result + for i in range(len(self.views) + len(self.view_to_load)): if len(self.view_to_load): self.load_view_to_load() self.__current_view = len(self.views) - 1 @@ -546,9 +549,7 @@ class Screen(SignalEvent): else: self.__current_view = ((self.__current_view + 1) % len(self.views)) - if not view_type and view_id is None: - break - if view_type and not view_id and not len(self.view_to_load): + if found(): break self.screen_container.set(self.current_view.widget) if display: @@ -616,9 +617,9 @@ class Screen(SignalEvent): 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 not self.current_view.editable: - self.switch_view('form', display=False) - if self.current_view.view_type != 'form': + if self.current_view and not self.current_view.creatable: + self.switch_view(creatable=True) + if not self.current_view.creatable: return None if self.current_record: group = self.current_record.group diff --git a/tryton/gui/window/view_form/view/__init__.py b/tryton/gui/window/view_form/view/__init__.py index 33896a5b94..0e31577f18 100644 --- a/tryton/gui/window/view_form/view/__init__.py +++ b/tryton/gui/window/view_form/view/__init__.py @@ -16,6 +16,7 @@ class View(object): view_id = None modified = None editable = None + creatable = None children_field = None scroll = None xml_parser = None diff --git a/tryton/gui/window/view_form/view/calendar_.py b/tryton/gui/window/view_form/view/calendar_.py index 3240d247ba..8978ffd07a 100644 --- a/tryton/gui/window/view_form/view/calendar_.py +++ b/tryton/gui/window/view_form/view/calendar_.py @@ -62,6 +62,7 @@ class CalendarXMLViewParser(XMLViewParser): class ViewCalendar(View): editable = False + creatable = False view_type = 'calendar' xml_parser = CalendarXMLViewParser diff --git a/tryton/gui/window/view_form/view/form.py b/tryton/gui/window/view_form/view/form.py index 4efbb6fb70..1483c5b46a 100644 --- a/tryton/gui/window/view_form/view/form.py +++ b/tryton/gui/window/view_form/view/form.py @@ -461,6 +461,8 @@ class ViewForm(View): super().__init__(view_id, screen, xml) + self.creatable = bool(int(self.attributes.get('creatable', 1))) + def get_fields(self): return list(self.widgets.keys()) 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 becbfb3182..2ef15add0e 100644 --- a/tryton/gui/window/view_form/view/form_gtk/one2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/one2many.py @@ -371,7 +371,7 @@ class One2Many(Widget): self.screen.group.set_sequence( field=sequence, position=self.screen.new_position) - if self.screen.current_view.editable: + if self.screen.current_view.creatable: self.screen.new() self.screen.current_view.widget.set_sensitive(True) update_sequence() diff --git a/tryton/gui/window/view_form/view/graph.py b/tryton/gui/window/view_form/view/graph.py index e9b7654b9a..b83f0fe754 100644 --- a/tryton/gui/window/view_form/view/graph.py +++ b/tryton/gui/window/view_form/view/graph.py @@ -67,6 +67,7 @@ class GraphXMLViewParser(XMLViewParser): class ViewGraph(View): view_type = 'graph' editable = False + creatable = False xml_parser = GraphXMLViewParser def __init__(self, view_id, screen, xml): diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 760a9fd1fc..cf89f7e0b1 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -439,6 +439,7 @@ class ViewTree(View): self.sum_box = Gtk.HBox() self.treeview = None self._editable = bool(int(xml.getAttribute('editable') or 0)) + self._creatable = bool(int(xml.getAttribute('creatable') or 1)) if self._editable: self.treeview = EditableTreeView(self) grid_lines = Gtk.TreeViewGridLines.BOTH @@ -630,6 +631,10 @@ class ViewTree(View): def editable(self): return self._editable and not self.screen.readonly + @property + def creatable(self): + return self.editable and self._creatable + def get_fields(self, visible_only=False): return [col.name for col in self.treeview.get_columns() if col.name and (not visible_only or col.get_visible())] diff --git a/tryton/gui/window/view_form/view/list_form.py b/tryton/gui/window/view_form/view/list_form.py index 1bc8fe92d5..504b955c00 100644 --- a/tryton/gui/window/view_form/view/list_form.py +++ b/tryton/gui/window/view_form/view/list_form.py @@ -59,6 +59,7 @@ class ViewListForm(View): def __init__(self, view_id, screen, xml): super().__init__(view_id, screen, xml) + self.creatable = bool(int(self.attributes.get('creatable', 1))) self.view_type = 'list-form' self.form_xml = xml diff --git a/tryton/gui/window/view_form/view/list_gtk/editabletree.py b/tryton/gui/window/view_form/view/list_gtk/editabletree.py index 228d9db9fb..0d72f9f8f3 100644 --- a/tryton/gui/window/view_form/view/list_gtk/editabletree.py +++ b/tryton/gui/window/view_form/view/list_gtk/editabletree.py @@ -118,7 +118,7 @@ class EditableTreeView(TreeView): model = self.get_model() limit = (self.view.screen.size_limit is not None and (len(model) >= self.view.screen.size_limit >= 0)) - if not access['create'] or limit: + if not self.view.creatable or not access['create'] or limit: return if self.view.screen.new_position == 0: method = model.prepend