From cc48eb8532d253ce58e7a3e8b528f714088e7975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 3 Oct 2011 09:45:21 +0200 Subject: [PATCH] New search widget - Change select on fields into Boolean - Change format of search_value on ir.action.act_window review95002 --- CHANGELOG | 2 ++ doc/ref/models/fields.rst | 4 +--- doc/topics/modules/index.rst | 14 +++++------ doc/topics/views/index.rst | 13 ++++------- trytond/ir/action.py | 39 ++++++++++++++----------------- trytond/ir/action.xml | 22 ++++++++--------- trytond/ir/attachment.xml | 4 ++-- trytond/ir/cron.xml | 10 ++++---- trytond/ir/export.xml | 4 ++-- trytond/ir/lang.xml | 8 +++---- trytond/ir/model.xml | 38 +++++++++++++++--------------- trytond/ir/module/module.xml | 16 ++++++------- trytond/ir/property.xml | 8 +++---- trytond/ir/rule.xml | 16 ++++++------- trytond/ir/sequence.xml | 10 ++++---- trytond/ir/translation.xml | 16 ++++++------- trytond/ir/trigger.xml | 14 +++++------ trytond/ir/ui/form.rnc | 2 -- trytond/ir/ui/form.rng | 11 --------- trytond/ir/ui/icon.xml | 6 ++--- trytond/ir/ui/menu.xml | 2 +- trytond/ir/ui/tree.rnc | 2 -- trytond/ir/ui/tree.rng | 11 --------- trytond/ir/ui/view.xml | 16 ++++++------- trytond/model/fields/binary.py | 2 +- trytond/model/fields/boolean.py | 2 +- trytond/model/fields/char.py | 2 +- trytond/model/fields/field.py | 8 +++---- trytond/model/fields/float.py | 2 +- trytond/model/fields/many2many.py | 4 ++-- trytond/model/fields/many2one.py | 2 +- trytond/model/fields/one2many.py | 4 ++-- trytond/model/fields/reference.py | 2 +- trytond/model/fields/selection.py | 2 +- trytond/model/model.py | 7 ++++++ trytond/model/modelview.py | 2 +- trytond/res/group.xml | 2 +- trytond/res/request.xml | 18 +++++++------- trytond/res/user.xml | 12 +++++----- trytond/workflow/workflow.xml | 30 ++++++++++++------------ 40 files changed, 179 insertions(+), 210 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4adfe95aa2..3ac4167e22 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Change select on fields into Boolean +* Change format of search_value on ir.action.act_window * Manage relation field access * Support size format in context for Binary fields * Use buffer for Binary fields diff --git a/doc/ref/models/fields.rst b/doc/ref/models/fields.rst index 52e8d036ee..ba7015dd45 100644 --- a/doc/ref/models/fields.rst +++ b/doc/ref/models/fields.rst @@ -77,9 +77,7 @@ If true, the field can be used as condition for a custom default value. .. attribute:: Field.select -When equal to ``1``, the field appears in the search box in list view and the -search will be optimized. When equal to ``2`` the field appears in the -*Advanced Search* in the search box. +If true, the content of the field will be indexed. ``on_change`` ------------- diff --git a/doc/topics/modules/index.rst b/doc/topics/modules/index.rst index 0a0e1786a4..c72a2ebd4c 100644 --- a/doc/topics/modules/index.rst +++ b/doc/topics/modules/index.rst @@ -123,13 +123,13 @@ The following snippet gives a first idea of what an xml file looks: - - - - - - - + + + + + + + ]]> diff --git a/doc/topics/views/index.rst b/doc/topics/views/index.rst index 2947b5a3f6..b1946d2de1 100644 --- a/doc/topics/views/index.rst +++ b/doc/topics/views/index.rst @@ -464,11 +464,6 @@ field * ``widget``: The widget that must be used instead of the default one. - * ``select``: A number between 0 and 2. If set to 1, the field will be used - as main search criteria; if set to 2, the field will be used as second - search criteria; if set to 0, the field will not be used as search - criteria. - * ``tree_invisible``: Boolean to display or not the column. * ``icon``: The name of the field that contains the name of the icon to @@ -487,10 +482,10 @@ Example :: - - - - + + + + diff --git a/trytond/ir/action.py b/trytond/ir/action.py index e4d0c8cd08..c74ac5c157 100644 --- a/trytond/ir/action.py +++ b/trytond/ir/action.py @@ -521,15 +521,23 @@ class ActionActWindow(ModelSQL, ModelView): ('check_views', 'invalid_views'), ('check_domain', 'invalid_domain'), ('check_context', 'invalid_context'), - ('check_search_value', 'invalid_search_value'), ] self._error_messages.update({ 'invalid_views': 'Invalid views!', - 'invalid_domain': 'Invalid domain!', + 'invalid_domain': 'Invalid domain or search criteria!', 'invalid_context': 'Invalid context!', - 'invalid_search_value': 'Invalid search criteria!', }) + def init(self, module_name): + cursor = Transaction().cursor + super(ActionActWindow, self).init(module_name) + + # Migration from 2.0: new search_value format + cursor.execute('UPDATE "%s" ' + 'SET search_value = %%s ' + 'WHERE search_value = %%s' % self._table, + ('[]', '{}')) + def default_type(self): return 'ir.action.act_window' @@ -549,7 +557,7 @@ class ActionActWindow(ModelSQL, ModelView): return True def default_search_value(self): - return '{}' + return '[]' def check_views(self, ids): "Check views" @@ -571,11 +579,13 @@ class ActionActWindow(ModelSQL, ModelView): return True def check_domain(self, ids): - "Check domain" + "Check domain and search_value" for action in self.browse(ids): - if action.domain: + for domain in (action.domain, action.search_value): + if not domain: + continue try: - value = safe_eval(action.domain, CONTEXT) + value = safe_eval(domain, CONTEXT) except Exception: return False if isinstance(value, PYSON): @@ -610,21 +620,6 @@ class ActionActWindow(ModelSQL, ModelView): return False return True - def check_search_value(self, ids): - "Check search_value" - for action in self.browse(ids): - if action.search_value: - try: - value = safe_eval(action.search_value, CONTEXT) - except Exception: - return False - if isinstance(value, PYSON): - if not value.types() == set([dict]): - return False - elif not isinstance(value, dict): - return False - return True - def get_views(self, ids, name): res = {} for act in self.browse(ids): diff --git a/trytond/ir/action.xml b/trytond/ir/action.xml index 9a5318655b..f92f0bd018 100644 --- a/trytond/ir/action.xml +++ b/trytond/ir/action.xml @@ -46,8 +46,8 @@ this repository contains the full copyright notices and license terms. --> - - + + ]]> @@ -133,10 +133,10 @@ this repository contains the full copyright notices and license terms. --> - + - - + + ]]> @@ -231,8 +231,8 @@ this repository contains the full copyright notices and license terms. --> - - + + ]]> @@ -306,9 +306,9 @@ this repository contains the full copyright notices and license terms. --> - + - + ]]> @@ -377,9 +377,9 @@ this repository contains the full copyright notices and license terms. --> - + - + ]]> diff --git a/trytond/ir/attachment.xml b/trytond/ir/attachment.xml index 8386dff210..7c6d601704 100644 --- a/trytond/ir/attachment.xml +++ b/trytond/ir/attachment.xml @@ -44,8 +44,8 @@ this repository contains the full copyright notices and license terms. --> - - + + diff --git a/trytond/ir/cron.xml b/trytond/ir/cron.xml index cef16614b4..4faa070458 100644 --- a/trytond/ir/cron.xml +++ b/trytond/ir/cron.xml @@ -13,13 +13,13 @@ this repository contains the full copyright notices and license terms. --> - - - + + + - - + + ]]> diff --git a/trytond/ir/export.xml b/trytond/ir/export.xml index 89452fb2ee..857dbe627c 100644 --- a/trytond/ir/export.xml +++ b/trytond/ir/export.xml @@ -24,8 +24,8 @@ this repository contains the full copyright notices and license terms. --> - - + + ]]> diff --git a/trytond/ir/lang.xml b/trytond/ir/lang.xml index 0c035c5656..bfaee5d6e6 100644 --- a/trytond/ir/lang.xml +++ b/trytond/ir/lang.xml @@ -79,11 +79,11 @@ this repository contains the full copyright notices and license terms. --> - - + + - - + + ]]> diff --git a/trytond/ir/model.xml b/trytond/ir/model.xml index 63396de1ec..cb2f1c0fef 100644 --- a/trytond/ir/model.xml +++ b/trytond/ir/model.xml @@ -43,10 +43,10 @@ this repository contains the full copyright notices and license terms. --> - - - - + + + + ]]> @@ -99,11 +99,11 @@ this repository contains the full copyright notices and license terms. --> - - - - - + + + + + ]]> @@ -133,12 +133,12 @@ this repository contains the full copyright notices and license terms. --> - - - - - - + + + + + + ]]> @@ -193,10 +193,10 @@ this repository contains the full copyright notices and license terms. --> - - - - + + + + ]]> diff --git a/trytond/ir/module/module.xml b/trytond/ir/module/module.xml index 31bafdb263..7e17a6a40c 100644 --- a/trytond/ir/module/module.xml +++ b/trytond/ir/module/module.xml @@ -61,13 +61,13 @@ this repository contains the full copyright notices and license terms. --> - - - + + + - - - + + + ]]> @@ -99,9 +99,9 @@ this repository contains the full copyright notices and license terms. --> - + - + ]]> diff --git a/trytond/ir/property.xml b/trytond/ir/property.xml index a2a4c8ec70..00bed26996 100644 --- a/trytond/ir/property.xml +++ b/trytond/ir/property.xml @@ -27,10 +27,10 @@ this repository contains the full copyright notices and license terms. --> - - - - + + + + ]]> diff --git a/trytond/ir/rule.xml b/trytond/ir/rule.xml index 710fcff8cc..ce8deae52c 100644 --- a/trytond/ir/rule.xml +++ b/trytond/ir/rule.xml @@ -42,14 +42,14 @@ this repository contains the full copyright notices and license terms. --> - - - - - - - - + + + + + + + + ]]> diff --git a/trytond/ir/sequence.xml b/trytond/ir/sequence.xml index 49e4064035..03ae1132b6 100644 --- a/trytond/ir/sequence.xml +++ b/trytond/ir/sequence.xml @@ -59,10 +59,10 @@ this repository contains the full copyright notices and license terms. --> - - - - + + + + ]]> @@ -147,7 +147,7 @@ this repository contains the full copyright notices and license terms. --> - + ]]> diff --git a/trytond/ir/translation.xml b/trytond/ir/translation.xml index 3fe2cfeda3..a83b8a5bcb 100644 --- a/trytond/ir/translation.xml +++ b/trytond/ir/translation.xml @@ -37,14 +37,14 @@ this repository contains the full copyright notices and license terms. --> - - - - - - - - + + + + + + + + ]]> diff --git a/trytond/ir/trigger.xml b/trytond/ir/trigger.xml index 1c42a6a704..b6e697904d 100644 --- a/trytond/ir/trigger.xml +++ b/trytond/ir/trigger.xml @@ -45,13 +45,13 @@ this repository contains the full copyright notices and license terms. --> - - - - - - - + + + + + + + ]]> diff --git a/trytond/ir/ui/form.rnc b/trytond/ir/ui/form.rnc index b3dd367605..b47702a002 100644 --- a/trytond/ir/ui/form.rnc +++ b/trytond/ir/ui/form.rnc @@ -114,8 +114,6 @@ attlist.field &= attribute sum { text }? attlist.field &= attribute key { text }? attlist.field &= attribute domain { text }? attlist.field &= attribute color { text }? -attlist.field &= - [ a:defaultValue = "0" ] attribute select { "0" | "1" | "2" }? attlist.field &= [ a:defaultValue = "left_to_right" ] attribute orientation { "left_to_right" diff --git a/trytond/ir/ui/form.rng b/trytond/ir/ui/form.rng index 2b6ca350db..725df61dd9 100644 --- a/trytond/ir/ui/form.rng +++ b/trytond/ir/ui/form.rng @@ -424,17 +424,6 @@ - - - - - 0 - 1 - 2 - - - - diff --git a/trytond/ir/ui/icon.xml b/trytond/ir/ui/icon.xml index 636292f8e4..a94dde2668 100644 --- a/trytond/ir/ui/icon.xml +++ b/trytond/ir/ui/icon.xml @@ -9,9 +9,9 @@ - - - + + + ]]> diff --git a/trytond/ir/ui/menu.xml b/trytond/ir/ui/menu.xml index c9db9ab078..acb7a9dec1 100644 --- a/trytond/ir/ui/menu.xml +++ b/trytond/ir/ui/menu.xml @@ -24,7 +24,7 @@ this repository contains the full copyright notices and license terms. --> - + ]]> diff --git a/trytond/ir/ui/tree.rnc b/trytond/ir/ui/tree.rnc index 7d46342c83..e1b966d46e 100644 --- a/trytond/ir/ui/tree.rnc +++ b/trytond/ir/ui/tree.rnc @@ -37,8 +37,6 @@ attlist.field &= | "sip" | "progressbar" }? -attlist.field &= - [ a:defaultValue = "0" ] attribute select { "0" | "1" | "2" }? attlist.field &= [ a:defaultValue = "0" ] attribute tree_invisible { "0" | "1" }? attlist.field &= attribute icon { text }? diff --git a/trytond/ir/ui/tree.rng b/trytond/ir/ui/tree.rng index 1dfdd1874d..d7d726e251 100644 --- a/trytond/ir/ui/tree.rng +++ b/trytond/ir/ui/tree.rng @@ -105,17 +105,6 @@ - - - - - 0 - 1 - 2 - - - - diff --git a/trytond/ir/ui/view.xml b/trytond/ir/ui/view.xml index 3bbad13893..39c75a49f6 100644 --- a/trytond/ir/ui/view.xml +++ b/trytond/ir/ui/view.xml @@ -33,12 +33,12 @@ this repository contains the full copyright notices and license terms. --> - - - - - - + + + + + + ]]> @@ -88,8 +88,8 @@ this repository contains the full copyright notices and license terms. --> - - + + ]]> diff --git a/trytond/model/fields/binary.py b/trytond/model/fields/binary.py index 0224fea1b0..bd06c04230 100644 --- a/trytond/model/fields/binary.py +++ b/trytond/model/fields/binary.py @@ -12,7 +12,7 @@ class Binary(Field): _type = 'binary' def __init__(self, string='', help='', required=False, readonly=False, - domain=None, states=None, change_default=False, select=0, + domain=None, states=None, change_default=False, select=False, on_change=None, on_change_with=None, depends=None, filename=None, order_field=None, context=None, loading='lazy'): if filename is not None: diff --git a/trytond/model/fields/boolean.py b/trytond/model/fields/boolean.py index 046e2af6af..e7bbd4dc86 100644 --- a/trytond/model/fields/boolean.py +++ b/trytond/model/fields/boolean.py @@ -11,7 +11,7 @@ class Boolean(Field): _type = 'boolean' def __init__(self, string='', help='', readonly=False, domain=None, - states=None, change_default=False, select=0, on_change=None, + states=None, change_default=False, select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager'): super(Boolean, self).__init__(string=string, help=help, required=False, diff --git a/trytond/model/fields/char.py b/trytond/model/fields/char.py index 09bba2b2ba..593d61b5a2 100644 --- a/trytond/model/fields/char.py +++ b/trytond/model/fields/char.py @@ -16,7 +16,7 @@ class Char(Field): def __init__(self, string='', size=None, help='', required=False, readonly=False, domain=None, states=None, change_default=False, - translate=False, select=0, on_change=None, on_change_with=None, + translate=False, select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager', autocomplete=None): ''' diff --git a/trytond/model/fields/field.py b/trytond/model/fields/field.py index 72f3af404d..f24e65295d 100644 --- a/trytond/model/fields/field.py +++ b/trytond/model/fields/field.py @@ -54,7 +54,7 @@ class Field(object): _type = None def __init__(self, string='', help='', required=False, readonly=False, - domain=None, states=None, change_default=False, select=0, + domain=None, states=None, change_default=False, select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager'): ''' @@ -70,9 +70,7 @@ class Field(object): dynamically the attributes of the field. :param change_default: A boolean. If ``True`` the field can be used as condition for a custom default value. - :param select: An integer. When equal to ``1``, the field appears in the - search box in list view and the search will be optimized. When equal to - ``2`` the field appears in the *Advanced Search* in the search box. + :param select: An boolean. When True search will be optimized. :param on_change: A list of values. If set, the client will call the method ``on_change_`` when the user changes the field value. It then passes this list of values as arguments to the @@ -98,7 +96,7 @@ class Field(object): self.__states = None self.states = states or {} self.change_default = change_default - self.select = select + self.select = bool(select) self.__on_change = None self.on_change = on_change self.__on_change_with = None diff --git a/trytond/model/fields/float.py b/trytond/model/fields/float.py index d411c3f5dc..4e88658a21 100644 --- a/trytond/model/fields/float.py +++ b/trytond/model/fields/float.py @@ -23,7 +23,7 @@ class Float(Field): def __init__(self, string='', digits=None, help='', required=False, readonly=False, domain=None, states=None, change_default=False, - select=0, on_change=None, on_change_with=None, depends=None, + select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager'): ''' :param digits: a list of two integers defining the total diff --git a/trytond/model/fields/many2many.py b/trytond/model/fields/many2many.py index 64fc0182b9..3fa259449a 100644 --- a/trytond/model/fields/many2many.py +++ b/trytond/model/fields/many2many.py @@ -14,7 +14,7 @@ class Many2Many(Field): def __init__(self, relation_name, origin, target, string='', order=None, datetime_field=None, help='', required=False, readonly=False, - domain=None, states=None, change_default=False, select=0, + domain=None, states=None, change_default=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='lazy'): ''' @@ -35,7 +35,7 @@ class Many2Many(Field): depends = [datetime_field] super(Many2Many, self).__init__(string=string, help=help, required=required, readonly=readonly, domain=domain, - states=states, change_default=change_default, select=select, + states=states, change_default=change_default, on_change=on_change, on_change_with=on_change_with, depends=depends, order_field=order_field, context=context, loading=loading) diff --git a/trytond/model/fields/many2one.py b/trytond/model/fields/many2one.py index f544399944..48f391da06 100644 --- a/trytond/model/fields/many2one.py +++ b/trytond/model/fields/many2one.py @@ -13,7 +13,7 @@ class Many2One(Field): def __init__(self, model_name, string='', left=None, right=None, ondelete='SET NULL', datetime_field=None, help='', required=False, readonly=False, domain=None, states=None, change_default=False, - select=0, on_change=None, on_change_with=None, depends=None, + select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager'): ''' :param model_name: The name of the target model. diff --git a/trytond/model/fields/one2many.py b/trytond/model/fields/one2many.py index 9f4a72b33b..5ae64c629e 100644 --- a/trytond/model/fields/one2many.py +++ b/trytond/model/fields/one2many.py @@ -19,7 +19,7 @@ class One2Many(Field): def __init__(self, model_name, field, string='', add_remove=None, order=None, datetime_field=None, help='', required=False, readonly=False, domain=None, states=None, change_default=False, - select=0, on_change=None, on_change_with=None, depends=None, + on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='lazy'): ''' :param model_name: The name of the target model. @@ -39,7 +39,7 @@ class One2Many(Field): depends = [datetime_field] super(One2Many, self).__init__(string=string, help=help, required=required, readonly=readonly, domain=domain, - states=states, change_default=change_default, select=select, + states=states, change_default=change_default, on_change=on_change, on_change_with=on_change_with, depends=depends, order_field=order_field, context=context, loading=loading) diff --git a/trytond/model/fields/reference.py b/trytond/model/fields/reference.py index 6dafb0457f..de2895ee2d 100644 --- a/trytond/model/fields/reference.py +++ b/trytond/model/fields/reference.py @@ -14,7 +14,7 @@ class Reference(Field): def __init__(self, string='', selection=None, help='', required=False, readonly=False, domain=None, states=None, change_default=False, - select=0, on_change=None, on_change_with=None, depends=None, + select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager'): ''' :param selection: A list or a function name that returns a list. diff --git a/trytond/model/fields/selection.py b/trytond/model/fields/selection.py index 66ff9f3722..7d804d2262 100644 --- a/trytond/model/fields/selection.py +++ b/trytond/model/fields/selection.py @@ -12,7 +12,7 @@ class Selection(Field): def __init__(self, selection, string='', sort=True, translate=True, help='', required=False, readonly=False, domain=None, states=None, - change_default=False, select=0, on_change=None, + change_default=False, select=False, on_change=None, on_change_with=None, depends=None, order_field=None, context=None, loading='eager'): ''' diff --git a/trytond/model/model.py b/trytond/model/model.py index ce492fd402..03953dae4a 100644 --- a/trytond/model/model.py +++ b/trytond/model/model.py @@ -539,6 +539,13 @@ class Model(WarningErrorMixin, URLMixin): (fields.Function, fields.One2Many)) \ and not self._columns[field].order_field: res[field]['sortable'] = False + if ((isinstance(self._columns[field], fields.Function) + and not self._columns[field].searcher) + or self._columns[field]._type in ('binary', 'many2many', + 'one2many', 'sha')): + res[field]['searchable'] = False + else: + res[field]['searchable'] = True if Transaction().context.get('language'): # translate the field label diff --git a/trytond/model/modelview.py b/trytond/model/modelview.py index 48e7ee0860..e280dabf50 100644 --- a/trytond/model/modelview.py +++ b/trytond/model/modelview.py @@ -372,7 +372,7 @@ class ModelView(Model): fields_def.setdefault(depend, {'name': depend}) if ('active' in self._columns) or ('active' in self._inherit_fields): - fields_def.setdefault('active', {'name': 'active', 'select': "2"}) + fields_def.setdefault('active', {'name': 'active'}) arch = etree.tostring(tree, encoding='utf-8', pretty_print=False) fields2 = self.fields_get(fields_def.keys()) diff --git a/trytond/res/group.xml b/trytond/res/group.xml index 7994141574..b015873a79 100644 --- a/trytond/res/group.xml +++ b/trytond/res/group.xml @@ -35,7 +35,7 @@ this repository contains the full copyright notices and license terms. --> - + ]]> diff --git a/trytond/res/request.xml b/trytond/res/request.xml index 5c07884f83..40b0e8a5ed 100644 --- a/trytond/res/request.xml +++ b/trytond/res/request.xml @@ -10,15 +10,15 @@ this repository contains the full copyright notices and license terms. --> - - - - - + + + + + - - + + ]]> @@ -119,8 +119,8 @@ this repository contains the full copyright notices and license terms. --> - - + + ]]> diff --git a/trytond/res/user.xml b/trytond/res/user.xml index 0a00750c16..17f421c92b 100644 --- a/trytond/res/user.xml +++ b/trytond/res/user.xml @@ -97,10 +97,10 @@ this repository contains the full copyright notices and license terms. --> - - + + - + ]]> @@ -190,9 +190,9 @@ this repository contains the full copyright notices and license terms. --> - - - + + + ]]> diff --git a/trytond/workflow/workflow.xml b/trytond/workflow/workflow.xml index 2fc046f836..954c19ca44 100644 --- a/trytond/workflow/workflow.xml +++ b/trytond/workflow/workflow.xml @@ -33,8 +33,8 @@ this repository contains the full copyright notices and license terms. --> - - + + ]]> @@ -163,8 +163,8 @@ this repository contains the full copyright notices and license terms. --> - - + + @@ -240,8 +240,8 @@ this repository contains the full copyright notices and license terms. --> - - + + @@ -315,11 +315,11 @@ this repository contains the full copyright notices and license terms. --> - - - - - + + + + + ]]> @@ -371,10 +371,10 @@ this repository contains the full copyright notices and license terms. --> - - - - + + + + ]]>