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
This commit is contained in:
Cédric Krier committed 2023-01-14 15:41:26 +01:00
1 parent d62f2acb08
commit 69a1be6404
24 files changed
+60 -51

No files matched your search

@@ -244,7 +244,6 @@ Send 5 products::
>>> ShipmentOut = Model.get('stock.shipment.out')
>>> shipment, = sale.shipments
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('pick')
@@ -206,7 +206,6 @@ Send 5 products::
>>> shipment, = sale.shipments
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('pick')
+2
View File
@@ -1,3 +1,5 @@
* Assign all possible productions when trying
Version 6.6.0 - 2022-10-31
--------------------------
* Bug fixes (see mercurial logs for details)
+14 -4
View File
@@ -779,12 +779,22 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
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)
return True
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 @@ Test reset bom button::
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 @@ Make a production with effective date yesterday and running the day before::
>>> 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 @@ Test works::
Run the production::
>>> production.click('assign_try')
True
>>> production.click('run')
>>> production.state
'running'
@@ -358,7 +358,6 @@ Check Return Shipments::
>>> move_return.quantity
4.0
>>> ship_return.click('assign_try')
True
>>> ship_return.click('done')
>>> ship_return.state
'done'
@@ -429,7 +428,6 @@ Checking Shipments::
>>> 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 @@ Checking Shipments::
>>> mix_return.click('wait')
>>> mix_return.click('assign_try')
True
>>> mix_return.click('done')
>>> move_return, = mix_return.moves
>>> move_return.product.rec_name
-5
View File
@@ -265,7 +265,6 @@ Not yet linked to invoice lines::
Validate Shipments::
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('done')
@@ -365,7 +364,6 @@ Ship 3 products::
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 @@ Checking Shipments::
>>> 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 @@ Checking Shipments::
>>> 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 @@ to invoices::
>>> 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 @@ Let's try to pack it::
>>> 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 @@ Check the shipments::
>>> 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 @@ not create a new purchase request::
>>> inventory.state
'done'
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
+1
View File
@@ -1,3 +1,4 @@
* Assign all possible shipments when trying
* Store warehouse locations on shipments
Version 6.6.0 - 2022-10-31
+34 -7
View File
@@ -977,7 +977,17 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
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,9 +1704,17 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
if m.assignation_required]
if Move.assign_try(to_assign):
cls.assign(shipments)
return True
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,11 +2833,19 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
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)
return True
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 @@ class Assign(Wizard):
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 @@ Add two shipment lines of same product and go through the workflow::
>>> 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 @@ Create an internal shipment::
>>> shipment_internal.save()
>>> shipment_internal.click('wait')
>>> shipment_internal.click('assign_try')
True
>>> shipment_internal.click('done')
Testing the report::
@@ -89,7 +89,8 @@ Create Internal Shipment::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
False
>>> shipment.state
'waiting'
>>> shipment.assigned_by
>>> shipment.done_by
@@ -110,7 +111,6 @@ Create Internal Shipment from lost_found location::
>>> 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 @@ Create Internal Shipment from lost_found location::
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 @@ Make 1 unit of the product available::
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 @@ Fill supplier consignment location::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
@@ -142,7 +141,6 @@ Use supplier consignment stock::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
@@ -184,7 +182,8 @@ Use supplier consignment stock for shipment out::
>>> 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 @@ Fill customer consignment location::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
@@ -224,7 +222,6 @@ Use customer consignment stock::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
@@ -268,7 +265,6 @@ Cancel supplier consignment stock::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> move, = shipment.moves
@@ -112,7 +112,6 @@ Fill supplier consignment location::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
@@ -133,7 +132,6 @@ Use supplier consignment stock by customer::
>>> shipment.state
'waiting'
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> shipment.click('done')
@@ -43,7 +43,6 @@ Move pallet from storage1 to storage2::
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> pallet.reload()
@@ -87,7 +86,8 @@ Concurrently move pallet::
>>> 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 @@ Move pallet from storage1 to storage2 with lead_time::
>>> shipment.locations.append(Location(pallet.id))
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.click('ship')
>>> pallet.reload()
@@ -133,7 +133,6 @@ Ship 1 product from the locations::
>>> move.to_location = customer_loc
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> shipment.click('done')
@@ -115,7 +115,6 @@ Request specific lot in stock assignation::
Assign the shipment::
>>> shipment.click('assign_try')
True
>>> shipment.state
'assigned'
>>> move, = shipment.inventory_moves
@@ -100,7 +100,6 @@ Let's ship a product with a lot::
>>> move.to_location = customer_loc
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> move.lot = lot
>>> shipment.click('pick')
>>> shipment.click('pack')
@@ -129,7 +128,6 @@ Let's ship now two times the same lot::
>>> move2.to_location = customer_loc
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> move1, move2 = shipment.inventory_moves
>>> move1.lot = lot
>>> move2.lot = lot
@@ -156,7 +154,6 @@ Now let's ship one move with a quantity bigger than lot unit quantity::
>>> move.to_location = customer_loc
>>> shipment.click('wait')
>>> shipment.click('assign_try')
True
>>> move, = shipment.inventory_moves
>>> move.lot = lot
>>> shipment.click('pick') # doctest: +IGNORE_EXCEPTION_DETAIL
@@ -203,7 +203,6 @@ Create the packs and ship the shipment::
>>> Package = Model.get('stock.package')
>>> shipment, = sale.shipments
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> pack = shipment.packages.new()
>>> pack.type = box
@@ -210,7 +210,6 @@ Create the packs and ship the shipment::
>>> shipment, = sale.shipments
>>> shipment.shipping_description = 'Football Players'
>>> shipment.click('assign_try')
True
>>> shipment.click('pick')
>>> pack = shipment.packages.new()
>>> pack.type = ups_box