跳到正文
DEV Community· Amod Jangada·· 1 小時前AI 評分22

用程式碼把一週的批發訂單轉成烘焙計劃

Turning a week of wholesale orders into a roast plan (with code)

AI 導讀

烘焙商可把一週的咖啡館批發訂單整理成清單,扣除已包裝庫存,再按配方比例及烘焙損耗計算各成分所需的生豆量。文章以 15% 損耗率示範計算,並説明如何按批次安排烘焙、製作包裝清單及記錄實際產量以改善後續計劃。

正文

Disclosure: this post was written with AI assistance and reviewed by the author. #ABotWroteThis

Wholesale cafes order roasted coffee in whatever way is easiest for them: a WhatsApp message, a call, a spreadsheet. A roaster then has to turn that pile of messages into three answers: what finished stock already covers, how much of each blend component to roast, and what packing needs before dispatch.

This is a small, concrete way to model it. The numbers are made up. The loss rate and batch size are the parts you should replace with your own.

1. One list of orders

One row per cafe per product:

cafe product kg
Cafe A House Blend 10
Cafe B House Blend 6
Cafe C Ethiopia 4

2. Total, then subtract finished stock

House Blend: 10 + 6 = 16 kg ordered, 5 kg already packed, so produce 11 kg. Ethiopia: 4 kg ordered, none in stock, produce 4 kg. Only the shortfall goes to the roaster.

3. Split blends and convert to green weight

House Blend is 60% Arabica and 40% Robusta (by weight, post-roast). Roasting loses weight, so green needed = finished / (1 - loss). Using 15% loss:

from collections import defaultdict

orders = [("Cafe A", "House", 10), ("Cafe B", "House", 6), ("Cafe C", "Ethiopia", 4)]
stock = {"House": 5, "Ethiopia": 0}
blends = {"House": {"Arabica": 0.6, "Robusta": 0.4}, "Ethiopia": {"Ethiopia": 1.0}}
LOSS = 0.15

ordered = defaultdict(float)
for _, product, kg in orders:
    ordered[product] += kg

green = defaultdict(float)
for product, kg in ordered.items():
    make = max(kg - stock.get(product, 0), 0)
    for component, ratio in blends[product].items():
        green[component] += make * ratio / (1 - LOSS)

for component, kg in green.items():
    print(component, round(kg, 2), "kg green")

Output:

Arabica 7.76 kg green
Robusta 5.18 kg green
Ethiopia 4.71 kg green

Check this against your green stock before you commit. A short lot is cheaper to find on Monday than on Thursday.

4. Batches and the packing list

If your roaster takes a 5 kg green batch, decide up front whether you round up and hold the surplus or round to what the orders need, and write the rule down so the next person does the same. Packing needs the output, not the plan: for 250 g bags, 11 kg of House Blend is 44 bags (150 g Arabica plus 100 g Robusta each), and Ethiopia is 16 bags, grouped by cafe so dispatch can pack boxes.

5. Close the loop

After roasting, record actual output next to the plan. If you planned 11 kg and got 10.6 kg, your loss was about 18%, not 15%. That single number improves every plan after it.

Spreadsheet version

Sheet 1 Orders: date, cafe, product, kg. Sheet 2 Plan: product, ordered, in stock, to produce (=ordered-stock), component ratios, finished kg, green kg (=finished/(1-loss)). Sheet 3 Packing: cafe, product, bag size, bags.

A real example

Once the whole process was automated and easy at Ground Zero Coffee Roasters, all the repeat work was gone. They could put all their time into roasting, and they processed three times more coffee per month than before, immediately. It compounds, because the time you free up goes into roasting, into other things in coffee, and into family.

Where this stops scaling

A script or sheet is fine for a few cafes. When orders arrive on WhatsApp and by phone and you are re-keying them every week, errors creep in. I co-founded Daily Brew Ops, which keeps the cafes' ordering habit and gives the roaster one list to plan, roast, pack and bill from. Weigh that accordingly. The method above works with or without it.

來源:DEV Community · dev.to