From d5482c3947aeeeb5a098a5711f4cbdf7a9c20768 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sat, 29 Nov 2025 14:56:44 +0100 Subject: [PATCH] Include assigned move in close period error message --- modules/stock/message.xml | 2 +- modules/stock/period.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/stock/message.xml b/modules/stock/message.xml index 2bb2dde0d1..9bf5368963 100644 --- a/modules/stock/message.xml +++ b/modules/stock/message.xml @@ -33,7 +33,7 @@ because the type does not support moves and location has existing moves. You cannot close periods with a date in the future or today. - You cannot close periods with assigned moves in it. + To close the period "%(period)s", the assigned moves "%(moves)s" must be done or cancelled. Planned Date diff --git a/modules/stock/period.py b/modules/stock/period.py index 76d37019aa..6f3f87f76b 100644 --- a/modules/stock/period.py +++ b/modules/stock/period.py @@ -120,13 +120,15 @@ class Period(Workflow, ModelSQL, ModelView): ], order=[]) for company, c_periods in groupby(periods, key=lambda p: p.company): + c_periods = list(c_periods) with Transaction().set_context(company=company.id): today = Date.today() - recent_date = max(period.date for period in c_periods) + recent_period = max(c_periods, key=lambda p: p.date) + recent_date = recent_period.date if recent_date >= today: raise PeriodCloseError( gettext('stock.msg_period_close_date')) - if Move.search([ + if assigned_moves := Move.search([ ('company', '=', company.id), ('state', '=', 'assigned'), ['OR', [ @@ -135,9 +137,14 @@ class Period(Workflow, ModelSQL, ModelView): ], ('effective_date', '<=', recent_date), ]], - limit=1): + limit=6): + names = ', '.join(m.rec_name for m in assigned_moves[:5]) + if len(assigned_moves) > 5: + names += '...' raise PeriodCloseError( - gettext('stock.msg_period_close_assigned_move')) + gettext('stock.msg_period_close_assigned_move', + period=recent_period.rec_name, + moves=names)) for grouping in cls.groupings(): Cache = cls.get_cache(grouping)