details:   https://code.tryton.org/tryton/commit/7a9bef17e408
branch:    default
user:      Sergi Almacellas Abellana <[email protected]>
date:      Sat Nov 29 14:56:44 2025 +0100
description:
        Include assigned move in close period error message
diffstat:

 modules/stock/message.xml |   2 +-
 modules/stock/period.py   |  15 +++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diffs (50 lines):

diff -r 504795bdb0b1 -r 7a9bef17e408 modules/stock/message.xml
--- a/modules/stock/message.xml Thu Sep 04 09:08:41 2025 +0200
+++ b/modules/stock/message.xml Sat Nov 29 14:56:44 2025 +0100
@@ -33,7 +33,7 @@
             <field name="text">You cannot close periods with a date in the 
future or today.</field>
         </record>
         <record model="ir.message" id="msg_period_close_assigned_move">
-            <field name="text">You cannot close periods with assigned moves in 
it.</field>
+            <field name="text">To close the period "%(period)s", the assigned 
moves "%(moves)s" must be done or cancelled.</field>
         </record>
         <record model="ir.message" id="msg_shipment_planned_date">
             <field name="text">Planned Date</field>
diff -r 504795bdb0b1 -r 7a9bef17e408 modules/stock/period.py
--- a/modules/stock/period.py   Thu Sep 04 09:08:41 2025 +0200
+++ b/modules/stock/period.py   Sat Nov 29 14:56:44 2025 +0100
@@ -120,13 +120,15 @@
                 ], 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 @@
                                 ],
                             ('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)

Reply via email to