62 lines
2.3 KiB
Diff
62 lines
2.3 KiB
Diff
Index: trytond/trytond/model/modelsql.py
|
|
===================================================================
|
|
|
|
--- a/trytond/trytond/model/modelsql.py
|
|
+++ b/trytond/trytond/model/modelsql.py
|
|
@@ -331,7 +331,7 @@
|
|
for id_ in ids:
|
|
column_datetime = Coalesce(history.write_date, history.create_date)
|
|
hwhere = (column_datetime <= datetime) & (history.id == id_)
|
|
- horder = column_datetime.desc
|
|
+ horder = (column_datetime.desc, Column(history, '__id').desc)
|
|
cursor.execute(*history.select(*hcolumns,
|
|
where=hwhere, order_by=horder, limit=1))
|
|
values = cursor.fetchone()
|
|
|
|
Index: trytond/trytond/tests/test_history.py
|
|
===================================================================
|
|
|
|
--- a/trytond/trytond/tests/test_history.py
|
|
+++ b/trytond/trytond/tests/test_history.py
|
|
@@ -184,6 +184,39 @@
|
|
History.restore_history([history_id], datetime.datetime.min)
|
|
self.assertRaises(UserError, History.read, [history_id])
|
|
|
|
+ @unittest.skipIf(CONFIG['db_type'] in ('sqlite', 'mysql'),
|
|
+ 'now() is not the start of the transaction')
|
|
+ def test0045restore_history_same_timestamp(self):
|
|
+ 'Test restore history with same timestamp'
|
|
+ History = POOL.get('test.history')
|
|
+
|
|
+ with Transaction().start(DB_NAME, USER,
|
|
+ context=CONTEXT) as transaction:
|
|
+ history = History(value=1)
|
|
+ history.save()
|
|
+ history_id = history.id
|
|
+ first = history.create_date
|
|
+ history.value = 2
|
|
+ history.save()
|
|
+ second = history.create_date
|
|
+
|
|
+ self.assertEqual(first, second)
|
|
+
|
|
+ transaction.cursor.commit()
|
|
+
|
|
+ with Transaction().start(DB_NAME, USER,
|
|
+ context=CONTEXT) as transaction:
|
|
+ history = History(history_id)
|
|
+ history.value = 3
|
|
+ history.save()
|
|
+
|
|
+ transaction.cursor.commit()
|
|
+
|
|
+ with Transaction().start(DB_NAME, USER, context=CONTEXT):
|
|
+ History.restore_history([history_id], first)
|
|
+ history = History(history_id)
|
|
+ self.assertEqual(history.value, 2)
|
|
+
|
|
def test0050ordered_search(self):
|
|
'Test ordered search of history models'
|
|
History = POOL.get('test.history')
|
|
|