Cannot do UL if has moves without end date.

This commit refs #27658
This commit is contained in:
Sergio Morillo 2023-08-03 12:07:30 +02:00
parent 8b771978cc
commit 68487f0441
4 changed files with 36 additions and 11 deletions

View File

@ -962,4 +962,8 @@ msgstr "Hora inicio"
msgctxt "view:stock.move:"
msgid "End Time"
msgstr "Hora fin"
msgstr "Hora fin"
msgctxt "model:ir.message,text:msg_move_without_end_date"
msgid "Cannot do UL \"%(unit_load)s\" with a move without end date."
msgstr "No se puede finalizar la UdC \"%(unit_load)s\" con un movimiento sin fecha fin."

View File

@ -65,5 +65,8 @@
<record model="ir.message" id="msg_stock_unit_load_wrong_warehouse">
<field name="text">Cannot move or drop UL "%(unit_load)s" to location "%(to_location)s" because it is on Warehouse "%(warehouse)s".</field>
</record>
<record model="ir.message" id="msg_move_without_end_date">
<field name="text">Cannot do UL "%(unit_load)s" with a move without end date.</field>
</record>
</data>
</tryton>

View File

@ -589,6 +589,9 @@ Execute global drop wizard with proposed end date::
True
>>> move2.end_date = datetime.datetime.now()
>>> move2.save()
>>> move.reload()
>>> move.state
'draft'
>>> time.sleep(5)
>>> drop_ul = Wizard('stock.unit_load.do_drop', [])
@ -601,6 +604,12 @@ Execute global drop wizard with proposed end date::
>>> move3, = unit_load6.drop_moves
>>> not bool(move3.end_date)
True
>>> move.reload()
>>> move.state
'draft'
>>> move3.reload()
>>> move3.state
'draft'
>>> time.sleep(5)
>>> drop_ul = Wizard('stock.unit_load.do_drop', [])
@ -613,8 +622,13 @@ Execute global drop wizard with proposed end date::
>>> move4, = unit_load7.drop_moves
>>> not bool(move4.end_date)
True
>>> move4.state
'draft'
>>> unit_load7.click('assign')
>>> unit_load7.click('do')
>>> unit_load7.click('do') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
trytond.exceptions.UserError: Cannot do UL "..." with a move without end date. -
>>> time.sleep(5)
>>> drop_ul = Wizard('stock.unit_load.do_drop', [])

View File

@ -1315,7 +1315,10 @@ class UnitLoad(ModelSQL, ModelView):
'stock_unit_load.msg_stock_unit_load_state_origin',
unit_load=move.unit_load.rec_name,
origin=(move.origin or move.shipment).rec_name))
if not move.end_date:
raise UserError(gettext('stock_unit_load'
'.msg_move_without_end_date',
unit_load=move.unit_load.rec_name))
move.unit_load.check_warehouse(move)
if moves:
@ -2339,15 +2342,15 @@ class DropUnitLoad(Wizard):
if (prod_conf.propose_drop_end_date == 'last_drop'
and not self.data.parallel):
moves = Move.search(self.get_last_drop_moves_domain())
# get ULs from moves
uls = list(set(m.unit_load for m in moves))
moves = [m for ul in uls
for m in ul.drop_moves + ul.return_moves
if not m.end_date and m.state != 'do'
]
moves = sorted(moves, key=lambda m: m.start_date, reverse=True)
to_write = []
for move in moves:
if not move.end_date:
to_write.append(move)
if to_write:
Move.write(to_write, {'end_date': self.data.start_date})
uls = list(set(
m.unit_load for m in moves if m.state != 'done'))
if moves:
Move.write(moves, {'end_date': self.data.start_date})
if uls:
Unitload.do(uls)
@ -2386,6 +2389,7 @@ class DropUnitLoad(Wizard):
def get_last_drop_moves_domain(self):
return [
('unit_load', '!=', None),
('unit_load.production_state', '=', 'done'),
('to_location', '=', self.data.location),
('start_date', '>=', datetime.datetime.combine(
self.data.start_date.date(), datetime.datetime.min.time())),