From 10d277f001fed2aae9fa57c260262ee4fc0db82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 3 Feb 2022 23:13:28 +0100 Subject: [PATCH] Add optional column on tree view issue10989 review374321002 --- CHANGELOG | 1 + doc/ref/models/models.rst | 2 +- doc/topics/views/index.rst | 5 ++ trytond/ir/__init__.py | 1 + trytond/ir/ui/tree.rnc | 1 + trytond/ir/ui/tree.rng | 11 +++ trytond/ir/ui/view.py | 63 +++++++++++++++ trytond/ir/ui/view.xml | 33 ++++++++ trytond/ir/view/attachment_list.xml | 10 +-- trytond/ir/view/cron_list.xml | 4 +- trytond/ir/view/icon_view_list.xml | 4 +- trytond/ir/view/lang_list.xml | 4 +- trytond/ir/view/model_data_list.xml | 4 +- trytond/ir/view/model_field_list.xml | 10 +-- trytond/ir/view/model_list.xml | 4 +- .../view/module_config_wizard_item_list.xml | 2 +- trytond/ir/view/module_list.xml | 2 +- trytond/ir/view/note_list.xml | 6 +- trytond/ir/view/translation_list.xml | 8 +- trytond/ir/view/ui_view_list.xml | 8 +- .../ir/view/ui_view_tree_optional_form.xml | 14 ++++ .../ir/view/ui_view_tree_optional_list.xml | 9 +++ trytond/model/modelview.py | 81 ++++++++++++------- trytond/res/ir.xml | 4 + 24 files changed, 230 insertions(+), 61 deletions(-) create mode 100644 trytond/ir/view/ui_view_tree_optional_form.xml create mode 100644 trytond/ir/view/ui_view_tree_optional_list.xml diff --git a/CHANGELOG b/CHANGELOG index 9d8f786b51..1fbfba68b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add optional column on tree view * Use dictionary as domain on Reference field * Include model, field and column in import data error message * Support limit and offset to ModelSQL count search and search_count diff --git a/doc/ref/models/models.rst b/doc/ref/models/models.rst index 8fb123d5db..d7e73ade67 100644 --- a/doc/ref/models/models.rst +++ b/doc/ref/models/models.rst @@ -188,7 +188,7 @@ Class methods: :attr:`~trytond.transaction.Transaction.context` when calling this method. -.. classmethod:: ModelView.parse_view(tree, type[, field_children[, level[, view_depends]]]) +.. classmethod:: ModelView.parse_view(tree, type[, view_id[, field_children[, level[, view_depends]]]]) Return the sanitized XML and the corresponding fields definition. diff --git a/doc/topics/views/index.rst b/doc/topics/views/index.rst index 3ce81f04f0..93272c1c0c 100644 --- a/doc/topics/views/index.rst +++ b/doc/topics/views/index.rst @@ -619,6 +619,11 @@ field that will be evaluated as boolean with the context of the view to display or not the column. + * ``optional``: A boolean to define if the column is hidden or not. + Defining the optional attribute allows each user to show/hide the column. + The attribute value is used as default when the user has no custom + setting for it. + * ``visual``: A :ref:`PYSON statement ` that will be evaluated as string ``muted``, ``success``, ``warning`` or ``danger`` with the context of the record to provide a visual context to the field. diff --git a/trytond/ir/__init__.py b/trytond/ir/__init__.py index 81f63ee85e..f199233e38 100644 --- a/trytond/ir/__init__.py +++ b/trytond/ir/__init__.py @@ -29,6 +29,7 @@ def register(): ui.view.View, ui.view.ShowViewStart, ui.view.ViewTreeWidth, + ui.view.ViewTreeOptional, ui.view.ViewTreeState, ui.view.ViewSearch, ui.icon.Icon, diff --git a/trytond/ir/ui/tree.rnc b/trytond/ir/ui/tree.rnc index 9e52bfce41..e4bcab0baa 100644 --- a/trytond/ir/ui/tree.rnc +++ b/trytond/ir/ui/tree.rnc @@ -46,6 +46,7 @@ attlist.field &= }? attlist.field &= [ a:defaultValue = "0" ] attribute tree_invisible { text }? +attlist.field &= attribute optional { "0" | "1" }? attlist.field &= [ a:defaultValue = "0" ] attribute expand { xsd:integer }? attlist.field &= attribute visual { text }? diff --git a/trytond/ir/ui/tree.rng b/trytond/ir/ui/tree.rng index adf69b98d9..e87e002e38 100644 --- a/trytond/ir/ui/tree.rng +++ b/trytond/ir/ui/tree.rng @@ -152,6 +152,17 @@ + + + + optional + + 0 + 1 + + + + diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 5f7719bbdf..81a6952474 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -405,6 +405,69 @@ class ViewTreeWidth(ModelSQL, ModelView): cls.create(to_create) +class ViewTreeOptional(ModelSQL, ModelView): + "View Tree Optional" + __name__ = 'ir.ui.view_tree_optional' + view_id = fields.Many2One( + 'ir.ui.view', "View ID", required=True, ondelete='CASCADE', + domain=[ + ('type', '=', 'tree'), + ]) + user = fields.Many2One( + 'res.user', "User", required=True, ondelete='CASCADE') + field = fields.Char("Field", required=True) + value = fields.Boolean("Value") + + @classmethod + def __setup__(cls): + super().__setup__() + cls.__rpc__.update({ + 'set_optional': RPC(readonly=False), + }) + + @classmethod + def __register__(cls, module_name): + super().__register__(module_name) + table_h = cls.__table_handler__(module_name) + table_h.index_action(['view_id', 'user'], 'add') + + @classmethod + def create(cls, vlist): + records = super().create(vlist) + ModelView._fields_view_get_cache.clear() + return records + + @classmethod + def write(cls, *args): + super().write(*args) + ModelView._fields_view_get_cache.clear() + + @classmethod + def delete(cls, records): + ModelView._fields_view_get_cache.clear() + super().delete(records) + + @classmethod + def set_optional(cls, view_id, fields): + "Store optional field that must be displayed" + user = Transaction().user + records = cls.search([ + ('view_id', '=', view_id), + ('user', '=', user), + ]) + cls.delete(records) + to_create = [] + for field, value in fields.items(): + to_create.append({ + 'view_id': view_id, + 'user': user, + 'field': field, + 'value': bool(value), + }) + if to_create: + cls.create(to_create) + + class ViewTreeState(ModelSQL, ModelView): 'View Tree State' __name__ = 'ir.ui.view_tree_state' diff --git a/trytond/ir/ui/view.xml b/trytond/ir/ui/view.xml index e0396fe5ee..71547142fe 100644 --- a/trytond/ir/ui/view.xml +++ b/trytond/ir/ui/view.xml @@ -80,6 +80,39 @@ this repository contains the full copyright notices and license terms. --> sequence="50" id="menu_view_tree_width"/> + + ir.ui.view_tree_optional + form + ui_view_tree_optional_form + + + + ir.ui.view_tree_optional + tree + ui_view_tree_optional_list + + + + View Tree Optional + ir.ui.view_tree_optional + + + + + + + + + + + + + + ir.ui.view_tree_state form diff --git a/trytond/ir/view/attachment_list.xml b/trytond/ir/view/attachment_list.xml index cf5b577b80..f72dc3b362 100644 --- a/trytond/ir/view/attachment_list.xml +++ b/trytond/ir/view/attachment_list.xml @@ -4,12 +4,12 @@ this repository contains the full copyright notices and license terms. --> - - - - + + + - + diff --git a/trytond/ir/view/cron_list.xml b/trytond/ir/view/cron_list.xml index 0bcb907ff7..69a8e5565f 100644 --- a/trytond/ir/view/cron_list.xml +++ b/trytond/ir/view/cron_list.xml @@ -3,8 +3,8 @@ this repository contains the full copyright notices and license terms. --> - - + +