changeset 6e1719d56c06 in modules/sale:4.4
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=6e1719d56c06
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 254551e8aeb0 -r 6e1719d56c06 sale.py
--- a/sale.py Thu Jul 05 12:00:41 2018 +0200
+++ b/sale.py Wed Feb 06 22:51:18 2019 +0100
@@ -922,6 +922,7 @@
def process(cls, sales):
done = []
process = []
+ cls.__lock(sales)
for sale in sales:
if sale.state not in ('confirmed', 'processing', 'done'):
continue
@@ -942,6 +943,25 @@
if done:
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)
+
class SaleIgnoredInvoice(ModelSQL):
'Sale - Ignored Invoice'