Include assigned move in close period error message
This commit is contained in:
1 parent
31a8acf935
commit
d5482c3947
2 files changed
+12
-5
No files matched your search
@@ -33,7 +33,7 @@ because the type does not support moves and location has existing moves.</field>
|
||||
<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>
|
||||
|
||||
+11
-4
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user