diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 9e5537c9310..1af444e669c 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -534,16 +534,6 @@ class StockMove(models.Model): else: return 0.0 - def _show_details_in_draft(self): - self.ensure_one() - production = self.raw_material_production_id or self.production_id - if production and (self.state != 'draft' or production.state != 'draft'): - return True - elif production: - return False - else: - return super()._show_details_in_draft() - def _update_quantity_done(self, mo): self.ensure_one() new_qty = float_round((mo.qty_producing - mo.qty_produced) * self.unit_factor, precision_rounding=self.product_uom.rounding) diff --git a/addons/mrp/tests/test_procurement.py b/addons/mrp/tests/test_procurement.py index 49bc491009d..79b8544acee 100644 --- a/addons/mrp/tests/test_procurement.py +++ b/addons/mrp/tests/test_procurement.py @@ -455,6 +455,7 @@ class TestProcurement(TestMrpCommon): 'location_dest_id': self.ref('stock.stock_location_customers'), })], }) + pick_output.action_reset_draft() pick_output.action_confirm() # should trigger orderpoint to create and confirm 1st MO pick_output.action_assign() diff --git a/addons/mrp/tests/test_stock.py b/addons/mrp/tests/test_stock.py index e17b6e933d2..f15ae8e219f 100644 --- a/addons/mrp/tests/test_stock.py +++ b/addons/mrp/tests/test_stock.py @@ -304,7 +304,6 @@ class TestKitPicking(common.TestMrpCommon): 'location_dest_id': self.warehouse_1.wh_input_stock_loc_id.id, 'partner_id': self.test_partner.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, - 'immediate_transfer': True }) move_receipt_1 = self.env['stock.move'].create({ 'name': self.kit_parent.name, @@ -366,6 +365,8 @@ class TestKitPicking(common.TestMrpCommon): 'picking_type_id': in_type.id, 'location_id': customer_location.id, 'location_dest_id': stock_location.id, + 'state': 'draft', + 'immediate_transfer': False, 'move_ids': [(0, 0, { 'name': product.name, 'product_id': product.id, diff --git a/addons/mrp/tests/test_traceability.py b/addons/mrp/tests/test_traceability.py index 221c31b8aa8..9bfec2a001e 100644 --- a/addons/mrp/tests/test_traceability.py +++ b/addons/mrp/tests/test_traceability.py @@ -505,16 +505,12 @@ class TestTraceability(TestMrpCommon): moveA = self.env['stock.move'].create({ 'name': 'Picking A move', 'product_id': endproductA.id, - 'product_uom_qty': 1, + 'quantity_done': 1, 'product_uom': endproductA.uom_id.id, 'picking_id': pickingA_out.id, 'location_id': stock_location.id, 'location_dest_id': customer_location.id}) - # Confirm and assign pickingA - pickingA_out.action_confirm() - pickingA_out.action_assign() - # Set move_line lot_id to the mrp.production lot_producing_id moveA.move_line_ids[0].write({ 'qty_done': 1.0, diff --git a/addons/mrp/tests/test_unbuild.py b/addons/mrp/tests/test_unbuild.py index 58e074d784b..1bb80accba4 100644 --- a/addons/mrp/tests/test_unbuild.py +++ b/addons/mrp/tests/test_unbuild.py @@ -708,11 +708,8 @@ class TestUnbuild(TestMrpCommon): internal_form.location_dest_id = subloc01 with internal_form.move_ids_without_package.new() as move: move.product_id = p_final - move.product_uom_qty = 1.0 + move.quantity_done = 1.0 internal_transfer = internal_form.save() - internal_transfer.action_confirm() - internal_transfer.action_assign() - internal_transfer.move_line_ids.qty_done = 1.0 internal_transfer.button_validate() unbuild_order_form = Form(self.env['mrp.unbuild']) diff --git a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py index 62f6ef8b904..300ec39ba16 100644 --- a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py +++ b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py @@ -146,7 +146,10 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): 'location_dest_id': self.customer_location, 'partner_id': self.env['ir.model.data']._xmlid_to_res_id('base.res_partner_4'), 'picking_type_id': self.warehouse.out_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) + self.env['stock.move'].create({ 'name': self.finished_product.name, 'product_id': self.finished_product.id, @@ -226,6 +229,8 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): 'location_dest_id': self.customer_location, 'partner_id': self.env['ir.model.data']._xmlid_to_res_id('base.res_partner_4'), 'picking_type_id': self.warehouse.out_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': self.finished_product.name, diff --git a/addons/mrp_account/tests/test_valuation_layers.py b/addons/mrp_account/tests/test_valuation_layers.py index ea6f641d5bf..be34216484b 100644 --- a/addons/mrp_account/tests/test_valuation_layers.py +++ b/addons/mrp_account/tests/test_valuation_layers.py @@ -334,6 +334,8 @@ class TestMrpValuationStandard(TestMrpValuationCommon): 'location_id': self.customer_location.id, 'location_dest_id': self.stock_location.id, 'picking_type_id': self.picking_type_in.id, + 'state': 'draft', + 'immediate_transfer': False, 'move_line_ids': [(0, 0, { 'product_id': self.product1.id, 'qty_done': 1, diff --git a/addons/mrp_subcontracting/models/mrp_production.py b/addons/mrp_subcontracting/models/mrp_production.py index 2ec044f77f7..4bd5940f77b 100644 --- a/addons/mrp_subcontracting/models/mrp_production.py +++ b/addons/mrp_subcontracting/models/mrp_production.py @@ -80,7 +80,7 @@ class MrpProduction(models.Model): if consumption_issues: return self._action_generate_consumption_wizard(consumption_issues) - self._update_finished_move() + self.sudo()._update_finished_move() # Portal user may need sudo rights to update pickings self.subcontracting_has_been_recorded = True quantity_issues = self._get_quantity_produced_issues() diff --git a/addons/mrp_subcontracting/models/stock_move.py b/addons/mrp_subcontracting/models/stock_move.py index ca3c6ad2a44..01749b5dbeb 100644 --- a/addons/mrp_subcontracting/models/stock_move.py +++ b/addons/mrp_subcontracting/models/stock_move.py @@ -153,9 +153,6 @@ class StockMove(models.Model): bom = move._get_subcontract_bom() if not bom: continue - if float_is_zero(move.product_qty, precision_rounding=move.product_uom.rounding) and\ - move.picking_id.immediate_transfer is True: - raise UserError(_("To subcontract, use a planned transfer.")) move.write({ 'is_subcontract': True, 'location_id': move.picking_id.partner_id.with_company(move.company_id).property_stock_subcontractor.id @@ -241,7 +238,10 @@ class StockMove(models.Model): def _update_subcontract_order_qty(self, new_quantity): for move in self: - quantity_to_remove = move.product_uom_qty - new_quantity + move_quantity = move.quantity_done if move.from_immediate_transfer else move.product_uom_qty + quantity_to_remove = move_quantity - new_quantity + if float_is_zero(quantity_to_remove, precision_rounding=move.product_uom.rounding): + continue productions = move.move_orig_ids.production_id.filtered(lambda p: p.state not in ('done', 'cancel'))[::-1] # Cancel productions until reach new_quantity for production in productions: diff --git a/addons/mrp_subcontracting/models/stock_picking.py b/addons/mrp_subcontracting/models/stock_picking.py index 6f08c82cd50..0c7258beb77 100644 --- a/addons/mrp_subcontracting/models/stock_picking.py +++ b/addons/mrp_subcontracting/models/stock_picking.py @@ -138,7 +138,7 @@ class StockPicking(models.Model): 'bom_id': bom.id, 'location_src_id': subcontract_move.picking_id.partner_id.with_company(subcontract_move.company_id).property_stock_subcontractor.id, 'location_dest_id': subcontract_move.picking_id.partner_id.with_company(subcontract_move.company_id).property_stock_subcontractor.id, - 'product_qty': subcontract_move.product_uom_qty, + 'product_qty': subcontract_move.from_immediate_transfer and subcontract_move.quantity_done or subcontract_move.product_qty, 'picking_type_id': warehouse.subcontracting_type_id.id, 'date_start': subcontract_move.date - relativedelta(days=bom.produce_delay) } @@ -150,7 +150,8 @@ class StockPicking(models.Model): # do not create extra production for move that have their quantity updated if move.move_orig_ids.production_id: continue - if float_compare(move.product_qty, 0, precision_rounding=move.product_uom.rounding) <= 0: + quantity = move.from_immediate_transfer and move.quantity_done or move.product_qty + if float_compare(quantity, 0, precision_rounding=move.product_uom.rounding) <= 0: # If a subcontracted amount is decreased, don't create a MO that would be for a negative value. continue mo = self.env['mrp.production'].with_company(move.company_id).create(self._prepare_subcontract_mo_vals(move, bom)) diff --git a/addons/mrp_subcontracting/tests/test_subcontracting.py b/addons/mrp_subcontracting/tests/test_subcontracting.py index f8467b5d8bc..3056e11a5e7 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting.py @@ -38,9 +38,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() # Nothing should be tracked self.assertTrue(all(m.product_uom_qty == m.reserved_availability for m in picking_receipt.move_ids)) @@ -121,9 +120,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() # Nothing should be tracked self.assertEqual(picking_receipt.display_action_record_components, 'hide') @@ -189,9 +187,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() # Nothing should be tracked self.assertEqual(picking_receipt.display_action_record_components, 'hide') @@ -255,9 +252,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() warehouse = picking_receipt.picking_type_id.warehouse_id @@ -324,9 +320,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt1 = picking_form.save() - picking_receipt1.action_confirm() # Create a receipt picking from the subcontractor2 picking_form = Form(self.env['stock.picking']) @@ -334,9 +329,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = subcontractor_partner2 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt2 = picking_form.save() - picking_receipt2.action_confirm() mo_pick1 = picking_receipt1.move_ids.mapped('move_orig_ids.production_id') mo_pick2 = picking_receipt2.move_ids.mapped('move_orig_ids.production_id') @@ -385,9 +379,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = subcontractor_partner2 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() picking_receipt.move_ids.quantity_done = 3.0 picking_receipt._action_done() @@ -412,8 +405,9 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 5 + move.quantity_done = 5 picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() picking_receipt.move_ids.quantity_done = 3 @@ -452,9 +446,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 5 + move.quantity_done = 5 picking_receipt = picking_form.save() - picking_receipt.action_confirm() picking_delivery = self.env['stock.move'].search([ ('product_id', 'in', (self.comp1 | self.comp2).ids) @@ -485,9 +478,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = subcontractor_contact with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() # Check that a manufacturing order is created mo = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)]) self.assertEqual(len(mo), 1) @@ -501,9 +493,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() self.assertEqual(picking_receipt.display_action_record_components, 'facultative') action = picking_receipt.action_record_components() mo = self.env['mrp.production'].browse(action['res_id']) @@ -534,9 +525,8 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() - picking_receipt.action_confirm() self.assertEqual(picking_receipt.display_action_record_components, 'facultative') action = picking_receipt.action_record_components() @@ -642,8 +632,9 @@ class TestSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = finished - move.product_uom_qty = 5 + move.quantity_done = 5 picking = picking_form.save() + picking.action_reset_draft() picking.action_confirm() supply_picking = self.env['mrp.production'].search([('bom_id', '=', bom.id)]).picking_ids @@ -745,8 +736,9 @@ class TestSubcontractingTracking(TransactionCase): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished_product - move.product_uom_qty = 1 + move.quantity_done = 1 picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() # We should be able to call the 'record_components' button @@ -823,8 +815,9 @@ class TestSubcontractingTracking(TransactionCase): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished_product - move.product_uom_qty = nb_finished_product + move.quantity_done = nb_finished_product picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() # We shouldn't be able to call the 'record_components' button @@ -870,8 +863,9 @@ class TestSubcontractingTracking(TransactionCase): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished_product - move.product_uom_qty = todo_nb + move.quantity_done = todo_nb picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() # We should be able to call the 'record_components' button @@ -973,8 +967,9 @@ class TestSubcontractingTracking(TransactionCase): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = finished_product - move.product_uom_qty = todo_nb + move.quantity_done = todo_nb picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() mo = self.env['mrp.production'].search([('bom_id', '=', bom.id)]) @@ -1047,8 +1042,9 @@ class TestSubcontractingTracking(TransactionCase): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = finished_product - move.product_uom_qty = todo_nb + move.quantity_done = todo_nb picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() mo = self.env['mrp.production'].search([('bom_id', '=', bom.id)]) @@ -1146,9 +1142,8 @@ class TestSubcontractingPortal(TransactionCase): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished_product - move.product_uom_qty = 2 + move.quantity_done = 2 picking_receipt = picking_form.save() - picking_receipt.action_confirm() # Using the subcontractor (portal user) lot1 = self.env['stock.lot'].with_user(self.portal_user).create({ @@ -1259,8 +1254,9 @@ class TestSubcontractingSerialMassReceipt(TransactionCase): picking_form.partner_id = self.subcontractor with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = sum(quantities) + move.quantity_done = sum(quantities) picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() # Process the delivery of the components picking_deliver = self.env['mrp.production'].search([('bom_id', '=', self.bom.id)]).picking_ids @@ -1297,9 +1293,8 @@ class TestSubcontractingSerialMassReceipt(TransactionCase): picking_form.partner_id = self.subcontractor with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = quantity + move.quantity_done = quantity picking_receipt = picking_form.save() - picking_receipt.action_confirm() # Receive finished products Form(self.env['stock.assign.serial'].with_context( default_move_id=picking_receipt.move_ids[0].id, diff --git a/addons/mrp_subcontracting/tests/test_subcontracting_portal_ui.py b/addons/mrp_subcontracting/tests/test_subcontracting_portal_ui.py index 5f84565d15e..e6a58915d41 100644 --- a/addons/mrp_subcontracting/tests/test_subcontracting_portal_ui.py +++ b/addons/mrp_subcontracting/tests/test_subcontracting_portal_ui.py @@ -54,8 +54,9 @@ class TestSubcontractingPortalUi(HttpCase): picking_form.partner_id = self.partner_portal with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished_product - move.product_uom_qty = 2 + move.quantity_done = 2 picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() picking_receipt.action_confirm() self.start_tour("/my/productions", 'subcontracting_portal_tour', login="georges1") diff --git a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py index 9a2dc4d7d28..4993632c385 100644 --- a/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py +++ b/addons/mrp_subcontracting_account/tests/test_subcontracting_account.py @@ -146,8 +146,9 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = todo_nb + move.quantity_done = todo_nb picking_receipt = picking_form.save() + picking_receipt.action_reset_draft() # Mimic the extra cost on the po line picking_receipt.move_ids.price_unit = 50 picking_receipt.action_confirm() @@ -219,8 +220,9 @@ class TestAccountSubcontractingFlows(TestMrpSubcontractingCommon): receipt_form.partner_id = self.subcontractor_partner1 with receipt_form.move_ids_without_package.new() as move: move.product_id = self.finished - move.product_uom_qty = 10 + move.quantity_done = 10 receipt = receipt_form.save() + receipt.action_reset_draft() # add an extra cost receipt.move_ids.price_unit = 50 receipt.action_confirm() diff --git a/addons/point_of_sale/models/stock_picking.py b/addons/point_of_sale/models/stock_picking.py index 0f1ca5b7cc2..f5d2ecc0384 100644 --- a/addons/point_of_sale/models/stock_picking.py +++ b/addons/point_of_sale/models/stock_picking.py @@ -22,6 +22,7 @@ class StockPicking(models.Model): 'move_type': 'direct', 'location_id': location_id, 'location_dest_id': location_dest_id, + 'state': 'draft', } diff --git a/addons/product_expiry/tests/test_stock_lot.py b/addons/product_expiry/tests/test_stock_lot.py index 17b69fce8fa..f3af6d487f2 100644 --- a/addons/product_expiry/tests/test_stock_lot.py +++ b/addons/product_expiry/tests/test_stock_lot.py @@ -49,7 +49,9 @@ class TestStockLot(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, - 'location_dest_id': self.stock_location + 'location_dest_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, }) move_a = self.MoveObj.create({ @@ -145,6 +147,8 @@ class TestStockLot(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) move_b = self.MoveObj.create({ @@ -192,6 +196,8 @@ class TestStockLot(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) move_c = self.MoveObj.create({ @@ -336,9 +342,8 @@ class TestStockLot(TestStockCommon): picking_form.picking_type_id = self.env.ref('stock.picking_type_in') with picking_form.move_ids_without_package.new() as move: move.product_id = self.apple_product - move.product_uom_qty = 4 + move.quantity_done = 4 receipt = picking_form.save() - receipt.action_confirm() # Defines a date during the receipt. move = receipt.move_ids_without_package[0] @@ -346,7 +351,6 @@ class TestStockLot(TestStockCommon): self.assertEqual(move.use_expiration_date, True) line.lot_name = 'Apple Box #3' line.expiration_date = expiration_date - line.qty_done = 4 receipt._action_done() # Get back the lot created when the picking was done... diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index a5c946333e7..4aa5f7cea6f 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -227,6 +227,8 @@ class PurchaseOrder(models.Model): 'location_dest_id': self._get_destination_location(), 'location_id': self.partner_id.property_stock_supplier.id, 'company_id': self.company_id.id, + 'state': 'draft', + 'immediate_transfer': False, } def _create_picking(self): diff --git a/addons/purchase_stock/tests/test_average_price.py b/addons/purchase_stock/tests/test_average_price.py index 79121cf3d34..6295ced532e 100644 --- a/addons/purchase_stock/tests/test_average_price.py +++ b/addons/purchase_stock/tests/test_average_price.py @@ -97,6 +97,7 @@ class TestAveragePrice(ValuationReconciliationTestCommon): }) # Assign this outgoing shipment and process the delivery + outgoing_shipment.action_reset_draft() outgoing_shipment.action_assign() res = outgoing_shipment.button_validate() Form(self.env['stock.immediate.transfer'].with_context(res['context'])).save().process() diff --git a/addons/purchase_stock/tests/test_create_picking.py b/addons/purchase_stock/tests/test_create_picking.py index 592c1045556..cd4fe98058a 100644 --- a/addons/purchase_stock/tests/test_create_picking.py +++ b/addons/purchase_stock/tests/test_create_picking.py @@ -273,8 +273,8 @@ class TestCreatePicking(common.TestProductCommon): 'procure_method': 'make_to_order', 'picking_id': customer_picking.id, }) - - customer_move._action_confirm() + customer_picking.action_reset_draft() + customer_picking.action_confirm() purchase_order = self.env['purchase.order'].search([('partner_id', '=', partner.id)]) self.assertTrue(purchase_order, 'No purchase order created.') @@ -420,7 +420,8 @@ class TestCreatePicking(common.TestProductCommon): 'picking_id': delivery_order.id, }) - customer_move._action_confirm() + delivery_order.action_reset_draft() + delivery_order.action_confirm() # find created po the product purchase_order = self.env['purchase.order'].search([('partner_id', '=', partner.id)]) diff --git a/addons/purchase_stock/tests/test_fifo_price.py b/addons/purchase_stock/tests/test_fifo_price.py index efa2f5262cb..58a918ad08e 100644 --- a/addons/purchase_stock/tests/test_fifo_price.py +++ b/addons/purchase_stock/tests/test_fifo_price.py @@ -99,6 +99,7 @@ class TestFifoPrice(ValuationReconciliationTestCommon): }) # I assign this outgoing shipment + outgoing_shipment.action_reset_draft() outgoing_shipment.action_assign() # Process the delivery of the outgoing shipment @@ -124,6 +125,7 @@ class TestFifoPrice(ValuationReconciliationTestCommon): }) # I assign this outgoing shipment + outgoing_shipment_uom.action_reset_draft() outgoing_shipment_uom.action_assign() # Process the delivery of the outgoing shipment @@ -184,6 +186,7 @@ class TestFifoPrice(ValuationReconciliationTestCommon): }) # I assign this outgoing shipment + outgoing_shipment_cur.action_reset_draft() outgoing_shipment_cur.action_assign() # Process the delivery of the outgoing shipment @@ -206,6 +209,7 @@ class TestFifoPrice(ValuationReconciliationTestCommon): }) # I assign this outgoing shipment + outgoing_shipment_ret.action_reset_draft() outgoing_shipment_ret.action_assign() res = outgoing_shipment_ret.button_validate() Form(self.env[res['res_model']].with_context(res['context'])).save().process() diff --git a/addons/purchase_stock/tests/test_move_cancel_propagation.py b/addons/purchase_stock/tests/test_move_cancel_propagation.py index 8fb48eda7c3..8ef2964f873 100644 --- a/addons/purchase_stock/tests/test_move_cancel_propagation.py +++ b/addons/purchase_stock/tests/test_move_cancel_propagation.py @@ -52,6 +52,7 @@ class TestMoveCancelPropagation(PurchaseTestCommon): self.warehouse.write({'delivery_steps': 'ship_only', 'reception_steps': 'one_step'}) self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) + self.picking_out.action_reset_draft() self.picking_out.action_confirm() # Find PO related to picking. @@ -81,6 +82,7 @@ class TestMoveCancelPropagation(PurchaseTestCommon): self.warehouse.write({'delivery_steps': 'ship_only', 'reception_steps': 'one_step'}) self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) + self.picking_out.action_reset_draft() self.picking_out.action_confirm() # Find PO related to picking. @@ -111,6 +113,7 @@ class TestMoveCancelPropagation(PurchaseTestCommon): self.warehouse.write({'delivery_steps': 'pick_ship', 'reception_steps': 'two_steps'}) self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) + self.picking_out.action_reset_draft() self.picking_out.action_confirm() # Find purchase order related to picking. @@ -145,6 +148,7 @@ class TestMoveCancelPropagation(PurchaseTestCommon): self.warehouse.write({'delivery_steps': 'pick_ship', 'reception_steps': 'two_steps'}) self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) + self.picking_out.action_reset_draft() self.picking_out.action_confirm() # Find PO related to picking. @@ -183,6 +187,7 @@ class TestMoveCancelPropagation(PurchaseTestCommon): self.warehouse.write({'delivery_steps': 'pick_pack_ship', 'reception_steps': 'three_steps'}) self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) + self.picking_out.action_reset_draft() self.picking_out.action_confirm() # Find PO related to picking. @@ -219,6 +224,7 @@ class TestMoveCancelPropagation(PurchaseTestCommon): self.warehouse.write({'delivery_steps': 'pick_pack_ship', 'reception_steps': 'three_steps'}) self.picking_out.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) self.move.write({'location_id': self.warehouse.out_type_id.default_location_src_id.id}) + self.picking_out.action_reset_draft() self.picking_out.action_confirm() # Find PO related to picking. diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index 865cf48768c..e484cb30e01 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -66,10 +66,8 @@ class TestReorderingRule(TransactionCase): picking_form.picking_type_id = self.env.ref('stock.picking_type_out') with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_01 - move.product_uom_qty = 10.0 + move.quantity_done = 10.0 customer_picking = picking_form.save() - # picking confirm - customer_picking.action_confirm() # Run scheduler self.env['procurement.group'].run_scheduler() @@ -143,16 +141,15 @@ class TestReorderingRule(TransactionCase): picking_form.picking_type_id = self.env.ref('stock.picking_type_out') with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_01 - move.product_uom_qty = 10.0 + move.quantity_done = 10.0 with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_01 - move.product_uom_qty = 10.0 + move.quantity_done = 10.0 customer_picking = picking_form.save() customer_picking.move_ids[0].location_id = subloc_1.id customer_picking.move_ids[1].location_id = subloc_2.id # picking confirm - customer_picking.action_confirm() self.assertEqual(self.product_01.with_context(location=subloc_1.id).virtual_available, -10) self.assertEqual(self.product_01.with_context(location=subloc_2.id).virtual_available, -10) @@ -305,6 +302,7 @@ class TestReorderingRule(TransactionCase): move.product_uom_qty = 10.0 customer_picking = picking_form.save() customer_picking.move_ids.filtered(lambda m: m.product_id == product_buy_mto).procure_method = 'make_to_order' + customer_picking.action_reset_draft() customer_picking.action_confirm() self.env['stock.warehouse.orderpoint']._get_orderpoint_action() self.env['stock.warehouse.orderpoint']._get_orderpoint_action() @@ -348,6 +346,7 @@ class TestReorderingRule(TransactionCase): move.product_uom_qty = 10.0 customer_picking = picking_form.save() customer_picking.move_ids.filtered(lambda m: m.product_id == product_buy_mto).procure_method = 'make_to_order' + customer_picking.action_reset_draft() customer_picking.action_confirm() self.env['stock.warehouse.orderpoint'].flush_model() @@ -403,6 +402,7 @@ class TestReorderingRule(TransactionCase): move.product_uom_qty = 10.0 customer_picking = picking_form.save() customer_picking.move_ids.filtered(lambda m: m.product_id == product_buy_mto).procure_method = 'make_to_order' + customer_picking.action_reset_draft() customer_picking.action_confirm() self.env['stock.warehouse.orderpoint']._get_orderpoint_action() orderpoint_product = self.env['stock.warehouse.orderpoint'].search( @@ -445,6 +445,7 @@ class TestReorderingRule(TransactionCase): move.product_uom_qty = 10.0 customer_picking = picking_form.save() customer_picking.move_ids.filtered(lambda m: m.product_id == product_buy_mto).procure_method = 'make_to_order' + customer_picking.action_reset_draft() customer_picking.action_confirm() self.env['stock.warehouse.orderpoint'].flush_model() @@ -959,8 +960,11 @@ class TestReorderingRule(TransactionCase): 'product_uom_qty': 1, 'location_id': warehouse.lot_stock_id.id, 'location_dest_id': self.env.ref('stock.stock_location_customers').id, - })] + })], + 'state': 'draft', + 'immediate_transfer': False, }) + picking.with_user(user).action_reset_draft() picking.with_user(user).action_assign() # check that the PO line quantity has been updated self.assertEqual(po_line.product_qty, 6, 'The PO line quantity should be 6') diff --git a/addons/purchase_stock/tests/test_stockvaluation.py b/addons/purchase_stock/tests/test_stockvaluation.py index 7cad22d8c0b..fe5c6fa5f86 100644 --- a/addons/purchase_stock/tests/test_stockvaluation.py +++ b/addons/purchase_stock/tests/test_stockvaluation.py @@ -1624,7 +1624,10 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon): 'location_id': stock_location.id, 'location_dest_id': customer_location.id, })], + 'state': 'draft', + 'immediate_transfer': False, }) + delivery01.action_reset_draft() delivery01.action_confirm() delivery01.move_ids._set_quantities_to_reservation() delivery01.button_validate() @@ -1695,7 +1698,10 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon): 'location_id': stock_location.id, 'location_dest_id': customer_location.id, })], + 'state': 'draft', + 'immediate_transfer': False, }) + delivery02.action_reset_draft() delivery02.action_confirm() delivery02.move_ids._set_quantities_to_reservation() delivery02.button_validate() @@ -1748,7 +1754,10 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon): 'location_id': stock_location.id, 'location_dest_id': customer_location.id, })], + 'state': 'draft', + 'immediate_transfer': False, }) + delivery.action_reset_draft() delivery.action_confirm() delivery.move_ids._set_quantities_to_reservation() delivery.button_validate() diff --git a/addons/sale_stock_margin/tests/test_sale_stock_margin.py b/addons/sale_stock_margin/tests/test_sale_stock_margin.py index 009d9086278..5654893471c 100644 --- a/addons/sale_stock_margin/tests/test_sale_stock_margin.py +++ b/addons/sale_stock_margin/tests/test_sale_stock_margin.py @@ -274,6 +274,7 @@ class TestSaleStockMargin(TestStockValuationCommon): 'picking_type_id': incoming_picking_type.id, 'picking_id': picking.id, }) + picking.action_reset_draft() picking.action_confirm() res_dict = picking.button_validate() wizard = Form(self.env[(res_dict.get('res_model'))].with_context(res_dict['context'])).save() diff --git a/addons/stock/data/stock_demo2.xml b/addons/stock/data/stock_demo2.xml index 86f9f5c19cf..e644230b529 100644 --- a/addons/stock/data/stock_demo2.xml +++ b/addons/stock/data/stock_demo2.xml @@ -86,6 +86,8 @@ + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False + draft + False 1: @@ -681,7 +680,10 @@ Please change the quantity done or the rounding precision of your unit of measur (self - move_to_unreserve).filtered(lambda m: m.state == 'assigned').write({'state': 'partially_available'}) # When editing the initial demand, directly run again action assign on receipt moves. receipt_moves_to_reassign |= move_to_unreserve.filtered(lambda m: m.location_id.usage == 'supplier') - receipt_moves_to_reassign |= (self - move_to_unreserve).filtered(lambda m: m.location_id.usage == 'supplier' and m.state in ('partially_available', 'assigned')) + receipt_moves_to_reassign |= (self - move_to_unreserve).filtered(lambda m: + m.location_id.usage == 'supplier' + and m.state in ('partially_available', 'assigned') + and not m.picking_id.immediate_transfer) move_to_recompute_state |= self - move_to_unreserve - receipt_moves_to_reassign # propagate product_packaging_id changes in the stock move chain if 'product_packaging_id' in vals: @@ -784,7 +786,7 @@ Please change the quantity done or the rounding precision of your unit of measur show_source_location=self.picking_type_id.code != 'incoming', show_destination_location=self.picking_type_id.code != 'outgoing', show_package=not self.location_id.usage == 'supplier', - show_reserved_quantity=self.state != 'done' and not self.picking_id.immediate_transfer and self.picking_type_id.code != 'incoming' + show_reserved_quantity=self.state != 'done' and self.picking_type_id.code != 'incoming' ), } @@ -1194,7 +1196,6 @@ Please change the quantity done or the rounding precision of your unit of measur ('location_dest_id', '=', self.location_dest_id.id), ('picking_type_id', '=', self.picking_type_id.id), ('printed', '=', False), - ('immediate_transfer', '=', False), ('state', 'in', ['draft', 'confirmed', 'waiting', 'partially_available', 'assigned'])] if self.partner_id and (self.location_id.usage == 'transit' or self.location_dest_id.usage == 'transit'): domain += [('partner_id', '=', self.partner_id.id)] @@ -1328,6 +1329,8 @@ Please change the quantity done or the rounding precision of your unit of measur 'picking_type_id': self.mapped('picking_type_id').id, 'location_id': self.mapped('location_id').id, 'location_dest_id': self.mapped('location_dest_id').id, + 'state': 'draft', + 'immediate_transfer': False, } def _should_be_assigned(self): @@ -1408,8 +1411,7 @@ Please change the quantity done or the rounding precision of your unit of measur neg_r_moves._assign_picking() # call `_action_assign` on every confirmed move which location_id bypasses the reservation + those expected to be auto-assigned - moves.filtered(lambda move: not move.picking_id.immediate_transfer - and move.state in ('confirmed', 'partially_available') + moves.filtered(lambda move: move.state in ('confirmed', 'partially_available') and (move._should_bypass_reservation() or move.picking_type_id.reservation_method == 'at_confirm' or (move.reservation_date and move.reservation_date <= fields.Date.today())))\ @@ -1676,7 +1678,7 @@ Please change the quantity done or the rounding precision of your unit of measur assigned_moves_ids.add(move.id) moves_to_redirect.add(move.id) else: - if float_is_zero(move.product_uom_qty, precision_rounding=move.product_uom.rounding): + if float_is_zero(move.product_uom_qty, precision_rounding=move.product_uom.rounding) and not force_qty: assigned_moves_ids.add(move.id) elif not move.move_orig_ids: if move.procure_method == 'make_to_order': @@ -1876,8 +1878,8 @@ Please change the quantity done or the rounding precision of your unit of measur @api.ondelete(at_uninstall=False) def _unlink_if_draft_or_cancel(self): - if any(move.state not in ('draft', 'cancel') for move in self): - raise UserError(_('You can only delete draft or cancelled moves.')) + if any(move.state not in ('draft', 'cancel') and (move.move_orig_ids or move.move_dest_ids) for move in self): + raise UserError(_('You can not delete moves linked to another operation')) def unlink(self): # With the non plannified picking, draft moves could have some move lines. @@ -2112,10 +2114,6 @@ Please change the quantity done or the rounding precision of your unit of measur else: move.procure_method = 'make_to_order' - def _show_details_in_draft(self): - self.ensure_one() - return self.state != 'draft' or (self.picking_id.immediate_transfer and self.state == 'draft') - def _trigger_scheduler(self): """ Check for auto-triggered orderpoints and trigger them. """ if not self or self.env['ir.config_parameter'].sudo().get_param('stock.no_auto_scheduler'): diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index cecf6d0e0d5..99d69a957e3 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -313,7 +313,7 @@ class Picking(models.Model): ('assigned', 'Ready'), ('done', 'Done'), ('cancel', 'Cancelled'), - ], string='Status', compute='_compute_state', + ], string='Status', compute='_compute_state', default='assigned', copy=False, index=True, readonly=True, store=True, tracking=True, help=" * Draft: The transfer is not confirmed yet. Reservation doesn't apply.\n" " * Waiting another operation: This transfer is waiting for another operation before being ready.\n" @@ -365,8 +365,7 @@ class Picking(models.Model): picking_type_id = fields.Many2one( 'stock.picking.type', 'Operation Type', required=True, readonly=True, index=True, - default=_default_picking_type_id, - states={'draft': [('readonly', False)]}) + default=_default_picking_type_id) picking_type_code = fields.Selection( related='picking_type_id.code', readonly=True) @@ -400,9 +399,6 @@ class Picking(models.Model): show_check_availability = fields.Boolean( compute='_compute_show_check_availability', help='Technical field used to compute whether the button "Check Availability" should be displayed.') - show_mark_as_todo = fields.Boolean( - compute='_compute_show_mark_as_todo', - help='Technical field used to compute whether the button "Mark as Todo" should be displayed.') show_validate = fields.Boolean( compute='_compute_show_validate', help='Technical field used to decide whether the button "Validate" should be displayed.') @@ -426,7 +422,7 @@ class Picking(models.Model): show_reserved = fields.Boolean(related='picking_type_id.show_reserved') show_lots_text = fields.Boolean(compute='_compute_show_lots_text') has_tracking = fields.Boolean(compute='_compute_has_tracking') - immediate_transfer = fields.Boolean(default=False) + immediate_transfer = fields.Boolean(default=True) package_level_ids = fields.One2many('stock.package_level', 'picking_id') package_level_ids_details = fields.One2many('stock.package_level', 'picking_id') products_availability = fields.Char( @@ -443,14 +439,14 @@ class Picking(models.Model): ('name_uniq', 'unique(name, company_id)', 'Reference must be unique per company!'), ] - @api.depends('show_validate', 'immediate_transfer', + @api.depends('show_validate', 'move_ids.reserved_availability', 'move_ids.quantity_done') def _compute_show_qty_button(self): self.show_set_qty_button = False self.show_clear_qty_button = False for picking in self: - if not picking.show_validate or picking.immediate_transfer: + if not picking.show_validate: continue if any(float_is_zero(m.quantity_done, precision_rounding=m.product_uom.rounding) and not float_is_zero(m.reserved_availability, precision_rounding=m.product_uom.rounding) for m in picking.move_ids): picking.show_set_qty_button = True @@ -511,7 +507,7 @@ class Picking(models.Model): picking.show_operations = True continue if picking.picking_type_id.show_operations: - if (picking.state == 'draft' and picking.immediate_transfer) or picking.state != 'draft': + if (picking.state == 'draft') or picking.state != 'draft': picking.show_operations = True else: picking.show_operations = False @@ -545,7 +541,7 @@ class Picking(models.Model): ] }) - @api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id') + @api.depends('move_type', 'move_ids.state', 'move_ids.picking_id') def _compute_state(self): ''' State of a picking depends on the state of its related stock.move - Draft: only used for "planned pickings" @@ -574,7 +570,9 @@ class Picking(models.Model): picking_move_lines[picking_id.id].add(move.id) for picking in self: picking_id = (picking.ids and picking.ids[0]) or picking.id - if not picking_moves_state_map[picking_id]: + if not picking_moves_state_map[picking_id] and picking.immediate_transfer: + continue + elif not picking_moves_state_map[picking_id]: picking.state = 'draft' elif picking_moves_state_map[picking_id]['any_draft']: picking.state = 'draft' @@ -633,13 +631,13 @@ class Picking(models.Model): for picking in self: picking.has_packages = bool(cnt_by_picking.get(picking.id, False)) - @api.depends('immediate_transfer', 'state') + @api.depends('state') def _compute_show_check_availability(self): """ According to `picking.show_check_availability`, the "check availability" button will be displayed in the form view of a picking. """ for picking in self: - if picking.immediate_transfer or picking.state not in ('confirmed', 'waiting', 'assigned'): + if picking.state not in ('confirmed', 'waiting', 'assigned'): picking.show_check_availability = False continue picking.show_check_availability = any( @@ -648,24 +646,15 @@ class Picking(models.Model): for move in picking.move_ids ) - @api.depends('state', 'move_ids') - def _compute_show_mark_as_todo(self): - for picking in self: - if picking.immediate_transfer or picking.state != 'draft': - picking.show_mark_as_todo = False - else: - picking.show_mark_as_todo = True - @api.depends('state') def _compute_show_validate(self): for picking in self: - if not (picking.immediate_transfer) and picking.state == 'draft': + if picking.state == 'draft': picking.show_validate = False elif picking.state not in ('draft', 'waiting', 'confirmed', 'assigned'): picking.show_validate = False else: picking.show_validate = True - @api.depends('state', 'move_ids', 'picking_type_id') def _compute_show_allocation(self): self.show_allocation = False @@ -678,7 +667,7 @@ class Picking(models.Model): def _compute_location_id(self): for picking in self: picking = picking.with_company(picking.company_id) - if picking.picking_type_id and picking.state == 'draft': + if picking.picking_type_id: if picking.picking_type_id.default_location_src_id: location_id = picking.picking_type_id.default_location_src_id.id elif picking.partner_id: @@ -776,6 +765,12 @@ class Picking(models.Model): # order to get a determinist execution of `_set_scheduled_date` scheduled_dates.append(vals.pop('scheduled_date', False)) + # immediate transfer is a default value allow in specific cases (interface only) + if vals.get('state', 'assigned') != 'assigned': + vals['immediate_transfer'] = False + if self.env['ir.config_parameter'].sudo().get_param('stock.no_default_immediate_tranfer'): + vals['immediate_transfer'] = False + pickings = super().create(vals_list) for picking, scheduled_date in zip(pickings, scheduled_dates): @@ -842,6 +837,8 @@ class Picking(models.Model): def action_confirm(self): self._check_company() + if not self.env.context.get('skip_draft'): + self.filtered(lambda p: p.state in ['assigned', 'draft'] and p.immediate_transfer).action_reset_draft() self.mapped('package_level_ids').filtered(lambda pl: pl.state == 'draft' and not pl.move_ids)._generate_moves() # call `_action_confirm` on every draft move self.move_ids.filtered(lambda move: move.state == 'draft')._action_confirm() @@ -856,6 +853,7 @@ class Picking(models.Model): also impact the state of the picking as it is computed based on move's states. @return: True """ + self.mapped('package_level_ids').filtered(lambda pl: pl.state == 'draft' and not pl.move_ids)._generate_moves() self.filtered(lambda picking: picking.state == 'draft').action_confirm() moves = self.move_ids.filtered(lambda move: move.state not in ('draft', 'cancel', 'done')).sorted( key=lambda move: (-int(move.priority), not bool(move.date_deadline), move.date_deadline, move.date, move.id) @@ -877,6 +875,13 @@ class Picking(models.Model): self.filtered(lambda x: not x.move_ids).state = 'cancel' return True + def action_reset_draft(self): + picking_to_reset = self.filtered(lambda p: p.state not in ('done', 'cancel')) + picking_to_reset.do_unreserve() + picking_to_reset.immediate_transfer = False + picking_to_reset.move_ids.quantity_done = 0 + picking_to_reset.move_ids.state = 'draft' + def _action_done(self): """Call `_action_done` on the `stock.move` of the `stock.picking` in `self`. This method makes sure every `stock.move.line` is linked to a `stock.move` by either @@ -936,7 +941,7 @@ class Picking(models.Model): else: for move in self.move_ids: if not move.package_level_id: - if move.state == 'assigned' and move.picking_id and not move.picking_id.immediate_transfer or move.state == 'done': + if move.state == 'assigned' and move.picking_id or move.state == 'done': if any(not ml.package_level_id for ml in move.move_line_ids): move_ids_without_package |= move else: @@ -1223,9 +1228,8 @@ class Picking(models.Model): continue if not picking.move_ids and not picking.package_level_ids: continue - if picking.immediate_transfer or any(move.additional for move in picking.move_ids): - picking.action_confirm() - # Make sure the reservation is bypassed in immediate transfer mode. + if any(move.additional for move in picking.move_ids): + picking.with_context(skip_draft=picking.immediate_transfer).action_confirm() if picking.immediate_transfer: picking.move_ids.write({'state': 'assigned'}) @@ -1498,7 +1502,6 @@ class Picking(models.Model): picking_move_lines = self.move_line_ids if ( not self.picking_type_id.show_reserved - and not self.immediate_transfer and not self.env.context.get('barcode_view') ): picking_move_lines = self.move_line_nosuggest_ids diff --git a/addons/stock/tests/test_generate_serial_numbers.py b/addons/stock/tests/test_generate_serial_numbers.py index 126e9095a1a..3b33f2be071 100644 --- a/addons/stock/tests/test_generate_serial_numbers.py +++ b/addons/stock/tests/test_generate_serial_numbers.py @@ -507,6 +507,8 @@ class StockGenerate(StockGenerateCommon): 'picking_type_id': self.warehouse.in_type_id.id, 'location_id': self.env.ref('stock.stock_location_suppliers').id, 'location_dest_id': stock_location.id, + 'state': 'draft', + 'immediate_transfer': False, }) move = self.env['stock.move'].create({ 'name': self.product_serial.name, diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 5c816e82b6c..1184dfb7e17 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -2670,6 +2670,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, 'picking_type_id': self.env.ref('stock.picking_type_internal').id, + 'state': 'draft', + 'immediate_transfer': False, }) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_7', @@ -2684,6 +2686,8 @@ class StockMove(TransactionCase): 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move_pack_cust = self.env['stock.move'].create({ 'name': 'test_link_assign_7', @@ -2783,6 +2787,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, 'picking_type_id': self.env.ref('stock.picking_type_internal').id, + 'state': 'draft', + 'immediate_transfer': False, }) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_7', @@ -2797,6 +2803,8 @@ class StockMove(TransactionCase): 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move_pack_cust = self.env['stock.move'].create({ 'name': 'test_link_assign_7', @@ -2850,6 +2858,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, 'picking_type_id': self.env.ref('stock.picking_type_internal').id, + 'state': 'draft', + 'immediate_transfer': False, }) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_9', @@ -2864,6 +2874,8 @@ class StockMove(TransactionCase): 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move_pack_cust = self.env['stock.move'].create({ 'name': 'test_link_assign_0', @@ -3216,6 +3228,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.customer_location.id, 'partner_id': customer.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) p01_move = self.env['stock.move'].create({ @@ -4062,6 +4076,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.stock_location.id, 'partner_id': owner.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) # move from shelf1 move1 = self.env['stock.move'].create({ @@ -4213,6 +4229,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.stock_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test_immediate_validate_1', @@ -4245,6 +4263,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.customer_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test_immediate_validate_2', @@ -4292,6 +4312,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, 'picking_type_id': self.env.ref('stock.picking_type_internal').id, + 'state': 'draft', + 'immediate_transfer': False, }) product1_move = self.env['stock.move'].create({ 'name': 'product1_move', @@ -4349,6 +4371,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.customer_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) # move from shelf1 self.env['stock.move'].create({ @@ -4382,6 +4406,8 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_type_id': picking_type_id.id, + 'immediate_transfer': False, + 'state': 'draft', }) self.env['stock.move'].create({ 'name': 'move1', @@ -4437,6 +4463,8 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_type_id': picking_type.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'product1_move', @@ -4481,6 +4509,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.customer_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test_immediate_validate_2', @@ -4514,6 +4544,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.stock_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test_immediate_validate_8_1', @@ -4530,6 +4562,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.stock_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test_immediate_validate_8_2', @@ -4546,6 +4580,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.stock_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test_immediate_validate_8_3', @@ -4584,8 +4620,12 @@ class StockMove(TransactionCase): picking_type_receipt.use_create_lots = False picking_type_receipt.use_existing_lots = False - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = picking_type_receipt + internal_transfer = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': picking_type_receipt.id, + }) + picking_form = Form(internal_transfer) with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_serial move.product_uom_qty = 4 @@ -4617,8 +4657,12 @@ class StockMove(TransactionCase): 'company_id': self.env.company.id, }) self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 10, lot_id=lot) - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = picking_type_internal + internal_transfer = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': picking_type_internal.id, + }) + picking_form = Form(internal_transfer) with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_lot move.product_uom_qty = 4 @@ -4666,7 +4710,7 @@ class StockMove(TransactionCase): 'product_uom': self.uom_unit.id, }) self.assertEqual(move1.state, 'draft') - self.assertEqual(move1.product_uom_qty, 1) + self.assertEqual(move1.product_uom_qty, 0) move1.product_uom_qty = 100 move1.product_id = self.product_serial move1._onchange_product_id() @@ -4748,6 +4792,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.customer_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'A move to confirm and scrap its product', @@ -4793,6 +4839,8 @@ class StockMove(TransactionCase): 'location_dest_id': self.customer_location.id, 'partner_id': partner.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'A move to confirm and scrap its product', @@ -4896,6 +4944,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': scrap_location.id, 'picking_type_id': internal_operation.id, + 'state': 'draft', + 'immediate_transfer': False, 'move_ids': [(0, 0, { 'name': 'Scrap %s' % product.display_name, 'location_id': self.stock_location.id, @@ -5241,7 +5291,6 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, - 'immediate_transfer': True, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5266,6 +5315,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5360,6 +5411,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5402,6 +5455,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5445,6 +5500,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5492,6 +5549,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5557,8 +5616,12 @@ class StockMove(TransactionCase): }]).action_apply_inventory() # Creates a delivery for a bunch of products. - delivery_form = Form(self.env['stock.picking']) - delivery_form.picking_type_id = self.env.ref('stock.picking_type_out') + delivery_form = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': self.env.ref('stock.picking_type_out').id, + }) + delivery_form = Form(delivery_form) with delivery_form.move_ids_without_package.new() as move: move.product_id = self.product move.product_uom_qty = 10 @@ -5681,6 +5744,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5736,6 +5801,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5780,6 +5847,8 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -5893,7 +5962,10 @@ class StockMove(TransactionCase): picking_out = self.env['stock.picking'].create({ 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': self.stock_location.id, - 'location_dest_id': self.customer_location.id}) + 'location_dest_id': self.customer_location.id, + 'state': 'draft', + 'immediate_transfer': False, + }) move = self.env['stock.move'].create({ 'name': product.name, 'product_id': product.id, @@ -5928,6 +6000,8 @@ class StockMove(TransactionCase): 'picking_type_id': internal_transfer.id, 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': self.product_consu.name, @@ -6012,6 +6086,8 @@ class StockMove(TransactionCase): 'picking_type_id': internal_transfer.id, 'location_id': stock_location.id, 'location_dest_id': shelf_location.id, + 'state': 'draft', + 'immediate_transfer': False, 'move_line_nosuggest_ids': [Command.create({ 'product_id': self.product.id, 'qty_done': 1.0 @@ -6047,7 +6123,7 @@ class StockMove(TransactionCase): """ Since updating the move's `lot_ids` field for product tracked by serial numbers will also updates the move's `quantity_done`, this test checks the move's move lines will be - correclty updated and consequently its picking can be validated. + correctly updated and consequently its picking can be validated. """ sn = self.env['stock.lot'].create({ 'name': 'test_lot_001', @@ -6055,8 +6131,12 @@ class StockMove(TransactionCase): 'company_id': self.env.company.id, }) - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = self.env.ref('stock.picking_type_in') + internal_transfer = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + }) + picking_form = Form(internal_transfer) with picking_form.move_ids_without_package.new() as move: move.product_id = self.product_serial move.product_uom_qty = 1 diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index e239513df14..2b26eb9dbc5 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -18,6 +18,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) dest = self.MoveObj.create({ @@ -36,6 +38,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ @@ -56,6 +60,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) ship = self.MoveObj.create({ @@ -72,6 +78,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) pack = self.MoveObj.create({ @@ -89,6 +97,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ @@ -386,6 +396,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) dest = self.MoveObj.create({ 'name': self.gB.name, @@ -402,6 +414,8 @@ class TestPickShip(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ @@ -817,6 +831,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -857,6 +873,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -895,6 +913,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -939,6 +959,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -986,6 +1008,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) # Avoid to merge move3 and move4 for the test case self.env['ir.config_parameter'].create({ @@ -1073,6 +1097,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1118,6 +1144,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1162,6 +1190,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1200,6 +1230,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1244,6 +1276,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) product = self.kgB self.MoveObj.create({ @@ -1277,6 +1311,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1331,6 +1367,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1389,6 +1427,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1449,6 +1489,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1504,6 +1546,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1537,6 +1581,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1577,6 +1623,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1617,6 +1665,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1661,6 +1711,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1708,6 +1760,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1753,6 +1807,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) move_1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1795,6 +1851,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': warehouse.wh_input_stock_loc_id.id, 'picking_type_id': warehouse.in_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) move_receipt_1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1809,6 +1867,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': warehouse.wh_input_stock_loc_id.id, 'picking_type_id': warehouse.in_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) move_receipt_2 = self.MoveObj.create({ 'name': self.productA.name, @@ -1855,6 +1915,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': warehouse.wh_input_stock_loc_id.id, 'picking_type_id': warehouse.in_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) move_receipt_1 = self.MoveObj.create({ 'name': self.productA.name, @@ -1869,6 +1931,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': warehouse.wh_input_stock_loc_id.id, 'location_dest_id': warehouse.wh_qc_stock_loc_id.id, 'picking_type_id': warehouse.int_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) move1_receipt_2 = self.MoveObj.create({ 'name': self.productB.name, @@ -1913,6 +1977,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -1947,6 +2013,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) move_a = self.MoveObj.create({ 'name': self.productA.name, @@ -1982,10 +2050,10 @@ class TestSinglePicking(TestStockCommon): picking.picking_type_id = ptout with picking.move_ids_without_package.new() as move: move.product_id = self.productA - move.product_uom_qty = 10 + move.quantity_done = 10 picking = picking.save() - self.assertEqual(picking.immediate_transfer, False) - self.assertEqual(picking.state, 'draft') + self.assertEqual(picking.immediate_transfer, True) + self.assertEqual(picking.state, 'assigned') picking = Form(picking) picking.move_ids_without_package.remove(0) @@ -2001,6 +2069,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) move_1 = self.MoveObj.create({ 'name': self.productA.name, @@ -2033,6 +2103,8 @@ class TestSinglePicking(TestStockCommon): 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, 'move_type': 'one', + 'state': 'draft', + 'immediate_transfer': False, }) move_3 = self.MoveObj.create({ 'name': self.productA.name, @@ -2056,13 +2128,11 @@ class TestSinglePicking(TestStockCommon): # The autocoform ran, the picking shoud be confirmed and reservable. self.assertEqual(delivery_order.state, 'confirmed') - self.assertEqual(delivery_order.show_mark_as_todo, False) self.assertEqual(delivery_order.show_check_availability, True) delivery_order.action_assign() self.assertEqual(delivery_order.state, 'assigned') self.assertEqual(delivery_order.show_check_availability, False) - self.assertEqual(delivery_order.show_mark_as_todo, False) stock_location = self.env['stock.location'].browse(self.stock_location) self.assertEqual(self.env['stock.quant']._gather(self.productA, stock_location).reserved_quantity, 10.0) @@ -2077,7 +2147,6 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, - 'immediate_transfer': True, 'move_ids_without_package': [(0, 0, { 'name': self.productA.name, 'product_id': self.productA.id, @@ -2097,7 +2166,6 @@ class TestSinglePicking(TestStockCommon): self.assertEqual(delivery_order.state, 'assigned') self.assertEqual(delivery_order.show_check_availability, False) - self.assertEqual(delivery_order.show_mark_as_todo, False) def test_owner_1(self): # Required for `owner_id` to be visible in the view @@ -2108,6 +2176,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) move1 = self.env['stock.move'].create({ 'name': self.productA.name, @@ -2180,7 +2250,7 @@ class TestSinglePicking(TestStockCommon): # Checks receipt has still its destination location and checks its move # line took the one from the putaway rule. self.assertEqual(receipt.location_dest_id.id, stock_location.id) - self.assertEqual(receipt.move_line_ids.location_dest_id.id, shelf_location.id) + self.assertEqual(receipt.move_line_nosuggest_ids.location_dest_id.id, shelf_location.id) def test_cancel_plan_transfer(self): """ Test canceling plan transfer """ @@ -2189,6 +2259,8 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, 'move_ids': [(0, 0, { 'name': self.productA.name, 'product_id': self.productA.id, @@ -2214,7 +2286,6 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, - 'immediate_transfer': True, 'move_line_ids': [(0, 0, { 'product_id': self.productA.id, 'qty_done': 10, @@ -2236,7 +2307,6 @@ class TestSinglePicking(TestStockCommon): 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, - 'immediate_transfer': True, 'move_line_ids': [(0, 0, { 'product_id': self.productA.id, 'product_uom_id': self.productA.uom_id.id, @@ -2287,7 +2357,9 @@ class TestStockUOM(TestStockCommon): picking_in = self.env['stock.picking'].create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, - 'location_dest_id': self.stock_location + 'location_dest_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, }) move = self.env['stock.move'].create({ 'name': 'First move with 60 GT', @@ -2355,6 +2427,8 @@ class TestStockUOM(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.env.ref('stock.picking_type_out').id, + 'state': 'draft', + 'immediate_transfer': False, }) move = self.env['stock.move'].create({ @@ -3237,6 +3311,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.pack_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) dest = self.MoveObj.create({ @@ -3255,6 +3331,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ @@ -3284,6 +3362,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) customer_move = self.env['stock.move'].create({ 'name': 'customer move', @@ -3305,6 +3385,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.customer_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) supplier_move = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -3342,6 +3424,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'picking_type_id': self.picking_type_out, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -3390,6 +3474,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.stock_location, 'location_dest_id': self.customer_location, 'picking_type_id': picking_type_out1.id, + 'state': 'draft', + 'immediate_transfer': False, }) # 'by_date' picking w/ 1 day before scheduled date auto-assign setting, set to 5 days in advance => shouldn't auto-assign @@ -3450,6 +3536,8 @@ class TestAutoAssign(TestStockCommon): 'location_id': self.customer_location, 'location_dest_id': self.stock_location, 'picking_type_id': self.picking_type_in, + 'state': 'draft', + 'immediate_transfer': False, }) supplier_move = self.env['stock.move'].create({ 'name': 'test_transit_1', @@ -3529,27 +3617,3 @@ class TestAutoAssign(TestStockCommon): move.lot_ids = [(4, lot2.id)] move.lot_ids = [(4, lot3.id)] self.assertEqual(move.quantity_done, 3.0/12.0) - - def test_update_description(self): - """ Create an empty picking. Adds a move on product1, select the picking type, add - again a move on product1. Confirm the picking. The two stock moves should be merged. """ - product1 = self.env['product.product'].create({ - 'name': 'product', - 'type':'product', - }) - picking_form = Form(self.env['stock.picking']) - with picking_form.move_ids_without_package.new() as move: - move.product_id = product1 - move.product_uom_qty = 10 - move.location_id = self.env.ref('stock.stock_location_suppliers') - move.location_dest_id = self.env.ref('stock.stock_location_stock') - picking_form.picking_type_id = self.env.ref('stock.picking_type_in') - with picking_form.move_ids_without_package.new() as move: - move.product_id = product1 - move.product_uom_qty = 15 - - picking = picking_form.save() - picking.action_confirm() - - self.assertEqual(len(picking.move_ids), 1) - self.assertEqual(picking.move_ids.product_uom_qty, 25) diff --git a/addons/stock/tests/test_multicompany.py b/addons/stock/tests/test_multicompany.py index fecb33c0068..133e7140540 100644 --- a/addons/stock/tests/test_multicompany.py +++ b/addons/stock/tests/test_multicompany.py @@ -196,6 +196,8 @@ class TestMultiCompany(TransactionCase): 'picking_type_id': self.warehouse_a.in_type_id.id, 'location_id': self.env.ref('stock.stock_location_suppliers').id, 'location_dest_id': self.stock_location_a.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.assertEqual(picking.company_id, self.company_a) move1 = self.env['stock.move'].create({ @@ -555,6 +557,8 @@ class TestMultiCompany(TransactionCase): 'picking_type_id': self.warehouse_a.out_type_id.id, 'location_id': self.stock_location_a.id, 'location_dest_id': customer_location.id, + 'state': 'draft', + 'immediate_transfer': False, }) move_wha_to_cus = self.env['stock.move'].create({ 'name': "WH_A to Customer", diff --git a/addons/stock/tests/test_packing.py b/addons/stock/tests/test_packing.py index 86a016e97d2..633a1f5ac68 100644 --- a/addons/stock/tests/test_packing.py +++ b/addons/stock/tests/test_packing.py @@ -158,6 +158,7 @@ class TestPacking(TestPackingCommon): 'location_id': self.stock_location.id, 'location_dest_id': self.stock_location.id, 'state': 'draft', + 'immediate_transfer': False, }) picking.picking_type_id.show_entire_packs = True package_level = self.env['stock.package_level'].create({ @@ -183,6 +184,7 @@ class TestPacking(TestPackingCommon): 'location_id': self.stock_location.id, 'location_dest_id': self.stock_location.id, 'state': 'draft', + 'immediate_transfer': False, }) picking.picking_type_id.show_entire_packs = True package_level = self.env['stock.package_level'].create({ @@ -224,6 +226,7 @@ class TestPacking(TestPackingCommon): 'location_id': self.stock_location.id, 'location_dest_id': self.stock_location.id, 'state': 'draft', + 'immediate_transfer': False, }) package_level = self.env['stock.package_level'].create({ 'package_id': pack.id, @@ -275,6 +278,7 @@ class TestPacking(TestPackingCommon): 'location_id': self.customer_location.id, 'location_dest_id': self.stock_location.id, 'state': 'draft', + 'immediate_transfer': False, }) ship_move_a = self.env['stock.move'].create({ 'name': 'move 1', @@ -363,6 +367,7 @@ class TestPacking(TestPackingCommon): **location_dict, **{ 'picking_type_id': self.warehouse.in_type_id.id, + 'immediate_transfer': False, 'move_ids': [(6, 0, [move.id])], }}) @@ -392,6 +397,7 @@ class TestPacking(TestPackingCommon): 'location_id': self.stock_location.id, 'location_dest_id': self.stock_location.id, 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move.line'].create({ 'location_id': self.stock_location.id, @@ -464,11 +470,12 @@ class TestPacking(TestPackingCommon): # Add 2 lines with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productA - move_line.product_uom_qty = 1 + move_line.quantity_done = 1 with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productB - move_line.product_uom_qty = 1 + move_line.quantity_done = 1 receipt = receipt_form.save() + receipt.action_reset_draft() receipt.action_confirm() # Adds quantities then packs them and valids the receipt. @@ -521,8 +528,12 @@ class TestPacking(TestPackingCommon): # ... # if self.env.context.get('force_detailed_view'): # picking.show_operations = True - internal_form = Form(self.env['stock.picking'].with_context(force_detailed_view=True)) - internal_form.picking_type_id = self.warehouse.int_type_id + picking = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': self.warehouse.int_type_id.id, + }) + internal_form = Form(picking.with_context(force_detailed_view=True)) # The test specifically removes the ability to see the location fields # grp_multi_loc = self.env.ref('stock.group_stock_multi_locations') # self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]}) @@ -611,11 +622,12 @@ class TestPacking(TestPackingCommon): # Add 2 lines with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productA - move_line.product_uom_qty = 1 + move_line.quantity_done = 1 with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productB - move_line.product_uom_qty = 1 + move_line.quantity_done = 1 receipt = receipt_form.save() + receipt.action_reset_draft() receipt.action_confirm() # Adds quantities then packs them and valids the receipt. @@ -668,8 +680,12 @@ class TestPacking(TestPackingCommon): # ... # if self.env.context.get('force_detailed_view'): # picking.show_operations = True - internal_form = Form(self.env['stock.picking'].with_context(force_detailed_view=True)) - internal_form.picking_type_id = self.warehouse.int_type_id + picking = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': self.warehouse.int_type_id.id, + }) + internal_form = Form(picking.with_context(force_detailed_view=True)) # The test specifically removes the ability to see the location fields # grp_multi_loc = self.env.ref('stock.group_stock_multi_locations') # self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]}) @@ -758,8 +774,12 @@ class TestPacking(TestPackingCommon): dest_package1 = self.env["stock.quant.package"].create({"name": "Dest Pack1"}) # Create new picking: 120 productA - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = self.warehouse.pick_type_id + picking = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': self.warehouse.pick_type_id.id, + }) + picking_form = Form(picking) with picking_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productA move_line.product_uom_qty = 120 @@ -819,6 +839,8 @@ class TestPacking(TestPackingCommon): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.warehouse.out_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) with Form(picking) as picking_form: with picking_form.move_ids_without_package.new() as move: @@ -863,6 +885,8 @@ class TestPacking(TestPackingCommon): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_type_id': self.warehouse.out_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) with Form(picking) as picking_form: with picking_form.move_ids_without_package.new() as move: @@ -882,35 +906,35 @@ class TestPacking(TestPackingCommon): self.assertEqual(len(picking.move_ids), 1, 'Should have only 1 stock move') def test_picking_state_with_null_qty(self): - receipt_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=False)) + delivery_form = Form(self.env['stock.picking']) picking_type_id = self.warehouse.out_type_id - receipt_form.picking_type_id = picking_type_id - with receipt_form.move_ids_without_package.new() as move_line: + delivery_form.picking_type_id = picking_type_id + with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productA move_line.product_uom_qty = 10 - with receipt_form.move_ids_without_package.new() as move_line: + with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productB move_line.product_uom_qty = 10 - receipt = receipt_form.save() - receipt.action_confirm() - self.assertEqual(receipt.state, 'confirmed') - receipt.move_ids_without_package[1].product_uom_qty = 0 - self.assertEqual(receipt.state, 'confirmed') + delivery = delivery_form.save() + delivery.action_reset_draft() + delivery.action_confirm() + self.assertEqual(delivery.state, 'confirmed') + delivery.move_ids_without_package[1].product_uom_qty = 0 + self.assertEqual(delivery.state, 'confirmed') - receipt_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=True)) + delivery_form = Form(self.env['stock.picking']) picking_type_id = self.warehouse.out_type_id - receipt_form.picking_type_id = picking_type_id - with receipt_form.move_ids_without_package.new() as move_line: + delivery_form.picking_type_id = picking_type_id + with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productA move_line.quantity_done = 10 - with receipt_form.move_ids_without_package.new() as move_line: + with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productB move_line.quantity_done = 10 - receipt = receipt_form.save() - receipt.action_confirm() - self.assertEqual(receipt.state, 'assigned') - receipt.move_ids_without_package[1].product_uom_qty = 0 - self.assertEqual(receipt.state, 'assigned') + delivery = delivery_form.save() + self.assertEqual(delivery.state, 'assigned') + delivery.move_ids_without_package[1].product_uom_qty = 0 + self.assertEqual(delivery.state, 'assigned') def test_2_steps_and_backorder(self): """ When creating a backorder with a package, the latter should be reserved in the new picking. Moreover, @@ -920,6 +944,8 @@ class TestPacking(TestPackingCommon): 'picking_type_id': pick_type.id, 'location_id': from_loc.id, 'location_dest_id': to_loc.id, + 'state': 'draft', + 'immediate_transfer': False, }) move_A, move_B = self.env['stock.move'].create([{ 'name': self.productA.name, @@ -1000,6 +1026,8 @@ class TestPacking(TestPackingCommon): 'picking_type_id': self.warehouse.in_type_id.id, 'location_id': self.pack_location.id, 'location_dest_id': shelf2_location.id, + 'state': 'draft', + 'immediate_transfer': False, }) package_level = self.env['stock.package_level'].create({ 'package_id': pack.id, @@ -1070,6 +1098,8 @@ class TestPacking(TestPackingCommon): 'picking_type_id': warehouse.in_type_id.id, 'location_id': self.env.ref('stock.stock_location_suppliers').id, 'location_dest_id': warehouse.wh_input_stock_loc_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': self.productA.name, @@ -1184,6 +1214,8 @@ class TestPacking(TestPackingCommon): 'picking_type_id': warehouse.in_type_id.id, 'location_id': self.env.ref('stock.stock_location_suppliers').id, 'location_dest_id': warehouse.wh_input_stock_loc_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create([{ 'name': p.name, @@ -1273,6 +1305,8 @@ class TestPacking(TestPackingCommon): 'picking_type_id': self.warehouse.in_type_id.id, 'location_id': supplier_location.id, 'location_dest_id': input_location.id, + 'state': 'draft', + 'immediate_transfer': False, 'move_ids': [(0, 0, { 'name': p.name, 'location_id': supplier_location.id, @@ -1350,6 +1384,8 @@ class TestPacking(TestPackingCommon): 'location_dest_id': self.customer_location.id, 'picking_type_id': self.warehouse.out_type_id.id, })], + 'state': 'draft', + 'immediate_transfer': False, }) picking.action_confirm() @@ -1386,6 +1422,8 @@ class TestPacking(TestPackingCommon): 'location_id': loc_1.id, 'location_dest_id': loc_2.id, 'picking_type_id': self.warehouse.int_type_id.id, + 'state': 'draft', + 'immediate_transfer': False, }) moveA = self.env['stock.move'].create({ 'name': self.productA.name, diff --git a/addons/stock/tests/test_packing_neg.py b/addons/stock/tests/test_packing_neg.py index 1df6d31f0f8..57099b2e69d 100644 --- a/addons/stock/tests/test_packing_neg.py +++ b/addons/stock/tests/test_packing_neg.py @@ -47,6 +47,8 @@ class TestPackingNeg(TransactionCase): 'location_id': self.ref('stock.stock_location_suppliers'), 'location_dest_id': self.ref('stock.stock_location_stock'), })], + 'state': 'draft', + 'immediate_transfer': False, } pick_neg = self.env['stock.picking'].create(vals) pick_neg._onchange_picking_type() @@ -104,6 +106,8 @@ class TestPackingNeg(TransactionCase): 'location_id': self.ref('stock.stock_location_stock'), 'location_dest_id': self.ref('stock.stock_location_customers'), })], + 'state': 'draft', + 'immediate_transfer': False, } delivery_order_neg = self.env['stock.picking'].create(vals) delivery_order_neg._onchange_picking_type() @@ -161,6 +165,8 @@ class TestPackingNeg(TransactionCase): 'location_id': self.ref('stock.stock_location_suppliers'), 'location_dest_id': self.ref('stock.stock_location_stock'), })], + 'state': 'draft', + 'immediate_transfer': False, } delivery_reconcile = self.env['stock.picking'].create(vals) delivery_reconcile._onchange_picking_type() diff --git a/addons/stock/tests/test_proc_rule.py b/addons/stock/tests/test_proc_rule.py index 942a0a5cb12..b2e023e4ad4 100644 --- a/addons/stock/tests/test_proc_rule.py +++ b/addons/stock/tests/test_proc_rule.py @@ -91,6 +91,8 @@ class TestProcRule(TransactionCase): 'location_id': self.ref('stock.stock_location_output'), 'location_dest_id': self.ref('stock.stock_location_customers'), })], + 'state': 'draft', + 'immediate_transfer': False, } pick_output = self.env['stock.picking'].create(vals) pick_output.move_ids._onchange_product_id() diff --git a/addons/stock/tests/test_product.py b/addons/stock/tests/test_product.py index 8a69883fd58..f81b606c51c 100644 --- a/addons/stock/tests/test_product.py +++ b/addons/stock/tests/test_product.py @@ -30,7 +30,11 @@ class TestVirtualAvailable(TestStockCommon): 'quantity': 10.0, 'owner_id': cls.user_stock_user.partner_id.id}) - cls.picking_out = cls.env['stock.picking'].create({'picking_type_id': cls.env.ref('stock.picking_type_out').id}) + cls.picking_out = cls.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': cls.env.ref('stock.picking_type_out').id + }) cls.env['stock.move'].create({ 'name': 'a move', 'product_id': cls.product_3.id, @@ -41,6 +45,8 @@ class TestVirtualAvailable(TestStockCommon): 'location_dest_id': cls.env.ref('stock.stock_location_customers').id}) cls.picking_out_2 = cls.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, 'picking_type_id': cls.env.ref('stock.picking_type_out').id}) cls.env['stock.move'].create({ 'restrict_partner_id': cls.user_stock_user.partner_id.id, @@ -143,6 +149,8 @@ class TestVirtualAvailable(TestStockCommon): 'location_id': self.env.ref('stock.stock_location_customers').id, 'location_dest_id': self.env.ref('stock.stock_location_stock').id, 'picking_type_id': self.ref('stock.picking_type_in'), + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': 'test', diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index a17b140670d..613ed43c466 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -773,6 +773,8 @@ class StockQuant(TransactionCase): 'product_uom_qty': 10, 'product_uom': self.product.uom_id.id, })], + 'state': 'draft', + 'immediate_transfer': False, }) picking.action_confirm() diff --git a/addons/stock/tests/test_report.py b/addons/stock/tests/test_report.py index aa9d5dcb541..d3aec426dd7 100644 --- a/addons/stock/tests/test_report.py +++ b/addons/stock/tests/test_report.py @@ -319,8 +319,9 @@ class TestReports(TestReportsCommon): receipt = receipt_form.save() with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 2 + move_line.quantity_done = 2 receipt = receipt_form.save() + receipt.action_reset_draft() report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids) draft_picking_qty = docs['draft_picking_qty'] @@ -337,8 +338,9 @@ class TestReports(TestReportsCommon): delivery = delivery_form.save() with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 delivery = delivery_form.save() + delivery.action_reset_draft() report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids) draft_picking_qty = docs['draft_picking_qty'] @@ -677,8 +679,9 @@ class TestReports(TestReportsCommon): delivery = delivery_form.save() with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 delivery = delivery_form.save() + delivery.action_reset_draft() report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids) draft_picking_qty = docs['draft_picking_qty'] @@ -719,8 +722,9 @@ class TestReports(TestReportsCommon): delivery_2 = delivery_form.save() with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 8 + move_line.quantity_done = 8 delivery_2 = delivery_form.save() + delivery_2.action_reset_draft() report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids) draft_picking_qty = docs['draft_picking_qty'] @@ -773,8 +777,9 @@ class TestReports(TestReportsCommon): wh_1_receipt = receipt_form.save() with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 2 + move_line.quantity_done = 2 wh_1_receipt = receipt_form.save() + wh_1_receipt.action_reset_draft() # Creates a receipt then checks draft picking quantities. receipt_form = Form(self.env['stock.picking'].with_context( @@ -785,8 +790,9 @@ class TestReports(TestReportsCommon): wh_2_receipt = receipt_form.save() with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 wh_2_receipt = receipt_form.save() + wh_2_receipt.action_reset_draft() report_values, docs, lines = self.get_report_forecast(product_template_ids=self.product_template.ids) draft_picking_qty = docs['draft_picking_qty'] @@ -945,7 +951,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 100 + move_line.quantity_done = 100 delivery = delivery_form.save() delivery.action_confirm() @@ -956,7 +962,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 200 + move_line.quantity_done = 200 delivery2 = delivery_form.save() delivery2.action_confirm() @@ -968,7 +974,7 @@ class TestReports(TestReportsCommon): receipt = receipt_form.save() with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 200 + move_line.quantity_done = 200 receipt = receipt_form.save() receipt.move_ids[0].write({ 'move_dest_ids': [(4, delivery2.move_ids[0].id)], @@ -1005,7 +1011,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 100 + move_line.quantity_done = 100 delivery = delivery_form.save() delivery.action_confirm() @@ -1016,7 +1022,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 200 + move_line.quantity_done = 200 delivery2 = delivery_form.save() delivery2.action_confirm() @@ -1028,7 +1034,7 @@ class TestReports(TestReportsCommon): receipt = receipt_form.save() with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 300 + move_line.quantity_done = 300 receipt = receipt_form.save() receipt.move_ids[0].write({ 'move_dest_ids': [(4, delivery2.move_ids[0].id)], @@ -1062,9 +1068,8 @@ class TestReports(TestReportsCommon): delivery_form.scheduled_date = date.today() with delivery_form.move_ids_without_package.new() as move: move.product_id = self.product - move.product_uom_qty = 200 + move.quantity_done = 200 delivery1 = delivery_form.save() - delivery1.action_confirm() # Creation of one receipt with date 'today + 1' and smaller qty than the delivery scheduled_date1 = datetime.now() + timedelta(days=1) @@ -1074,9 +1079,8 @@ class TestReports(TestReportsCommon): receipt_form.scheduled_date = scheduled_date1 with receipt_form.move_ids_without_package.new() as move: move.product_id = self.product - move.product_uom_qty = 150 + move.quantity_done = 150 receipt1 = receipt_form.save() - receipt1.action_confirm() self.assertEqual(receipt1.move_ids.forecast_availability, -50.0) self.assertEqual(delivery1.move_ids.forecast_availability, 150) self.assertEqual(delivery1.move_ids.forecast_expected_date, scheduled_date1) @@ -1089,11 +1093,8 @@ class TestReports(TestReportsCommon): receipt_form.scheduled_date = scheduled_date2 with receipt_form.move_ids_without_package.new() as move: move.product_id = self.product - move.product_uom_qty = 150 - receipt2 = receipt_form.save() - receipt2.action_confirm() - for move in receipt2.move_ids: move.quantity_done = 150 + receipt2 = receipt_form.save() # Check forecast_information of delivery1 delivery1.move_ids._compute_forecast_information() # Because depends not "complete" @@ -1112,7 +1113,7 @@ class TestReports(TestReportsCommon): delivery2_form = Form(delivery2) delivery2_form.scheduled_date = datetime.now() + timedelta(days=1) delivery2 = delivery2_form.save() - delivery2.action_confirm() + delivery2.move_ids.quantity_done = delivery1.move_ids.quantity_done self.assertEqual(delivery2.move_ids.forecast_availability, 100) # Check for both deliveries and receipts if the highlight (is_matched) corresponds to the correct picking @@ -1156,9 +1157,8 @@ class TestReports(TestReportsCommon): delivery_form.scheduled_date = datetime.now() - timedelta(days=10) with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 3 + move_line.quantity_done = 3 delivery_manual = delivery_form.save() - delivery_manual.action_confirm() # 'by_date' reservation => reservation_date = 1 day before today delivery_form = Form(self.env['stock.picking'].with_context( @@ -1169,7 +1169,7 @@ class TestReports(TestReportsCommon): delivery_form.scheduled_date = datetime.now() + timedelta(days=5) with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 3 + move_line.quantity_done = 3 delivery_by_date = delivery_form.save() delivery_by_date.action_confirm() @@ -1182,7 +1182,7 @@ class TestReports(TestReportsCommon): delivery_form.scheduled_date = datetime.now() + timedelta(days=5) with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 3 + move_line.quantity_done = 3 delivery_by_date_priority = delivery_form.save() # # The priority field is not visible until the name is set, @@ -1199,8 +1199,9 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = picking_type_at_confirm with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 3 + move_line.quantity_done = 3 delivery_at_confirm = delivery_form.save() + delivery_at_confirm.action_reset_draft() delivery_at_confirm.action_confirm() # Order should be: delivery_by_date, delivery_at_confirm, delivery_by_date_priority, delivery_manual @@ -1221,7 +1222,7 @@ class TestReports(TestReportsCommon): receipt_form.scheduled_date = date.today() + timedelta(days=1) with receipt_form.move_ids_without_package.new() as move: move.product_id = self.product - move.product_uom_qty = 6 + move.quantity_done = 6 receipt1 = receipt_form.save() receipt1.action_confirm() @@ -1243,14 +1244,14 @@ class TestReports(TestReportsCommon): outgoing.picking_type_id = self.picking_type_out with outgoing.move_ids_without_package.new() as move: move.product_id = self.product - move.product_uom_qty = 2 + move.quantity_done = 2 outgoing = outgoing.save() outgoing.action_confirm() incoming = Form(self.env['stock.picking']) incoming.picking_type_id = self.picking_type_in with incoming.move_ids_without_package.new() as move: move.product_id = self.product - move.product_uom_qty = 2 + move.quantity_done = 2 incoming = incoming.save() incoming.action_confirm() incoming.action_set_quantities_to_reservation() @@ -1286,10 +1287,10 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = product2 - move_line.product_uom_qty = 10 + move_line.quantity_done = 10 delivery1 = delivery_form.save() delivery1.action_confirm() @@ -1300,7 +1301,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 2 + move_line.quantity_done = 2 delivery2 = delivery_form.save() delivery2.action_confirm() @@ -1313,16 +1314,17 @@ class TestReports(TestReportsCommon): with receipt_form.move_ids_without_package.new() as move_line: # incoming qty greater than total (2 moves) outgoing amount => 2 report lines, each = outgoing qty move_line.product_id = self.product - move_line.product_uom_qty = 15 + move_line.quantity_done = 15 with receipt_form.move_ids_without_package.new() as move_line: # outgoing qty greater than incoming amount => report line = incoming qty move_line.product_id = product2 - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 with receipt_form.move_ids_without_package.new() as move_line: # not outgoing => shouldn't appear in report move_line.product_id = product3 - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 receipt = receipt_form.save() + receipt.action_reset_draft() # check that reception report has correct number of deliveries/outgoing moves # but the quantities aren't available for assignment yet (i.e. can link as chained moves) @@ -1392,8 +1394,9 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 100 + move_line.quantity_done = 100 delivery = delivery_form.save() + delivery.action_reset_draft() delivery.action_confirm() # Create 2 receipts and check its reception report values @@ -1404,8 +1407,9 @@ class TestReports(TestReportsCommon): receipt_form.picking_type_id = self.picking_type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 5 + move_line.quantity_done = 5 receipt1 = receipt_form.save() + receipt1.action_reset_draft() receipt_form = Form(self.env['stock.picking'].with_context( force_detailed_view=True @@ -1414,8 +1418,9 @@ class TestReports(TestReportsCommon): receipt_form.picking_type_id = self.picking_type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 3 + move_line.quantity_done = 3 receipt2 = receipt_form.save() + receipt2.action_reset_draft() # check that report correctly merges not draft incoming quantities report = self.env['report.stock.report_reception'] @@ -1470,7 +1475,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = picking_type_out_2 with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 100 + move_line.quantity_done = 100 delivery = delivery_form.save() delivery.action_confirm() @@ -1482,7 +1487,7 @@ class TestReports(TestReportsCommon): receipt_form.picking_type_id = self.picking_type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 15 + move_line.quantity_done = 15 receipt = receipt_form.save() report = self.env['report.stock.report_reception'] @@ -1525,7 +1530,7 @@ class TestReports(TestReportsCommon): receipt_form.picking_type_id = self.picking_type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = 15 + move_line.quantity_done = 15 receipt = receipt_form.save() report = self.env['report.stock.report_reception'] @@ -1553,7 +1558,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = outgoing_qty + move_line.quantity_done = outgoing_qty delivery = delivery_form.save() delivery.action_confirm() @@ -1564,7 +1569,7 @@ class TestReports(TestReportsCommon): receipt_form.picking_type_id = self.picking_type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = incoming_qty + move_line.quantity_done = incoming_qty receipt = receipt_form.save() receipt.action_confirm() @@ -1619,7 +1624,7 @@ class TestReports(TestReportsCommon): delivery_form.picking_type_id = self.picking_type_out with delivery_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = outgoing_qty + move_line.quantity_done = outgoing_qty delivery = delivery_form.save() delivery.action_confirm() @@ -1631,8 +1636,9 @@ class TestReports(TestReportsCommon): receipt_form.picking_type_id = self.picking_type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.product - move_line.product_uom_qty = incoming_qty + move_line.quantity_done = incoming_qty receipt = receipt_form.save() + receipt.action_reset_draft() receipt.action_confirm() report = self.env['report.stock.report_reception'] diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 20041aec132..56f9a5793cc 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -39,6 +39,8 @@ class TestStockFlow(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) move_a = self.MoveObj.create({ 'name': self.productA.name, @@ -175,6 +177,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) move_cust_a = self.MoveObj.create({ 'name': self.productA.name, @@ -455,6 +459,8 @@ class TestStockFlow(TestStockCommon): picking_in_A = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.DozA.name, @@ -553,6 +559,8 @@ class TestStockFlow(TestStockCommon): picking_in_B = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) move_in_a = self.MoveObj.create({ 'name': self.DozA.name, @@ -743,6 +751,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) self.MoveObj.create({ 'name': self.kgB.name, @@ -784,6 +794,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) self.MoveObj.create({ 'name': self.DozA.name, @@ -904,6 +916,8 @@ class TestStockFlow(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': productKG.name, @@ -952,6 +966,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) self.MoveObj.create({ 'name': productKG.name, @@ -1129,6 +1145,8 @@ class TestStockFlow(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.productA.name, @@ -1156,6 +1174,8 @@ class TestStockFlow(TestStockCommon): 'name': 'testpicking', 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) move_out = self.MoveObj.create({ 'name': self.productA.name, @@ -1186,6 +1206,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.pack_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) move_out = self.MoveObj.create({ 'name': self.productA.name, @@ -1198,6 +1220,8 @@ class TestStockFlow(TestStockCommon): picking_pack = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.pack_location}) move_pack = self.MoveObj.create({ 'name': self.productA.name, @@ -1211,6 +1235,8 @@ class TestStockFlow(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) move_in = self.MoveObj.create({ 'name': self.productA.name, @@ -1304,6 +1330,8 @@ class TestStockFlow(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.productE.name, @@ -1331,6 +1359,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) self.MoveObj.create({ 'name': self.productE.name, @@ -1361,6 +1391,8 @@ class TestStockFlow(TestStockCommon): picking_in = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.productE.name, @@ -1389,6 +1421,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) self.MoveObj.create({ 'name': self.productE.name, @@ -1446,6 +1480,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) picking_out.move_type = 'one' @@ -1484,6 +1520,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) picking_out.move_type = 'direct' @@ -1522,6 +1560,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) picking_out.move_type = 'direct' @@ -1559,6 +1599,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) picking_out.move_type = 'direct' @@ -1583,6 +1625,8 @@ class TestStockFlow(TestStockCommon): picking_out = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.customer_location}) move_mto_alone = self.MoveObj.create({ 'name': self.productA.name, @@ -1641,6 +1685,8 @@ class TestStockFlow(TestStockCommon): picking = self.PickingObj.create({ 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) move_a = self.MoveObj.create({ 'name': self.productA.name, @@ -1698,6 +1744,8 @@ class TestStockFlow(TestStockCommon): picking_ask = self.PickingObj.create({ 'picking_type_id': picking_type_ask.id, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.productA.name, @@ -1710,6 +1758,8 @@ class TestStockFlow(TestStockCommon): picking_always = self.PickingObj.create({ 'picking_type_id': picking_type_always.id, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.productA.name, @@ -1722,6 +1772,8 @@ class TestStockFlow(TestStockCommon): picking_never = self.PickingObj.create({ 'picking_type_id': picking_type_never.id, 'location_id': self.supplier_location, + 'state': 'draft', + 'immediate_transfer': False, 'location_dest_id': self.stock_location}) self.MoveObj.create({ 'name': self.productA.name, @@ -1883,11 +1935,12 @@ class TestStockFlow(TestStockCommon): f.picking_type_id = warehouse_company_1.out_type_id with f.move_ids_without_package.new() as move: move.product_id = product_from_company_2 - move.product_uom_qty = 5 + move.quantity_done = 5 with f.move_ids_without_package.new() as move: move.product_id = product_from_company_3 - move.product_uom_qty = 5 + move.quantity_done = 5 picking = f.save() + picking.action_reset_draft() picking.move_ids_without_package.write({'procure_method': 'make_to_order'}) picking.action_confirm() @@ -1916,9 +1969,13 @@ class TestStockFlow(TestStockCommon): product = self.env['product.product'].create({'name': 'Un petit coup de polish', 'type': 'product'}) wh = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) - f = Form(self.env['stock.picking'], view='stock.view_picking_form') + picking = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': wh.out_type_id.id, + }) + f = Form(picking, view='stock.view_picking_form') f.partner_id = partner - f.picking_type_id = wh.out_type_id with f.move_ids_without_package.new() as move: move.product_id = product move.product_uom_qty = 5 @@ -1971,7 +2028,7 @@ class TestStockFlow(TestStockCommon): f.scrap_location_id = wh.wh_input_stock_loc_id def test_picking_form_immediate_transfer(self): - picking_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=True)) + picking_form = Form(self.env['stock.picking']) picking_form.picking_type_id = self.env.ref('stock.picking_type_in') with picking_form.move_ids_without_package.new() as move: @@ -1984,9 +2041,9 @@ class TestStockFlow(TestStockCommon): self.assertEqual(picking.state, 'assigned') - picking_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=False)) + picking.action_reset_draft() + picking_form = Form(picking) - picking_form.picking_type_id = self.env.ref('stock.picking_type_in') with picking_form.move_ids_without_package.new() as move: self.assertTrue(move._get_modifier('quantity_done', 'column_invisible')) self.assertTrue(move._get_modifier('forecast_availability', 'column_invisible')) @@ -2018,8 +2075,9 @@ class TestStockFlow(TestStockCommon): picking_form.picking_type_id = picking_type with picking_form.move_ids_without_package.new() as move: move.product_id = product_lot - move.product_uom_qty = 8 + move.quantity_done = 8 receipt_1 = picking_form.save() + receipt_1.action_reset_draft() receipt_1.action_confirm() move_form = Form(receipt_1.move_ids, view="stock.view_stock_move_operations") @@ -2038,8 +2096,9 @@ class TestStockFlow(TestStockCommon): picking_form.picking_type_id = picking_type with picking_form.move_ids_without_package.new() as move: move.product_id = product_lot - move.product_uom_qty = 8 + move.quantity_done = 8 receipt_2 = picking_form.save() + receipt_2.action_reset_draft() receipt_2.action_confirm() move_form = Form(receipt_2.move_ids, view="stock.view_stock_move_operations") @@ -2078,8 +2137,12 @@ class TestStockFlow(TestStockCommon): # Checks also it still raise an error when it tries to create multiple time # the same serial numbers (same scenario but with SN instead of lots). picking_type = self.env['stock.picking.type'].browse(self.picking_type_in) - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = picking_type + picking = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': picking_type.id, + }) + picking_form = Form(picking) with picking_form.move_ids_without_package.new() as move: move.product_id = product_serial move.product_uom_qty = 2 @@ -2093,8 +2156,12 @@ class TestStockFlow(TestStockCommon): line.lot_name = 'sn-002' move = move_form.save() - picking_form = Form(self.env['stock.picking']) - picking_form.picking_type_id = picking_type + picking = self.env['stock.picking'].create({ + 'state': 'draft', + 'immediate_transfer': False, + 'picking_type_id': picking_type.id, + }) + picking_form = Form(picking) with picking_form.move_ids_without_package.new() as move: move.product_id = product_serial move.product_uom_qty = 2 @@ -2121,6 +2188,8 @@ class TestStockFlow(TestStockCommon): 'picking_type_id': picking_type, 'location_id': from_loc, 'location_dest_id': to_loc, + 'state': 'draft', + 'immediate_transfer': False, }) self.MoveObj.create({ 'name': self.productA.name, @@ -2173,6 +2242,8 @@ class TestStockFlow(TestStockCommon): 'picking_type_id': picking_type_out.id, 'location_id': stock_location.id, 'location_dest_id': self.customer_location, + 'state': 'draft', + 'immediate_transfer': False, }) move_out = self.MoveObj.create({ 'name': self.productA.name, @@ -2198,6 +2269,8 @@ class TestStockFlow(TestStockCommon): 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, + 'state': 'draft', + 'immediate_transfer': False, }) move_a = self.MoveObj.create({ 'name': self.productA.name, @@ -2314,7 +2387,7 @@ class TestStockFlow(TestStockCommon): self.productA.tracking = 'serial' type_in = self.env['stock.picking.type'].browse(self.picking_type_in) - receipt_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=True)) + receipt_form = Form(self.env['stock.picking']) receipt_form.picking_type_id = type_in with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productA @@ -2447,11 +2520,12 @@ class TestStockFlow(TestStockCommon): self.productA.tracking = 'lot' - receipt_form = Form(self.env['stock.picking'].with_context(default_immediate_transfer=True)) + receipt_form = Form(self.env['stock.picking']) receipt_form.picking_type_id = self.env.ref('stock.picking_type_in') with receipt_form.move_ids_without_package.new() as move: move.product_id = self.productA receipt = receipt_form.save() + receipt.action_confirm() with Form(receipt.move_ids, view='stock.view_stock_move_nosuggest_operations') as move_form: with move_form.move_line_nosuggest_ids.new() as sml: diff --git a/addons/stock/tests/test_warehouse.py b/addons/stock/tests/test_warehouse.py index c93131fb16c..ffeb6a95ae3 100644 --- a/addons/stock/tests/test_warehouse.py +++ b/addons/stock/tests/test_warehouse.py @@ -283,6 +283,7 @@ class TestWarehouse(TestStockCommon): 'location_id': warehouse_shop.lot_stock_id.id, 'location_dest_id': self.env.ref('stock.stock_location_customers').id, }) + picking_out.action_reset_draft() self.env['stock.move'].create({ 'name': product.name, 'product_id': product.id, @@ -365,6 +366,8 @@ class TestWarehouse(TestStockCommon): 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': warehouse_shop_namur.lot_stock_id.id, 'location_dest_id': customer_location.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': product.name, @@ -409,6 +412,8 @@ class TestWarehouse(TestStockCommon): 'picking_type_id': self.env.ref('stock.picking_type_out').id, 'location_id': warehouse_shop_wavre.lot_stock_id.id, 'location_dest_id': customer_location.id, + 'state': 'draft', + 'immediate_transfer': False, }) self.env['stock.move'].create({ 'name': product.name, diff --git a/addons/stock/tests/test_wise_operator.py b/addons/stock/tests/test_wise_operator.py index 4e1766c94b1..94155674c07 100644 --- a/addons/stock/tests/test_wise_operator.py +++ b/addons/stock/tests/test_wise_operator.py @@ -48,6 +48,8 @@ class TestWiseOperator(TransactionCase): 'location_id': self.ref('stock.stock_location_suppliers'), 'location_dest_id': self.ref('stock.stock_location_stock'), })], + 'state': 'draft', + 'immediate_transfer': False, } pick1_wise = self.env['stock.picking'].create(vals) pick1_wise._onchange_picking_type() @@ -95,6 +97,8 @@ class TestWiseOperator(TransactionCase): 'location_id': self.ref('stock.stock_location_stock'), 'location_dest_id': self.ref('stock.stock_location_customers'), })], + 'state': 'draft', + 'immediate_transfer': False, } delivery_order_wise1 = self.env['stock.picking'].create(vals) delivery_order_wise1._onchange_picking_type() @@ -120,6 +124,8 @@ class TestWiseOperator(TransactionCase): 'location_id': self.ref('stock.stock_location_stock'), 'location_dest_id': self.ref('stock.stock_location_customers'), })], + 'state': 'draft', + 'immediate_transfer': False, } delivery_order_wise2 = self.env['stock.picking'].create(vals) delivery_order_wise2._onchange_picking_type() diff --git a/addons/stock/views/stock_move_views.xml b/addons/stock/views/stock_move_views.xml index d437d752bfa..2ac3badae7a 100644 --- a/addons/stock/views/stock_move_views.xml +++ b/addons/stock/views/stock_move_views.xml @@ -292,7 +292,7 @@ - + diff --git a/addons/stock/views/stock_picking_type_views.xml b/addons/stock/views/stock_picking_type_views.xml index debd48bd17b..6613e9400f4 100644 --- a/addons/stock/views/stock_picking_type_views.xml +++ b/addons/stock/views/stock_picking_type_views.xml @@ -161,13 +161,7 @@ diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index bacfabf450e..5509be98216 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -108,9 +108,7 @@
- - @@ -127,10 +125,11 @@
-