diff --git a/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst b/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst index d37825382a..2a6a5ca16d 100644 --- a/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst +++ b/modules/account_stock_anglo_saxon/tests/scenario_account_stock_anglo_saxon.rst @@ -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') diff --git a/modules/account_stock_continental/tests/scenario_account_stock_continental.rst b/modules/account_stock_continental/tests/scenario_account_stock_continental.rst index 6b9e51eeea..416aa2f8af 100644 --- a/modules/account_stock_continental/tests/scenario_account_stock_continental.rst +++ b/modules/account_stock_continental/tests/scenario_account_stock_continental.rst @@ -206,7 +206,6 @@ Send 5 products:: >>> shipment, = sale.shipments >>> shipment.click('assign_try') - True >>> shipment.state 'assigned' >>> shipment.click('pick') diff --git a/modules/production/CHANGELOG b/modules/production/CHANGELOG index 3da1cd999d..da70da7262 100644 --- a/modules/production/CHANGELOG +++ b/modules/production/CHANGELOG @@ -1,3 +1,5 @@ +* Assign all possible productions when trying + Version 6.6.0 - 2022-10-31 -------------------------- * Bug fixes (see mercurial logs for details) diff --git a/modules/production/production.py b/modules/production/production.py index df6a548396..baa749c385 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -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): diff --git a/modules/production/tests/scenario_production.rst b/modules/production/tests/scenario_production.rst index ba9e0e5ba8..fe23bae004 100644 --- a/modules/production/tests/scenario_production.rst +++ b/modules/production/tests/scenario_production.rst @@ -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) diff --git a/modules/production_work/tests/scenario_production_work.rst b/modules/production_work/tests/scenario_production_work.rst index 1021e084d5..a66f44ccaa 100644 --- a/modules/production_work/tests/scenario_production_work.rst +++ b/modules/production_work/tests/scenario_production_work.rst @@ -179,7 +179,6 @@ Test works:: Run the production:: >>> production.click('assign_try') - True >>> production.click('run') >>> production.state 'running' diff --git a/modules/purchase/tests/scenario_purchase.rst b/modules/purchase/tests/scenario_purchase.rst index 0d991cc542..9e8bfa87b2 100644 --- a/modules/purchase/tests/scenario_purchase.rst +++ b/modules/purchase/tests/scenario_purchase.rst @@ -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 diff --git a/modules/sale/tests/scenario_sale.rst b/modules/sale/tests/scenario_sale.rst index c13e9d2889..4b80bfbb4e 100644 --- a/modules/sale/tests/scenario_sale.rst +++ b/modules/sale/tests/scenario_sale.rst @@ -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') diff --git a/modules/sale_advance_payment/tests/scenario_advance_payment.rst b/modules/sale_advance_payment/tests/scenario_advance_payment.rst index 1b304255f0..ec853ec732 100644 --- a/modules/sale_advance_payment/tests/scenario_advance_payment.rst +++ b/modules/sale_advance_payment/tests/scenario_advance_payment.rst @@ -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): diff --git a/modules/sale_shipment_grouping/tests/scenario_sale_shipment_grouping.rst b/modules/sale_shipment_grouping/tests/scenario_sale_shipment_grouping.rst index 04bff28b0c..399375d9c0 100644 --- a/modules/sale_shipment_grouping/tests/scenario_sale_shipment_grouping.rst +++ b/modules/sale_shipment_grouping/tests/scenario_sale_shipment_grouping.rst @@ -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') diff --git a/modules/sale_supply/tests/scenario_sale_supply.rst b/modules/sale_supply/tests/scenario_sale_supply.rst index cfdc63b9a4..feda03a5a5 100644 --- a/modules/sale_supply/tests/scenario_sale_supply.rst +++ b/modules/sale_supply/tests/scenario_sale_supply.rst @@ -243,7 +243,6 @@ not create a new purchase request:: >>> inventory.state 'done' >>> shipment.click('assign_try') - True >>> shipment.click('pick') >>> shipment.click('pack') diff --git a/modules/stock/CHANGELOG b/modules/stock/CHANGELOG index c177e4881a..7e44592fbf 100644 --- a/modules/stock/CHANGELOG +++ b/modules/stock/CHANGELOG @@ -1,3 +1,4 @@ +* Assign all possible shipments when trying * Store warehouse locations on shipments Version 6.6.0 - 2022-10-31 diff --git a/modules/stock/shipment.py b/modules/stock/shipment.py index 136bfb825a..79e5bea871 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -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' diff --git a/modules/stock/tests/scenario_stock_reporting.rst b/modules/stock/tests/scenario_stock_reporting.rst index 8863d2f8fe..fd9a1f285f 100644 --- a/modules/stock/tests/scenario_stock_reporting.rst +++ b/modules/stock/tests/scenario_stock_reporting.rst @@ -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:: diff --git a/modules/stock/tests/scenario_stock_shipment_internal.rst b/modules/stock/tests/scenario_stock_shipment_internal.rst index b0a0ff38ae..a678ff6cfc 100644 --- a/modules/stock/tests/scenario_stock_shipment_internal.rst +++ b/modules/stock/tests/scenario_stock_shipment_internal.rst @@ -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 diff --git a/modules/stock/tests/scenario_stock_shipment_out.rst b/modules/stock/tests/scenario_stock_shipment_out.rst index 963b3d2b99..bc37fd238a 100644 --- a/modules/stock/tests/scenario_stock_shipment_out.rst +++ b/modules/stock/tests/scenario_stock_shipment_out.rst @@ -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') diff --git a/modules/stock_consignment/tests/scenario_stock_consignment.rst b/modules/stock_consignment/tests/scenario_stock_consignment.rst index b70c8f61a9..5d8be93d75 100644 --- a/modules/stock_consignment/tests/scenario_stock_consignment.rst +++ b/modules/stock_consignment/tests/scenario_stock_consignment.rst @@ -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 diff --git a/modules/stock_consignment/tests/scenario_stock_consignment_supplier_customer.rst b/modules/stock_consignment/tests/scenario_stock_consignment_supplier_customer.rst index f6b4abc3bf..e2d504e568 100644 --- a/modules/stock_consignment/tests/scenario_stock_consignment_supplier_customer.rst +++ b/modules/stock_consignment/tests/scenario_stock_consignment_supplier_customer.rst @@ -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') diff --git a/modules/stock_location_move/tests/scenario_stock_location_move.rst b/modules/stock_location_move/tests/scenario_stock_location_move.rst index 328b1c1933..942d11ebd3 100644 --- a/modules/stock_location_move/tests/scenario_stock_location_move.rst +++ b/modules/stock_location_move/tests/scenario_stock_location_move.rst @@ -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() diff --git a/modules/stock_location_move/tests/scenario_stock_location_move_empty.rst b/modules/stock_location_move/tests/scenario_stock_location_move_empty.rst index 43255f00aa..9fcbdd75e3 100644 --- a/modules/stock_location_move/tests/scenario_stock_location_move_empty.rst +++ b/modules/stock_location_move/tests/scenario_stock_location_move_empty.rst @@ -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') diff --git a/modules/stock_lot/tests/scenario_stock_lot_assign_try.rst b/modules/stock_lot/tests/scenario_stock_lot_assign_try.rst index f080c9b405..42f8df6a3f 100644 --- a/modules/stock_lot/tests/scenario_stock_lot_assign_try.rst +++ b/modules/stock_lot/tests/scenario_stock_lot_assign_try.rst @@ -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 diff --git a/modules/stock_lot_unit/tests/scenario_stock_lot_unit.rst b/modules/stock_lot_unit/tests/scenario_stock_lot_unit.rst index 5cc30c64d0..0d340e0682 100644 --- a/modules/stock_lot_unit/tests/scenario_stock_lot_unit.rst +++ b/modules/stock_lot_unit/tests/scenario_stock_lot_unit.rst @@ -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 diff --git a/modules/stock_package_shipping_dpd/tests/scenario_shipping_dpd.rst b/modules/stock_package_shipping_dpd/tests/scenario_shipping_dpd.rst index 5199beffc9..8bf00502d2 100644 --- a/modules/stock_package_shipping_dpd/tests/scenario_shipping_dpd.rst +++ b/modules/stock_package_shipping_dpd/tests/scenario_shipping_dpd.rst @@ -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 diff --git a/modules/stock_package_shipping_ups/tests/scenario_shipping_ups.rst b/modules/stock_package_shipping_ups/tests/scenario_shipping_ups.rst index a5f39992ed..eabd8a0c07 100644 --- a/modules/stock_package_shipping_ups/tests/scenario_shipping_ups.rst +++ b/modules/stock_package_shipping_ups/tests/scenario_shipping_ups.rst @@ -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