Update lock_stock_move pathc adapting it to the core changes

This commit is contained in:
Bernat Brunet 2020-01-20 16:49:28 +01:00
parent da4645a3bf
commit cb1409e125
1 changed files with 78 additions and 0 deletions

78
lock_stock_move.diff Normal file
View File

@ -0,0 +1,78 @@
diff -r c1860f118efd move.py
--- a/trytond/trytond/modules/stock/move.py Wed Nov 07 12:14:26 2018 +0100
+++ b/trytond/trytond/modules/stock/move.py Wed Nov 07 12:18:14 2018 +0100
@@ -748,6 +748,10 @@ class Move(Workflow, ModelSQL, ModelView):
return to_pick
return to_pick
+ @staticmethod
+ def lock_stock_move():
+ return True
+
@classmethod
def assign_try(cls, moves, with_childs=True, grouping=('product',)):
'''
@@ -780,34 +784,35 @@ class Move(Workflow, ModelSQL, ModelView):
companies = {m.company for m in moves}
stock_date_end = Date.today()
- if database.has_select_for():
- for company in companies:
- table = cls.__table__()
- query = table.select(Literal(1),
- where=(table.to_location.in_(location_ids)
- | table.from_location.in_(location_ids))
- & table.product.in_(product_ids)
- & (table.company == company.id),
- for_=For('UPDATE', nowait=True))
-
- PeriodCache = Period.get_cache(grouping)
- if PeriodCache:
- periods = Period.search([
- ('date', '<', stock_date_end),
- ('company', '=', company.id),
- ('state', '=', 'closed'),
- ], order=[('date', 'DESC')], limit=1)
- if periods:
- period, = periods
- query.where &= Coalesce(
- table.effective_date,
- table.planned_date,
- datetime.date.max) > period.date
-
- with connection.cursor() as cursor:
- cursor.execute(*query)
- else:
- database.lock(connection, cls._table)
+ if cls.lock_stock_move():
+ if database.has_select_for():
+ for company in companies:
+ table = cls.__table__()
+ query = table.select(Literal(1),
+ where=(table.to_location.in_(location_ids)
+ | table.from_location.in_(location_ids))
+ & table.product.in_(product_ids)
+ & (table.company == company.id),
+ for_=For('UPDATE', nowait=True))
+
+ PeriodCache = Period.get_cache(grouping)
+ if PeriodCache:
+ periods = Period.search([
+ ('date', '<', stock_date_end),
+ ('company', '=', company.id),
+ ('state', '=', 'closed'),
+ ], order=[('date', 'DESC')], limit=1)
+ if periods:
+ period, = periods
+ query.where &= Coalesce(
+ table.effective_date,
+ table.planned_date,
+ datetime.date.max) > period.date
+
+ with connection.cursor() as cursor:
+ cursor.execute(*query)
+ else:
+ database.lock(connection, cls._table)
pblc = {}
for company in companies: