Hide columns containing always the same value

The domain inversion is used on the screen domain combined with the tab domain
to find columns that has always the same value.

issue4552
review10181002
This commit is contained in:
Cédric Krier committed 2015-03-18 11:09:31 +01:00
1 parent 5ff889024f
commit 25050ae683
5 files changed
+49 -9

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Hide columns containing always the same value
* Remove Tabs Position option
* Manage product attribute
* Remove float_time widget
+1 -1
View File
@@ -3,6 +3,6 @@
from common import *
from datetime_strftime import *
from domain_inversion import domain_inversion, eval_domain, localize_domain, \
merge, inverse_leaf, concat, simplify
merge, inverse_leaf, concat, simplify, unique_value
from environment import EvalEnvironment
import timedelta
+19
View File
@@ -193,6 +193,16 @@ def concat(*domains, **kwargs):
return simplify(merge(result))
def unique_value(domain):
"Return if unique, the field and the value"
if (isinstance(domain, list)
and len(domain) == 1
and domain[0][1] == '='):
return True, domain[0][1], domain[0][2]
else:
return False, None, None
def parse(domain):
if is_leaf(domain):
return domain
@@ -481,6 +491,15 @@ def test_concat():
'OR', [['a', '=', 1]], [['b', '=', 2]]]
def test_unique_value():
domain = [['a', '=', 1]]
assert unique_value(domain) == (True, '=', 1)
domain = [['a', '!=', 1]]
assert unique_value(domain)[0] == False
domain = [['a', '=', 1], ['a', '=', 2]]
assert unique_value(domain)[0] == False
def test_evaldomain():
domain = [['x', '>', 5]]
assert eval_domain(domain, {'x': 6})
+3 -5
View File
@@ -6,7 +6,7 @@ import tempfile
import locale
from tryton.common import \
domain_inversion, eval_domain, localize_domain, \
merge, inverse_leaf, concat, simplify, EvalEnvironment
merge, inverse_leaf, concat, simplify, unique_value, EvalEnvironment
import tryton.common as common
import datetime
import decimal
@@ -87,14 +87,12 @@ class Field(object):
elif domain == [('id', '=', None)]:
res = False
else:
if (isinstance(domain, list)
and len(domain) == 1
and domain[0][1] == '='):
unique, leftpart, value = unique_value(domain)
if unique:
# If the inverted domain is so constraint that only one value
# is possible we should use it. But we must also pay attention
# to the fact that the original domain might be a 'OR' domain
# and thus not preventing the modification of fields.
leftpart, _, value = domain[0][:3]
if value is False:
# XXX to remove once server domains are fixed
value = None
+25 -3
View File
@@ -18,6 +18,7 @@ from tryton.common.cellrenderertoggle import CellRendererToggle
from tryton.gui.window import Window
from tryton.common.popup_menu import populate
from tryton.common import RPCExecute, RPCException, node_attributes, Tooltips
from tryton.common import domain_inversion, simplify, unique_value
import tryton.common as common
from . import View
from .list_gtk.editabletree import EditableTreeView, TreeView
@@ -389,9 +390,6 @@ class ViewTree(View):
and not self.children_field
and field.attrs.get('sortable', True)):
column.connect('clicked', self.sort_model)
column.set_visible(not node_attrs.get('tree_invisible', False))
if name == self.screen.exclude_field:
column.set_visible(False)
self.treeview.append_column(column)
@@ -1086,6 +1084,30 @@ class ViewTree(View):
self.set_state()
self.update_sum()
# Set column visibility depending on attributes and domain
domain = []
if self.screen.domain:
domain.append(self.screen.domain)
tab_domain = self.screen.screen_container.get_tab_domain()
if tab_domain:
domain.append(tab_domain)
domain = simplify(domain)
for column in self.treeview.get_columns():
name = column.name
if not name:
continue
widget = self.get_column_widget(column)
if widget.attrs.get('tree_invisible', False):
column.set_visible(False)
elif name == self.screen.exclude_field:
column.set_visible(False)
else:
inv_domain = domain_inversion(domain, name)
if not isinstance(inv_domain, bool):
inv_domain = simplify(inv_domain)
unique, _, _ = unique_value(inv_domain)
column.set_visible(not unique)
def set_state(self):
record = self.screen.current_record
if record: