changeset b117c30f2292 in modules/sale:4.8
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=b117c30f2292
description:
Lock records when processing
issue8012
review60511002
(grafted from 22b74ed3f637140b6c06c225f14d15d0251f6c0a)
diffstat:
sale.py | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diffs (37 lines):
diff -r 656db55c90c0 -r b117c30f2292 sale.py
--- a/sale.py Sat Jan 26 01:12:51 2019 +0100
+++ b/sale.py Wed Feb 06 22:51:18 2019 +0100
@@ -950,6 +950,7 @@
def process(cls, sales):
done = []
process = []
+ cls.__lock(sales)
for sale in sales:
if sale.state not in ('confirmed', 'processing', 'done'):
continue
@@ -971,6 +972,25 @@
cls.do(done)
@classmethod
+ def __lock(cls, records):
+ from trytond.tools import grouped_slice, reduce_ids
+ from sql import Literal, For
+ transaction = Transaction()
+ database = transaction.database
+ connection = transaction.connection
+ table = cls.__table__()
+
+ if database.has_select_for():
+ for sub_records in grouped_slice(records):
+ where = reduce_ids(table.id, sub_records)
+ query = table.select(
+ Literal(1), where=where, for_=For('UPDATE', nowait=True))
+ with connection.cursor() as cursor:
+ cursor.execute(*query)
+ else:
+ database.lock(connection, cls._table)
+
+ @classmethod
@ModelView.button_action('sale.wizard_modify_header')
def modify_header(cls, sales):
pass