Moody Teas dev
Focus Steep time: 5 min

Why Odoo kept saying we had -596 in stock

In September I was going back through Blend Manager, the app we use for blending and shipping, after fixing a different bug where blending batches weren't using up their raw materials. While I was in there I noticed a lot of products showing the exact same stock number, -596.00, even though some had 15 on the shelf and some had 3.

What was going on

Most of what we sell is a kit in Odoo terms (Odoo calls it a phantom bill of materials). A tin of tea on the website is really the tea, the tin and the label. When one sells, Odoo takes stock out of those parts.

What I didn't know is that for kit products, qty_available isn't a count of that product at all. Odoo works out how many kits you could put together from the parts, and whichever part you have the least of sets the number. Our labels were sitting at -596, so every kit that used that label said -596.

That's a useful number if you're planning what to make. I was using it to find out what was on the shelf.

How many products it hit

What I comparedResult
Products holding stock, qty_available vs. adding up stock.quant115 of 246 didn't match
Worst one, on product.template-4,728 reported, -28 real

I measured this on September 19, 2026, against our live database.

Why it mattered more than a wrong number on a screen

Our supply count screen works out the correction by taking what you counted and subtracting what Odoo says is there. With the wrong "what's there", every saved count wrote a wrong adjustment. People were counting correctly and the numbers still went bad.

Change 1: read stock from stock.quant

Odoo keeps the actual stock in stock.quant, one row per product, location and lot. Add those up and you get what's physically there, kit or not.

quants = models.execute_kw(db, uid, pw, "stock.quant", "search_read",
    [[["product_id", "in", product_ids],
      ["location_id", "child_of", stock_location_id]]],
    {"fields": ["product_id", "quantity"]})

on_hand = {}
for q in quants:
    pid = q["product_id"][0]
    on_hand[pid] = on_hand.get(pid, 0) + q["quantity"]

I put that in one helper function and moved every stock read in Blend Manager over to it. Then I searched the code for qty_available and virtual_available until neither showed up anywhere, because a single missed spot would have kept the bad numbers going.

Change 2: count and adjust the same locations

The easy filter is location_id.usage = "internal", and that's what we had. It's wrong for counting, because "internal" also includes the bins we take to markets and the kitchen. The screen showed the warehouse plus the market bins, but the adjustment only landed on the warehouse.

Now the read and the write both use the warehouse's stock location and everything under it (lot_stock_id on stock.warehouse), so the number you count is the number that gets corrected.

Change 3: write counts so there's a record

For a long time Blend Manager wrote stock.quant.quantity directly. That works, but Odoo records nothing about it: no user, no date, no reason, no stock move. When I went looking, there were 521 adjustments with nothing behind them.

The proper way is an inventory adjustment. You set the counted quantity on the quant and apply it, and Odoo makes a stock move marked as an inventory adjustment, with who did it and when.

models.execute_kw(db, uid, pw, "stock.quant", "write",
    [[quant_id], {"inventory_quantity": counted,
                  "inventory_quantity_set": True}])
try:
    models.execute_kw(db, uid, pw, "stock.quant",
                      "action_apply_inventory", [[quant_id]])
except xmlrpc.client.Fault as e:
    # The adjustment went through. The method returns None,
    # and XML-RPC can't send None back, so it errors afterwards.
    if "cannot marshal None" not in str(e):
        raise
# Read stock.quant again and check the total matches the count.

The reason I stayed away from this for so long is a little embarrassing. action_apply_inventory returns None, and XML-RPC can't send None back, so the call throws an error after the adjustment has already happened. It looks exactly like a failure, and I took it as one. The code now catches that one error and then re-reads the stock to make sure the total is right.

Products tracked by lot can have stock spread over a lot of quants (one of our black teas had 14). Our screen shows one number per product, so the code works out the difference against the product's total, applies it to one quant, and then checks the total again rather than that one quant.

If you run Odoo with kits