changeset 1e965a04bfa7 in modules/purchase:4.8
details: https://hg.tryton.org/modules/purchase?cmd=changeset;node=1e965a04bfa7
description:
Lock records when processing
issue8012
review60511002
(grafted from fbf01ede212f025da32d4fa8bacc32eac34eaec7)
diffstat:
purchase.py | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diffs (37 lines):
diff -r d0eaeccfac17 -r 1e965a04bfa7 purchase.py
--- a/purchase.py Sat Jan 26 01:12:51 2019 +0100
+++ b/purchase.py Wed Feb 06 22:51:18 2019 +0100
@@ -881,6 +881,7 @@
@ModelView.button
def process(cls, purchases):
process, done = [], []
+ cls.__lock(purchases)
for purchase in purchases:
purchase.create_invoice()
purchase.set_invoice_state()
@@ -902,6 +903,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('purchase.wizard_modify_header')
def modify_header(cls, purchases):
pass