Paint walls.
Install flooring.
Lay molding on saw horses. Outside if possible. Prime and paint. Let dry.
Nail painted molding to wall. Set nails. Fill holes. Touch up molding.
This is how I do it. Others may differ. Personally I think its much easier to paint or stain your molding before you put it up. Goes faster too.