diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index 3e556b8287..db86822fc7 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -2278,7 +2278,9 @@ class ModelStorage(Model): 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 --git a/trytond/trytond/tests/test_modelstorage.py b/trytond/trytond/tests/test_modelstorage.py index c6a1eb79f9..5df78aae64 100644 --- a/trytond/trytond/tests/test_modelstorage.py +++ b/trytond/trytond/tests/test_modelstorage.py @@ -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 ( @@ -124,6 +125,22 @@ class ModelStorageTestCase(TestCase): 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 '