Though sporadically funny, this blackish comedy would have been far better had it been a lot darker. Instead of taking its premise about a rude, self-absorbed, manipulative middle-school teacher as far as it can, Jake Kasdan’s picture settles for sitcom-level shenanigans and mild raunchiness before coasting into an ending that effectively cops out. This “Teacher” isn’t really bad, just average.

Shedding her pin-up girl persona, Cameron Diaz stars as Elizabeth Halsey, an abrasive, do-as-little-as-possible gold digger who’s leaving her job as a seventh-grade teacher in a Chicago suburb because she’s finally snagged a rich fiance. But when the doofus, prompted by his mother, dumps her, Elizabeth has little choice but to return to her hated post for another year, determined to raise the ten grand she needs for the breast augmentation surgery she believes will be the key to seducing another wealthy male boob.

There’s some amusement in Halsey’s Spartan, book-free classroom, her nonchalant dismissal of her students, be they overachievers or dweebs, and her tactic of constantly showing them movies about school rather than doing any real work (the clips we see begin with “Stand and Deliver” and wind up with “Scream”). But the supposedly plot-driving premise of her money-making obsession bogs down, first in a car-wash sequence in which she plays on her slutty physical attributes although she’s supposedly uncertain of them (and which never makes clear whether she embezzles the profits, as was presumably her intention) and then in a protracted episode in which she steals the answer sheet to a state test so that she can win a big bonus for having the class with the most improved results.

Even more problematic, though, is that for the most part the script merely settles into the mold of oddball workplace comedy that writers Gene Stupnitsky and Lee Eisenberg have learned from their stint on “The Office,” which makes for a mildly amusing but awfully familiar result. The school principal, Wally Snur (John Michael Higgins), a dolphin-hugger, is a well-meaning dolt who might have been named Michael Scott. Elizabeth’s nemesis, hard-driving, endlessly ebullient but manipulative Amy Squirrel (Lucy Punch), is like a distaff Dwight Shrute. Gym teacher Russell Gettis (Jason Segel), who comments bemusedly on all his colleagues’ foibles, is basically a stand-in John Krasinski’s Jim. New teacher, rich Scott Delacorte (Justin Timberlake)—whom whom Elizabeth and Amy will fight—is the sort of high-minded dimwit who’s a Michael Scott in the making. And comparisons to the NBC comedy are further emphasized by the presence in the supporting cast of Phyllis Smith as another teacher, playing much the same role she does on Thursday nights.

But all the actors—except for Timberlake, who looks stiff and uncomfortable—throw themselves into the farcical business with abandon, sometimes too freely in fact. Under Kasdan’s permissive direction, Punch, most notably, overdoes everything, by the close becoming so manic that you wonder about a final gag that sees her transferred to an inner-city school. But Segel gives what’s probably his most ingratiating performance to date as the likable, laid-back fellow who’s obviously the perfect match for Elizabeth, and Diaz clearly is having a good time playing against type.

Unfortunately, “Bad Teacher” goes soft in the last reel, with Halsey turning over a new leaf while not abandoning either her lust or her hard-edged attitude. The effort to redeem the character without jettisoning what made her amusing in the first place doesn’t really work, smacking more of a having-it-both-ways mentality rather than going for the jugular. Perhaps the mildly cynical stance at the close is all the makers felt they could get away with, but it comes across as tepid rather than sharp.

So “Bad Teacher” deserves points for being more acerbic than the usual run of pallid, prefabricated Hollywood comedies. But it also earns demerits for failing to take things all the way. Like a student who could have gotten a solid B with some extra effort, it has to settle for an almost-but-not-quite C+.