details: https://code.tryton.org/tryton/commit/903b285731c3
branch: default
user: Cédric Krier <[email protected]>
date: Fri Jul 31 12:39:47 2026 +0200
description:
Group records written with the same values when saved
diffstat:
trytond/trytond/model/modelstorage.py | 4 +++-
trytond/trytond/tests/test_modelstorage.py | 17 +++++++++++++++++
2 files changed, 20 insertions(+), 1 deletions(-)
diffs (48 lines):
diff -r 2c1a865682ab -r 903b285731c3 trytond/trytond/model/modelstorage.py
--- a/trytond/trytond/model/modelstorage.py Thu Aug 06 10:52:54 2026 +0200
+++ b/trytond/trytond/model/modelstorage.py Fri Jul 31 12:39:47 2026 +0200
@@ -2278,7 +2278,9 @@
record._ids.append(record.id)
if to_write:
cls.write(*sum(
- (([r], save_values[r]) for r in to_write), ()))
+ ((list(gr), v) for v, gr in groupby(
+ to_write, lambda r: save_values[r])),
+ ()))
except Exception:
for record in chain(to_create, to_write):
record._values = values.get(record)
diff -r 2c1a865682ab -r 903b285731c3 trytond/trytond/tests/test_modelstorage.py
--- a/trytond/trytond/tests/test_modelstorage.py Thu Aug 06 10:52:54
2026 +0200
+++ b/trytond/trytond/tests/test_modelstorage.py Fri Jul 31 12:39:47
2026 +0200
@@ -2,6 +2,7 @@
# repository contains the full copyright notices and license terms.
import warnings
+from unittest.mock import patch
from trytond.model import BrowseList, EvalEnvironment
from trytond.model.exceptions import (
@@ -125,6 +126,22 @@
self.assertNotEqual(foo._context, bar._context)
@with_transaction()
+ def test_save_same_write_values(self):
+ "Test save with same write values"
+ pool = Pool()
+ ModelStorage = pool.get('test.modelstorage')
+
+ records = ModelStorage.create([{}, {}])
+
+ with patch.object(
+ ModelStorage, 'write', wraps=ModelStorage.write) as mock:
+ for record in records:
+ record.name = "test"
+ ModelStorage.save(records)
+
+ mock.assert_called_once_with(records, {'name': "test"})
+
+ @with_transaction()
def test_fail_saving_mixed_context1(self):
'Test fail saving with mixed context '
pool = Pool()