From cb1409e125c5881f638fac517572f334203c467c Mon Sep 17 00:00:00 2001 From: Bernat Brunet Date: Mon, 20 Jan 2020 16:49:28 +0100 Subject: [PATCH] Update lock_stock_move pathc adapting it to the core changes --- lock_stock_move.diff | 78 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lock_stock_move.diff diff --git a/lock_stock_move.diff b/lock_stock_move.diff new file mode 100644 index 0000000..1130d0c --- /dev/null +++ b/lock_stock_move.diff @@ -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: