Group records written with the same values when saved
This commit is contained in:
1 parent
7ef25665ff
commit
2bbf319507
2 files changed
+20
-1
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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 '
|
||||
|
||||
Reference in new issue
Block a user