From 60f167bcfe296a197daa7cd05088b0c2721166ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 5 Apr 2018 19:18:52 +0200 Subject: [PATCH] Add index method to order field set calls issue7090 review46301002 --- CHANGELOG | 1 + doc/ref/models/models.rst | 4 ++++ trytond/model/modelsql.py | 6 ++++-- trytond/model/modelstorage.py | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6904a0a36e..faeeb8e2d8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add index method to order field set calls * Add deactivable mixin * Ensure active field is present on tree view * Manage depends xml attribute on field tag diff --git a/doc/ref/models/models.rst b/doc/ref/models/models.rst index d5e99bb4ba..ce24e41fb5 100644 --- a/doc/ref/models/models.rst +++ b/doc/ref/models/models.rst @@ -268,6 +268,10 @@ Class methods: ``on_write`` is set and ``condition`` was false before :meth:`~ModelStorage.write` and true after. +.. classmethod:: ModelStorage.index_set_field(name) + + Return the index sort order of the field set calls. + .. classmethod:: ModelStorage.delete(records) Delete records. diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 3f6e3184cc..ad4292e724 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -642,7 +642,8 @@ class ModelSQL(ModelStorage): Translation.set_ids(name, 'model', Transaction().language, translations.keys(), translations.values()) - for fname, fargs in fields_to_set.iteritems(): + for fname in sorted(fields_to_set, key=cls.index_set_field): + fargs = fields_to_set[fname] field = cls._fields[fname] field.set(cls, fname, *fargs) @@ -1015,7 +1016,8 @@ class ModelSQL(ModelStorage): cls._update_mptt(field_names, [ids] * len(field_names), values) all_field_names |= set(field_names) - for fname, fargs in fields_to_set.iteritems(): + for fname in sorted(fields_to_set, key=cls.index_set_field): + fargs = fields_to_set[fname] field = cls._fields[fname] field.set(cls, fname, *fargs) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 04b2e75923..573b2b4235 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -214,6 +214,11 @@ class ModelStorage(Model): if triggered: Trigger.trigger_action(triggered, trigger) + @classmethod + def index_set_field(cls, name): + "Returns the index sort order of the field set calls." + return 0 + @classmethod def delete(cls, records): '''