With shares of Walgreens Boots Alliance (WBA -1.33%) falling by 26% in the past 12 months, shareholders probably aren't hungry for more bad news. But in keeping with the chaotic spirit of the 2020s thus far, they're getting some anyway.

The problem this time around is another instance of one of the company's bugbears over the last few years: legal settlements pertaining to its filling of opioid drug prescriptions. Let's get a better understanding of what happened and how it might affect shareholders in the future.

With one legal issue resolved, another lingers

The latest piece of bad news is that Walgreens agreed on May 17 to a $230 million settlement with the city of San Francisco, which was suing it for lack of sufficient due diligence when it filled prescriptions for opioid medications. While the company didn't admit any guilt, it'll be liable for the sum over the next 14 years, with most of it paid before 2031. Given that it has $1.8 billion in cash and equivalents and trailing-12-month free cash flow (FCF) of $982 million, this payout alone will probably not be a significant financial burden.

Still, the latest settlement follows another last year, also related to its prescribing of opioids. The state of Florida settled with the company for $683 million, to be paid over 18 years. And in December 2022, Walgreens agreed in principle with a group of states including New York, California, and Massachusetts (suing it for the same reasons) to pay $5.7 billion over 15 years. Payments are expected to start in the second half of this year.

This is roughly the point at which one would start to worry seriously about Walgreens' ability to pay off its settlements while still also having enough money to invest for growth and continue to pay a dividend to its shareholders. But the plaintiffs above aren't the only ones intent on taking the company to the bank by way of the legal arena, nor are opioids the only issue.

On May 19, Walgreens petitioned a judge to void the results of arbitration between it and Humana, which had called for the pharmacy chain to pay $642 million. Humana, an insurer, claimed that the business had been overcharging for years by misstating its prescription drug prices in requests for reimbursement. It's unclear how the legal challenge to the arbitration will play out, but Walgreens could be on the hook for the money.

The future doesn't look great

Now that you're up to speed on some of the settlements Walgreens will be paying out through the coming decade and beyond, it's time to turn to the question of whether the stock is a good investment.

Over the last five years, the company's quarterly sales have risen by only 1.5%, reaching $34.8 billion, and quarterly FCF has fallen by 87% to $248 million. Its core pharmacy segment -- which brought in sales of $27.6 billion in the second quarter -- is hardly growing at all year over year, and there isn't much reason to expect it to anytime soon.

Walgreens' strategic plan to start providing primary healthcare services from its pharmacies will take many years and lots more investment before it can be a significant driver of growth, if it ever becomes one; in the second quarter of 2023, the segment only brought in $1.6 billion. And its payout ratio is already higher than 100%, meaning that it needs to cough up some of its cash holdings to pay its dividend at the current rate, because net income isn't sufficient to cover it.

To be clear, the latest bad news about the opioid settlement with San Francisco is not, in isolation, enough of a reason to avoid the stock as the financial impact will not be massive. But when you take into account all of the other legal liabilities and Walgreens' present financial precariousness, there isn't much of a reason to buy it. And if you like your shares to retain value over time, this is a stock you should probably strongly think about selling.