Commit d4c18ea3 authored by Cédric Krier's avatar Cédric Krier
Browse files

Assign all possible shipments and productions when trying

If assign_try fails to assign all the moves, we check if all the moves of each
shipment and production are assigned and then assign them.
Also we remove the boolean return which makes no more sense.

Closes #7006
parent ced0956c41cd
Pipeline #61728 passed with stages
in 35 minutes and 46 seconds
......@@ -244,7 +244,6 @@
>>> ShipmentOut = Model.get('stock.shipment.out')
>>> shipment, = sale.shipments
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('pick')
......
......@@ -206,7 +206,6 @@
>>> shipment, = sale.shipments
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('pick')
......
* Assign all possible productions when trying
Version 6.6.0 - 2022-10-31
--------------------------
* Bug fixes (see mercurial logs for details)
......
......@@ -779,6 +779,8 @@
def assign_try(cls, productions):
pool = Pool()
Move = pool.get('stock.move')
if Move.assign_try(
[m for p in productions for m in p.assign_moves]):
to_assign = [
m for p in productions for m in p.assign_moves
if m.assignation_required]
if Move.assign_try(to_assign):
cls.assign(productions)
......@@ -784,3 +786,2 @@
cls.assign(productions)
return True
else:
......@@ -786,5 +787,14 @@
else:
return False
to_assign = []
for production in productions:
if any(
m.state in {'staging', 'draft'}
for m in production.assign_moves
if m.assignation_required):
continue
to_assign.append(production)
if to_assign:
cls.assign(to_assign)
@classmethod
def _get_reschedule_domain(cls, date):
......
......@@ -161,7 +161,8 @@
Do the production::
>>> production.click('assign_try')
True
>>> production.state
'assigned'
>>> all(i.state == 'assigned' for i in production.inputs)
True
>>> production.click('run')
......@@ -192,7 +193,6 @@
>>> production.quantity = 2
>>> production.click('wait')
>>> production.click('assign_try')
True
>>> production.click('run')
>>> production.reload()
>>> all(i.effective_date == before_yesterday for i in production.inputs)
......
......@@ -179,7 +179,6 @@
Run the production::
>>> production.click('assign_try')
True
>>> production.click('run')
>>> production.state
'running'
......
......@@ -358,7 +358,6 @@
>>> move_return.quantity
4.0
>>> ship_return.click('assign_try')
True
>>> ship_return.click('done')
>>> ship_return.state
'done'
......@@ -429,7 +428,6 @@
>>> mix_return.click('wait')
>>> mix_return.click('assign_try')
True
>>> mix_return.click('done')
>>> move_return, = mix_return.moves
>>> move_return.product.rec_name
......@@ -497,7 +495,6 @@
>>> mix_return.click('wait')
>>> mix_return.click('assign_try')
True
>>> mix_return.click('done')
>>> move_return, = mix_return.moves
>>> move_return.product.rec_name
......
......@@ -265,7 +265,6 @@
Validate Shipments::
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('done')
......@@ -365,7 +364,6 @@
4.0
>>> stock_inventory_move.quantity = 3.0
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('done')
......@@ -506,7 +504,6 @@
>>> move_return.quantity
2.0
>>> mix_shipment.click('assign_try')
True
>>> mix_shipment.click('pick')
>>> mix_shipment.click('pack')
>>> mix_shipment.click('done')
......@@ -568,7 +565,6 @@
>>> move_return.quantity
3.0
>>> mix_shipment.click('assign_try')
True
>>> mix_shipment.click('pick')
>>> mix_shipment.click('pack')
>>> move_shipment, = mix_shipment.outgoing_moves
......@@ -657,7 +653,6 @@
>>> for move in shipment.inventory_moves:
... move.quantity = 5.0
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('done')
......
......@@ -245,7 +245,6 @@
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
......
......@@ -147,7 +147,7 @@
>>> len(shipments)
2
>>> for shipment in shipments:
... _ = shipment.click('assign_try')
... shipment.click('assign_try')
... shipment.click('pick')
... shipment.click('pack')
... shipment.click('done')
......
......@@ -243,7 +243,6 @@
>>> inventory.state
'done'
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
......
* Assign all possible shipments when trying
* Store warehouse locations on shipments
Version 6.6.0 - 2022-10-31
......
......@@ -977,7 +977,17 @@
success = False
if success:
cls.assign(shipments)
return success
else:
to_assign = []
for shipment in shipments:
if any(
m.state in {'staging', 'draft'}
for m in shipment.assign_moves
if m.assignation_required):
continue
to_assign.append(shipment)
if to_assign:
cls.assign(to_assign)
@classmethod
def _get_reschedule_domain(cls, date):
......@@ -1694,5 +1704,4 @@
if m.assignation_required]
if Move.assign_try(to_assign):
cls.assign(shipments)
return True
else:
......@@ -1698,5 +1707,14 @@
else:
return False
to_assign = []
for shipment in shipments:
if any(
m.state in {'staging', 'draft'}
for m in shipment.assign_moves
if m.assignation_required):
continue
to_assign.append(shipment)
if to_assign:
cls.assign(to_assign)
@classmethod
def _get_reschedule_domain(cls, date):
......@@ -2815,5 +2833,5 @@
to_assign = [
m for s in shipments for m in s.assign_moves
if m.assignation_required]
if not to_assign or Move.assign_try(to_assign):
if Move.assign_try(to_assign):
cls.assign(shipments)
......@@ -2819,3 +2837,2 @@
cls.assign(shipments)
return True
else:
......@@ -2821,5 +2838,14 @@
else:
return False
to_assign = []
for shipment in shipments:
if any(
m.state in {'staging', 'draft'}
for m in shipment.assign_moves
if m.assignation_required):
continue
to_assign.append(shipment)
if to_assign:
cls.assign(to_assign)
@property
def _move_planned_date(self):
......@@ -2912,7 +2938,8 @@
ignore = StateTransition()
def transition_start(self):
if self.record.assign_try():
self.record.assign_try()
if self.record.state == 'assigned':
return 'end'
else:
return 'partial'
......
......@@ -112,7 +112,6 @@
>>> shipment_out.save()
>>> shipment_out.click('wait')
>>> shipment_out.click('assign_try')
True
>>> shipment_out.click('pick')
>>> shipment_out.click('pack')
>>> shipment_out.click('done')
......@@ -153,7 +152,6 @@
>>> shipment_internal.save()
>>> shipment_internal.click('wait')
>>> shipment_internal.click('assign_try')
True
>>> shipment_internal.click('done')
Testing the report::
......
......@@ -89,7 +89,8 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
False
>>> shipment.state
'waiting'
>>> shipment.assigned_by
>>> shipment.done_by
......@@ -110,7 +111,6 @@
>>> move.currency = company.currency
>>> lost_found_shipment.click('wait')
>>> lost_found_shipment.click('assign_try')
True
>>> lost_found_shipment.state
'assigned'
>>> lost_found_shipment.click('done')
......@@ -120,7 +120,6 @@
Check that now we can finish the older shipment::
>>> shipment.click('assign_try')
True
>>> shipment.assigned_by == employee
True
>>> shipment.done_by
......
......@@ -248,7 +248,6 @@
Finish the shipment::
>>> shipment_out.click('assign_try')
True
>>> shipment_out.click('pick')
>>> shipment_out.click('pack')
>>> shipment_out.click('done')
......
......@@ -121,7 +121,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
......@@ -142,7 +141,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
......@@ -184,7 +182,8 @@
>>> move, = shipment_out.inventory_moves
>>> move.from_location = supplier_consignment_loc
>>> shipment_out.click('assign_try')
True
>>> shipment_out.state
'assigned'
>>> move, = shipment_out.inventory_moves
>>> len(move.invoice_lines)
1
......@@ -203,7 +202,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
......@@ -224,7 +222,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
......@@ -268,7 +265,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> move, = shipment.moves
......
......@@ -112,7 +112,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
......@@ -133,7 +132,6 @@
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
......
......@@ -43,7 +43,6 @@
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> pallet.reload()
......@@ -87,7 +86,8 @@
>>> shipment2.click('wait')
>>> shipment1.click('assign_try')
True
>>> shipment1.state
'assigned'
>>> shipment2.click('assign_try') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
......@@ -117,7 +117,6 @@
>>> shipment.locations.append(Location(pallet.id))
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.click('ship')
>>> pallet.reload()
......
......@@ -133,7 +133,6 @@
>>> move.to_location = customer_loc
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('done')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment