diff --git a/CHANGELOG b/CHANGELOG index 8d280ff01d..e47e1283e9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add sort and translate options to Reference field * Do not create empty translations * Replace dsn by params to connect to postgresql * Simplify cron diff --git a/doc/ref/models/fields.rst b/doc/ref/models/fields.rst index 3c85a054e2..5d6cf200bd 100644 --- a/doc/ref/models/fields.rst +++ b/doc/ref/models/fields.rst @@ -446,7 +446,7 @@ A binary field. It will be represented in Python by a ``bytes`` instance. Selection --------- -.. class:: Selection(selection, string[, sort[, selection_change_with[, translate[, \**options]]]) +.. class:: Selection(selection, string[, sort[, selection_change_with[, translate[, \**options]]]]) A string field with limited values to choice. @@ -505,7 +505,7 @@ Instance methods: Reference --------- -.. class:: Reference(string[, selection[, selection_change_with[, search_order[, search_context[, \**options]]]]) +.. class:: Reference(string[, selection[, sort[, selection_change_with[, translated[,search_order[, search_context[, \**options]]]]]]]) A field that refers to a record of a model. It will be represented in Python by a ``str`` instance like this:: @@ -520,10 +520,18 @@ But a ``tuple`` can be used to search or set value. Same as :attr:`Selection.selection` but only for model name. +.. attribute:: Reference.sort + + Same as :attr:`Selection.sort`. + .. attribute:: Reference.selection_change_with Same as :attr:`Selection.selection_change_with`. +.. attribute:: Reference.translate_selection + + Same as :attr:`Selection.translate_selection`. + .. attribute:: Reference.datetime_field Same as :attr:`Many2One.datetime_field` diff --git a/trytond/ir/ui/menu.py b/trytond/ir/ui/menu.py index df3120bec7..f5dbb4a203 100644 --- a/trytond/ir/ui/menu.py +++ b/trytond/ir/ui/menu.py @@ -99,7 +99,7 @@ class UIMenu(DeactivableMixin, sequence_ordered(), tree(separator=' / '), ('ir.action.act_window', 'ir.action.act_window'), ('ir.action.wizard', 'ir.action.wizard'), ('ir.action.url', 'ir.action.url'), - ]), 'get_action', setter='set_action') + ], translate=False), 'get_action', setter='set_action') action_keywords = fields.One2Many('ir.action.keyword', 'model', 'Action Keywords') favorite = fields.Function(fields.Boolean('Favorite'), 'get_favorite') diff --git a/trytond/model/fields/reference.py b/trytond/model/fields/reference.py index 3b71d453ff..114ea40db4 100644 --- a/trytond/model/fields/reference.py +++ b/trytond/model/fields/reference.py @@ -21,15 +21,17 @@ class Reference(SelectionMixin, Field): _type = 'reference' _sql_type = 'VARCHAR' - def __init__(self, string='', selection=None, selection_change_with=None, - search_order=None, search_context=None, help='', required=False, - readonly=False, domain=None, states=None, select=False, - on_change=None, on_change_with=None, depends=None, context=None, - loading='lazy', datetime_field=None): + def __init__(self, string='', selection=None, sort=True, + selection_change_with=None, translate=True, search_order=None, + search_context=None, help='', required=False, readonly=False, + domain=None, states=None, select=False, on_change=None, + on_change_with=None, depends=None, context=None, loading='lazy', + datetime_field=None): ''' :param selection: A list or a function name that returns a list. The list must be a list of tuples. First member is an internal name of model and the second is the user name of model. + :param sort: A boolean to sort or not the selections. :param datetime_field: The name of the field that contains the datetime value to read the target records. :param search_order: The order to use when searching for a record @@ -52,6 +54,8 @@ class Reference(SelectionMixin, Field): 'use the depends decorator', DeprecationWarning, stacklevel=2) self.selection_change_with |= set(selection_change_with) + self.sort = sort + self.translate_selection = translate self.__search_order = None self.search_order = search_order self.__search_context = None diff --git a/trytond/model/fields/selection.py b/trytond/model/fields/selection.py index d359615422..6a3a8d7826 100644 --- a/trytond/model/fields/selection.py +++ b/trytond/model/fields/selection.py @@ -13,6 +13,7 @@ from ...rpc import RPC class SelectionMixin(Field): translate_selection = True + sort = True def translated(self, name=None): "Return a descriptor for the translated value of the field" @@ -39,6 +40,7 @@ class SelectionMixin(Field): selection = self.selection definition['selection'] = selection definition['selection_change_with'] = list(self.selection_change_with) + definition['sort'] = self.sort return definition def definition_translations(self, model, language): @@ -117,11 +119,6 @@ class Selection(SelectionMixin, Field): else: return [column] - def definition(self, model, language): - definition = super().definition(model, language) - definition['sort'] = self.sort - return definition - class TranslatedSelection(object): 'A descriptor for translated value of Selection field'