def test_reordering_rule(self): """ - Receive products in 2 steps - The product has a reordering rule - On the po generated, the source document should be the name of the reordering rule """ warehouse_1 = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) warehouse_1.write({'reception_steps': 'two_steps'}) # Create a supplier partner = self.env['res.partner'].create({ 'name': 'Smith' }) # create product and set the vendor product_form = Form(self.env['product.product']) product_form.name = 'Product A' product_form.type = 'product' with product_form.seller_ids.new() as seller: seller.name = partner product_form.route_ids.add(self.env.ref('purchase_stock.route_warehouse0_buy')) product_01 = product_form.save() # create reordering rule orderpoint_form = Form(self.env['stock.warehouse.orderpoint']) orderpoint_form.warehouse_id = warehouse_1 orderpoint_form.location_id = warehouse_1.lot_stock_id orderpoint_form.product_id = product_01 orderpoint_form.product_min_qty = 0.000 orderpoint_form.product_max_qty = 0.000 order_point = orderpoint_form.save() # Create Delivery Order of 10 product picking_form = Form(self.env['stock.picking']) picking_form.partner_id = partner 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 = product_01 move.product_uom_qty = 10.0 customer_picking = picking_form.save() # picking confirm customer_picking.action_confirm() # Run scheduler self.env['procurement.group'].run_scheduler() # Check purchase order created or not purchase_order = self.env['purchase.order'].search([('partner_id', '=', partner.id)]) self.assertTrue(purchase_order, 'No purchase order created.') # On the po generated, the source document should be the name of the reordering rule self.assertEqual(order_point.name, purchase_order.origin, 'Source document on purchase order should be the name of the reordering rule.')
def test_pack_in_receipt_two_step_multi_putaway(self): """ Checks all works right in the following specific corner case: * For a two-step receipt, receives two products using two putaways targeting different locations. * Puts these products in a package then valid the receipt. * Cancels the automatically generated internal transfer then create a new one. * In this internal transfer, adds the package then valid it. """ grp_multi_loc = self.env.ref('stock.group_stock_multi_locations') grp_multi_step_rule = self.env.ref('stock.group_adv_location') grp_pack = self.env.ref('stock.group_tracking_lot') self.env.user.write({'groups_id': [(3, grp_multi_loc.id)]}) self.env.user.write({'groups_id': [(3, grp_multi_step_rule.id)]}) self.env.user.write({'groups_id': [(3, grp_pack.id)]}) self.warehouse.reception_steps = 'two_steps' # Settings of receipt. self.warehouse.in_type_id.show_operations = True self.warehouse.in_type_id.show_entire_packs = True # Settings of internal transfer. self.warehouse.int_type_id.show_operations = True self.warehouse.int_type_id.show_entire_packs = True # Creates two new locations for putaway. location_form = Form(self.env['stock.location']) location_form.name = 'Shelf A' location_form.location_id = self.stock_location loc_shelf_A = location_form.save() location_form = Form(self.env['stock.location']) location_form.name = 'Shelf B' location_form.location_id = self.stock_location loc_shelf_B = location_form.save() # Creates a new putaway rule for productA and productB. putaway = self.env['product.putaway'].create({ 'name': 'Stock Putaway', 'product_location_ids': [(0, 0, { 'product_id': self.productA.id, 'fixed_location_id': loc_shelf_A.id, }), (0, 0, { 'product_id': self.productB.id, 'fixed_location_id': loc_shelf_B.id, })] }) location_form = Form(self.stock_location) location_form.putaway_strategy_id = putaway self.stock_location = location_form.save() # Create a new receipt with the two products. receipt_form = Form(self.env['stock.picking']) receipt_form.picking_type_id = self.warehouse.in_type_id # 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 with receipt_form.move_ids_without_package.new() as move_line: move_line.product_id = self.productB move_line.product_uom_qty = 1 receipt = receipt_form.save() receipt.action_confirm() # Adds quantities then packs them and valids the receipt. receipt_form = Form(receipt) with receipt_form.move_line_ids_without_package.edit(0) as move_line: move_line.qty_done = 1 with receipt_form.move_line_ids_without_package.edit(1) as move_line: move_line.qty_done = 1 receipt = receipt_form.save() receipt.put_in_pack() receipt.button_validate() receipt_package = receipt.package_level_ids_details[0] self.assertEqual(receipt_package.location_dest_id.id, receipt.location_dest_id.id) self.assertEqual(receipt_package.move_line_ids[0].location_dest_id.id, receipt.location_dest_id.id) self.assertEqual(receipt_package.move_line_ids[1].location_dest_id.id, receipt.location_dest_id.id) # Checks an internal transfer was created following the validation of the receipt. internal_transfer = self.env['stock.picking'].search( [('picking_type_id', '=', self.warehouse.int_type_id.id)], order='id desc', limit=1) self.assertEqual(internal_transfer.origin, receipt.name) self.assertEqual(len(internal_transfer.package_level_ids_details), 1) internal_package = internal_transfer.package_level_ids_details[0] self.assertEqual(internal_package.location_dest_id.id, internal_transfer.location_dest_id.id) self.assertNotEqual( internal_package.location_dest_id.id, putaway.product_location_ids[0].fixed_location_id.id, "The package destination location must be the one from the picking." ) self.assertNotEqual( internal_package.move_line_ids[0].location_dest_id.id, putaway.product_location_ids[0].fixed_location_id.id, "The move line destination location must be the one from the picking." ) self.assertNotEqual( internal_package.move_line_ids[1].location_dest_id.id, putaway.product_location_ids[0].fixed_location_id.id, "The move line destination location must be the one from the picking." ) # Cancels the internal transfer and creates a new one. internal_transfer.action_cancel() internal_form = Form(self.env['stock.picking']) internal_form.picking_type_id = self.warehouse.int_type_id internal_form.location_id = self.warehouse.wh_input_stock_loc_id with internal_form.package_level_ids_details.new() as pack_line: pack_line.package_id = receipt_package.package_id internal_transfer = internal_form.save() # Checks the package fields have been correctly set. internal_package = internal_transfer.package_level_ids_details[0] self.assertEqual(internal_package.location_dest_id.id, internal_transfer.location_dest_id.id) internal_transfer.action_assign() self.assertEqual(internal_package.location_dest_id.id, internal_transfer.location_dest_id.id) self.assertNotEqual( internal_package.location_dest_id.id, putaway.product_location_ids[0].fixed_location_id.id, "The package destination location must be the one from the picking." ) self.assertNotEqual( internal_package.move_line_ids[0].location_dest_id.id, putaway.product_location_ids[0].fixed_location_id.id, "The move line destination location must be the one from the picking." ) self.assertNotEqual( internal_package.move_line_ids[1].location_dest_id.id, putaway.product_location_ids[0].fixed_location_id.id, "The move line destination location must be the one from the picking." ) internal_transfer.button_validate()