From 68b7ee2d4e606ed545167e32dfae957d2349ec6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 21 Jan 2023 18:47:49 +0100 Subject: [PATCH] Lock journal period when automatically creating one This avoids uniqueness constraint error in case of concurrent creation. Closes #10747 (grafted from c4674b8f6fbda574212a4b1768afd86f4651f7c7) --HG-- branch : 6.0 --- modules/account/move.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/account/move.py b/modules/account/move.py index 63b4f6fdf9..2a8b4cdd51 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -1131,6 +1131,10 @@ class Line(ModelSQL, ModelView): and if there is no journal - period, create it ''' JournalPeriod = Pool().get('account.journal.period') + transaction = Transaction() + database = transaction.database + connection = transaction.connection + journal_periods = JournalPeriod.search([ ('journal', '=', journal.id), ('period', '=', period.id), @@ -1142,6 +1146,7 @@ class Line(ModelSQL, ModelView): gettext('account.msg_modify_line_closed_journal_period', journal_period=journal_period.rec_name)) else: + database.lock(connection, JournalPeriod._table) JournalPeriod.create([{ 'journal': journal.id, 'period': period.id,