Build the reorder list from stock levels.
Done by an agent. Checked twice.
A reorder list with quantities in full packs and costs by supplier, plus the stock rows that need a second look.
Real files in
- reorder_rules.md
The warehouse manager's reorder rules: safety days, cover days and what never gets reordered. 11 lines, 431 bytes. - stock.csv
Stock count for 45 items across five suppliers: 46 rows, with one row listed twice, one missing sales figure, one negative count and supplier names spelled three ways. 47 lines, 3 KB. - suppliers.csv
Five suppliers and the days each takes to deliver. 6 lines, 264 bytes.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read stock, suppliers and rules
- 2.Decide each item
- 3.Write the list and the review
Claude Sonnet 5.5, 43 seconds. No web. It never saw the check.
Checked twice
- Passed: 45 of 45 stock items appear once in stock_review.csv
- Passed: 45 of 45 decisions equal the decision recomputed from the stock file
- Passed: 39 of 39 reorder points and available counts equal the recomputed numbers
- Passed: reorder_list.csv holds 18 of 18 items that need ordering and 0 that do not
- Passed: 18 of 18 order quantities equal the recomputed quantity in full packs at or above the minimum
- Passed: 18 of 18 order lines carry the item name and unit cost from the stock file and a cost of quantity times unit cost under the right supplier
- Passed: summary.md states the order total for 5 of 5 suppliers and the total of all orders, 14,369.30
- Passed: 154 of 154 numbers in the reasons and in summary.md are that item's own figures, that supplier's count and total, or a count of the whole file
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 9 ways on purpose. The check caught 9.
- Kessler Chemical: 6 item(s) to order, total 6045.80 - Brannock Packaging: 3 item(s) to order, total 2112.50 - Pellham Paper Mills: 1 item(s) to order, total 1734.00 - Ironvale Tools: 3 item(s) to order, total 753.20 - Oakhurst Sundries: 5 item(s) to order, total 3723.80 **Total cost of all orders: 14369.30** ## Items needing attention - SKU-1056 (Descaler 1 L) - needs_review: Avg_daily_sales is blank; check the data before ordering. - SKU-1119 (Mailer bag A4) - needs_review: On_hand is -40, below zero; check the data before ordering. - SKU-1126 (Fragile labels roll) - no_sales: avg_daily_sales is 0, so nothing to reorder. - SKU-1252 (Couch roll 50 cm) - needs_review: Supplier 'Tidewater Paper' is not in suppliers.csv; check the data before ordering.
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 1 of 1 on 1 December 2026. The agent took 43 seconds.
What the second review verified
- Recomputed all 45 unique SKUs (SKU-1238 appears twice and was counted once). All 45 decisions, available values and reorder points in stock_review.csv match, including the edge cases SKU-1035 (85 vs 85 → reorder) and SKU-1098 (295 vs 294 → ok).
- Recomputed all 18 order quantities and costs. For example, SKU-1007: target ceil(3.5×47)=165, need 150, rounded up to full packs of 4 = 152, cost 1732.80. SKU-1140: need 24 is below the minimum of 30, so 30 is ordered, cost 480.00. Every row is in full packs, meets the minimum and matches the output.
- Supplier totals in summary.md match my recompute: Kessler 6 items / 6045.80, Brannock 3 / 2112.50, Pellham 1 / 1734.00, Ironvale 3 / 753.20, Oakhurst 5 / 3723.80. They add up to 14369.30, which equals the sum of order_cost in reorder_list.csv.
- Supplier names with odd capitals or spacing ('kessler chemical', 'BRANNOCK PACKAGING ') were matched and written as spelled in suppliers.csv. The summary lists all three needs_review items (SKU-1056 blank sales, SKU-1119 on_hand -40, SKU-1252 Tidewater Paper not in suppliers.csv) and the no_sales item SKU-1126.
What this run does not show
- The sample stock file holds one clear case of each data problem, where a real stock file is messier.
- The check applies the safety days and cover days as written and cannot say whether they suit the business.
- The worker and the check follow the same rules from the flow, so a wrong rule in the flow would pass both.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 9 of 9. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Build the reorder list from stock levels function: operations for: the person who buys stock for the warehouse goal: Every item that will run short before its next delivery is on a reorder list with a quantity and a cost. ## 1. Read stock, suppliers and rules Read input/stock.csv, input/suppliers.csv and input/reorder_rules.md. Take safety_days and cover_days from the rules file. Take each item's lead_time_days from suppliers.csv. Match supplier names without regard to capital letters or extra spaces. If the same sku appears twice with the same data, count it once. ## 2. Decide each item Give every sku one decision. Check in this order and use the first that applies: - `discontinued` when status is discontinued. - `needs_review` when avg_daily_sales is blank, on_hand is blank or below zero, or the supplier is not in suppliers.csv. - `no_sales` when avg_daily_sales is 0. - `reorder` when available is at or below reorder_point. - `ok` in every other case. available is on_hand plus on_order. reorder_point is avg_daily_sales times (lead_time_days plus safety_days), rounded up to a whole unit. For a `reorder` item work out order_qty like this: 1. target is avg_daily_sales times (lead_time_days plus safety_days plus cover_days), rounded up to a whole unit. 2. need is target minus available. 3. Round need up to a whole number of packs using pack_size. 4. If that is below min_order_qty, order min_order_qty. order_cost is order_qty times unit_cost, two decimals. ## 3. Write the list and the review Write output/stock_review.csv with columns sku,decision,available,reorder_point,reason. One row per sku. Fill available and reorder_point for `reorder` and `ok` rows and leave them blank for the others. reason is one plain sentence with the numbers that decided it. Write output/reorder_list.csv with columns sku,item,supplier,order_qty,unit_cost,order_cost. Only `reorder` items go in it. Write the supplier name as it is spelled in suppliers.csv. Write output/summary.md for the buyer: one line per supplier with the number of items to order and the total cost, then the total cost of all orders, then every `needs_review` and `no_sales` item with what is wrong. Write money with two decimals. ## Done looks like - Every sku appears once in stock_review.csv. - Every order quantity is in full packs and meets the supplier minimum. - The supplier totals in summary.md add up to the total cost of reorder_list.csv.
input/reorder_rules.md · 11 lines, 431 bytes
# Reorder rules Set by the warehouse manager. Reviewed each quarter. - safety_days: 7 - cover_days: 30 Safety days are the extra days of stock we hold on top of the supplier lead time. Cover days are how many days of sales one order should cover once it has arrived. We order full packs only. We never order below a supplier's minimum order quantity. We do not reorder discontinued items. We do not reorder items with no sales.
input/stock.csv · 47 lines, 3 KB
sku,item,supplier,on_hand,on_order,avg_daily_sales,pack_size,min_order_qty,unit_cost,status SKU-1007,Floor cleaner 5 L,Kessler Chemical,15,0,3.5,4,8,11.40,active SKU-1014,Glass cleaner 750 ml,Kessler Chemical,114,0,9,12,24,2.85,active SKU-1021,Degreaser 5 L,kessler chemical,9,0,1.8,4,8,14.20,active SKU-1028,Hand soap refill 1 L,Kessler Chemical,94,0,6.4,6,12,4.10,active SKU-1035,Bleach 4 L,Kessler Chemical,85,0,5,4,8,3.95,active SKU-1042,Dish detergent 5 L,Kessler Chemical,14,0,2.2,4,4,9.60,active SKU-1049,Disinfectant spray 500 ml,Kessler Chemical,252,0,7.5,12,24,3.30,active SKU-1056,Descaler 1 L,Kessler Chemical,3,0,,6,6,6.75,active SKU-1063,Oven cleaner 750 ml,Kessler Chemical,33,0,1.5,6,12,5.20,active SKU-1070,Carpet shampoo 5 L,Kessler Chemical,1,0,0.6,2,4,18.90,discontinued SKU-1077,Shipping box small,Brannock Packaging,24,450,42,25,100,0.62,active SKU-1084,Shipping box medium,Brannock Packaging,902,0,30,25,100,0.88,active SKU-1091,Shipping box large,Brannock Packaging,480,0,12.5,20,60,1.35,active SKU-1098,Packing tape 48 mm,Brannock Packaging,295,0,14,36,72,1.90,active SKU-1105,Bubble wrap roll 50 m,Brannock Packaging,18,0,1.2,4,8,13.50,active SKU-1112,Stretch film roll,BRANNOCK PACKAGING ,88,0,2.5,6,12,8.40,active SKU-1119,Mailer bag A4,Brannock Packaging,-40,0,65,100,200,0.14,active SKU-1126,Fragile labels roll,Brannock Packaging,14,0,0,10,10,3.20,active SKU-1133,Corner protectors,Brannock Packaging,558,0,22,50,100,0.21,active SKU-1140,Paper void fill 10 kg,Brannock Packaging,12,0,0.7,1,30,16.00,active SKU-1238,Hand towel c-fold,Pellham Paper Mills,152,0,26.5,20,40,1.70,active SKU-1147,Mop handle aluminium,Ironvale Tools,8,20,1.1,10,10,6.80,active SKU-1154,Mop head cotton,Ironvale Tools,225,0,4.2,12,24,3.45,active SKU-1161,Bucket with wringer,Ironvale Tools,24,0,0.4,2,4,27.50,active SKU-1168,Broom indoor,Ironvale Tools,5,66,1.6,6,12,7.10,active SKU-1175,Dustpan set,Ironvale Tools,10,0,0.9,6,6,5.90,active SKU-1182,Window squeegee 35 cm,Ironvale Tools,13,0,0.5,6,24,8.25,active SKU-1189,Spray bottle 750 ml,Ironvale Tools,234,0,6,24,48,1.15,active SKU-1196,Scraper blade pack,Ironvale Tools,76,0,2,10,20,2.40,active SKU-1203,Wet floor sign,Ironvale Tools,0,0,0.3,5,5,9.90,discontinued SKU-1210,Paper towel roll,Pellham Paper Mills,1448,0,55,16,48,1.05,active SKU-1217,Toilet tissue 2 ply,Pellham Paper Mills,310,1800,120,36,72,0.48,active SKU-1224,Centrefeed blue roll,Pellham Paper Mills,307,0,15,6,18,3.60,active SKU-1231,Facial tissue box,Pellham Paper Mills,403,0,18,24,48,0.95,active SKU-1238,Hand towel c-fold,Pellham Paper Mills,152,0,26.5,20,40,1.70,active SKU-1245,Napkins white,Pellham Paper Mills,1283,0,48,40,80,0.36,active SKU-1252,Couch roll 50 cm,Tidewater Paper,20,0,3.2,9,18,4.25,active SKU-1259,Kitchen roll twin pack,Pellham Paper Mills,266,0,11,12,24,1.60,active SKU-1266,Nitrile gloves M box,Oakhurst Sundries,36,40,8,10,20,5.40,active SKU-1273,Nitrile gloves L box,Oakhurst Sundries,56,0,6.5,10,20,5.40,active SKU-1280,Bin liners 50 L roll,Oakhurst Sundries,219,0,16,20,40,1.85,active SKU-1287,Bin liners 100 L roll,Oakhurst Sundries,215,0,9.5,20,40,2.70,active SKU-1294,Sponge scourer pack,Oakhurst Sundries,160,0,12,10,30,1.20,active SKU-1301,Microfibre cloth pack,Oakhurst Sundries,32,0,4.5,10,20,3.95,active SKU-1308,Air freshener refill,Oakhurst Sundries,25,0,3,12,12,2.60,active SKU-1315,Urinal blocks tub,Oakhurst Sundries,1,0,0.7,6,6,7.30,active
input/suppliers.csv · 6 lines, 264 bytes
supplier,lead_time_days,order_contact Kessler Chemical,10,orders@kessler.example Brannock Packaging,14,orders@brannock.example Ironvale Tools,21,orders@ironvale.example Pellham Paper Mills,7,orders@pellham.example Oakhurst Sundries,5,orders@oakhurst.example
output/reorder_list.csv · written by the agent, 19 lines
sku,item,supplier,order_qty,unit_cost,order_cost SKU-1007,Floor cleaner 5 L,Kessler Chemical,152,11.40,1732.80 SKU-1014,Glass cleaner 750 ml,Kessler Chemical,312,2.85,889.20 SKU-1021,Degreaser 5 L,Kessler Chemical,76,14.20,1079.20 SKU-1028,Hand soap refill 1 L,Kessler Chemical,210,4.10,861.00 SKU-1035,Bleach 4 L,Kessler Chemical,152,3.95,600.40 SKU-1042,Dish detergent 5 L,Kessler Chemical,92,9.60,883.20 SKU-1077,Shipping box small,Brannock Packaging,1675,0.62,1038.50 SKU-1105,Bubble wrap roll 50 m,Brannock Packaging,44,13.50,594.00 SKU-1140,Paper void fill 10 kg,Brannock Packaging,30,16.00,480.00 SKU-1238,Hand towel c-fold,Pellham Paper Mills,1020,1.70,1734.00 SKU-1147,Mop handle aluminium,Ironvale Tools,40,6.80,272.00 SKU-1175,Dustpan set,Ironvale Tools,48,5.90,283.20 SKU-1182,Window squeegee 35 cm,Ironvale Tools,24,8.25,198.00 SKU-1266,Nitrile gloves M box,Oakhurst Sundries,260,5.40,1404.00 SKU-1273,Nitrile gloves L box,Oakhurst Sundries,220,5.40,1188.00 SKU-1301,Microfibre cloth pack,Oakhurst Sundries,160,3.95,632.00 SKU-1308,Air freshener refill,Oakhurst Sundries,108,2.60,280.80 SKU-1315,Urinal blocks tub,Oakhurst Sundries,30,7.30,219.00
output/stock_review.csv · written by the agent, 46 lines
sku,decision,available,reorder_point,reason SKU-1007,reorder,15,60,"Available 15 is at or below reorder point 60; target 165, need 150, order 152." SKU-1014,reorder,114,153,"Available 114 is at or below reorder point 153; target 423, need 309, order 312." SKU-1021,reorder,9,31,"Available 9 is at or below reorder point 31; target 85, need 76, order 76." SKU-1028,reorder,94,109,"Available 94 is at or below reorder point 109; target 301, need 207, order 210." SKU-1035,reorder,85,85,"Available 85 is at or below reorder point 85; target 235, need 150, order 152." SKU-1042,reorder,14,38,"Available 14 is at or below reorder point 38; target 104, need 90, order 92." SKU-1049,ok,252,128,Available 252 is above reorder point 128. SKU-1056,needs_review,,,Avg_daily_sales is blank; check the data before ordering. SKU-1063,ok,33,26,Available 33 is above reorder point 26. SKU-1070,discontinued,,,"Status is discontinued, so it is not reordered." SKU-1077,reorder,474,882,"Available 474 is at or below reorder point 882; target 2142, need 1668, order 1675." SKU-1084,ok,902,630,Available 902 is above reorder point 630. SKU-1091,ok,480,263,Available 480 is above reorder point 263. SKU-1098,ok,295,294,Available 295 is above reorder point 294. SKU-1105,reorder,18,26,"Available 18 is at or below reorder point 26; target 62, need 44, order 44." SKU-1112,ok,88,53,Available 88 is above reorder point 53. SKU-1119,needs_review,,,"On_hand is -40, below zero; check the data before ordering." SKU-1126,no_sales,,,"avg_daily_sales is 0, so nothing to reorder." SKU-1133,ok,558,462,Available 558 is above reorder point 462. SKU-1140,reorder,12,15,"Available 12 is at or below reorder point 15; target 36, need 24, order 30." SKU-1238,reorder,152,371,"Available 152 is at or below reorder point 371; target 1166, need 1014, order 1020." SKU-1147,reorder,28,31,"Available 28 is at or below reorder point 31; target 64, need 36, order 40." SKU-1154,ok,225,118,Available 225 is above reorder point 118. SKU-1161,ok,24,12,Available 24 is above reorder point 12. SKU-1168,ok,71,45,Available 71 is above reorder point 45. SKU-1175,reorder,10,26,"Available 10 is at or below reorder point 26; target 53, need 43, order 48." SKU-1182,reorder,13,14,"Available 13 is at or below reorder point 14; target 29, need 16, order 24." SKU-1189,ok,234,168,Available 234 is above reorder point 168. SKU-1196,ok,76,56,Available 76 is above reorder point 56. SKU-1203,discontinued,,,"Status is discontinued, so it is not reordered." SKU-1210,ok,1448,770,Available 1448 is above reorder point 770. SKU-1217,ok,2110,1680,Available 2110 is above reorder point 1680. SKU-1224,ok,307,210,Available 307 is above reorder point 210. SKU-1231,ok,403,252,Available 403 is above reorder point 252. SKU-1245,ok,1283,672,Available 1283 is above reorder point 672. SKU-1252,needs_review,,,Supplier 'Tidewater Paper' is not in suppliers.csv; check the data before ordering. SKU-1259,ok,266,154,Available 266 is above reorder point 154. SKU-1266,reorder,76,96,"Available 76 is at or below reorder point 96; target 336, need 260, order 260." SKU-1273,reorder,56,78,"Available 56 is at or below reorder point 78; target 273, need 217, order 220." SKU-1280,ok,219,192,Available 219 is above reorder point 192. SKU-1287,ok,215,114,Available 215 is above reorder point 114. SKU-1294,ok,160,144,Available 160 is above reorder point 144. SKU-1301,reorder,32,54,"Available 32 is at or below reorder point 54; target 189, need 157, order 160." SKU-1308,reorder,25,36,"Available 25 is at or below reorder point 36; target 126, need 101, order 108." SKU-1315,reorder,1,9,"Available 1 is at or below reorder point 9; target 30, need 29, order 30."
output/summary.md · written by the agent, 20 lines
# Reorder summary ## Orders by supplier - Kessler Chemical: 6 item(s) to order, total 6045.80 - Brannock Packaging: 3 item(s) to order, total 2112.50 - Pellham Paper Mills: 1 item(s) to order, total 1734.00 - Ironvale Tools: 3 item(s) to order, total 753.20 - Oakhurst Sundries: 5 item(s) to order, total 3723.80 **Total cost of all orders: 14369.30** ## Items needing attention - SKU-1056 (Descaler 1 L) - needs_review: Avg_daily_sales is blank; check the data before ordering. - SKU-1119 (Mailer bag A4) - needs_review: On_hand is -40, below zero; check the data before ordering. - SKU-1126 (Fragile labels roll) - no_sales: avg_daily_sales is 0, so nothing to reorder. - SKU-1252 (Couch roll 50 cm) - needs_review: Supplier 'Tidewater Paper' is not in suppliers.csv; check the data before ordering. Notes: SKU-1238 appeared twice with identical data and was counted once. Supplier names were matched ignoring case and extra spaces.
check.py · the check, written before the run
"""Recomputes every reorder decision, quantity and cost from the stock file and compares with what the agent wrote."""
import csv, re, sys
from decimal import Decimal, ROUND_CEILING
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def up(d): return int(d.to_integral_value(rounding=ROUND_CEILING))
def key(s): return " ".join((s or "").split()).lower()
def whole(s):
try: return int(Decimal((s or "").strip()))
except Exception: return None
rules = (root/"input/reorder_rules.md").read_text()
safety = int(re.search(r"safety_days:\s*(\d+)", rules).group(1)); cover = int(re.search(r"cover_days:\s*(\d+)", rules).group(1))
sup = {key(r["supplier"]): (r["supplier"].strip(), int(r["lead_time_days"])) for r in csv.DictReader((root/"input/suppliers.csv").open())}
want = {}; stock = {}; raw_rows = 0
for r in csv.DictReader((root/"input/stock.csv").open()):
raw_rows += 1
if r["sku"] in want: continue
stock[r["sku"]] = r
s = sup.get(key(r["supplier"])); oh = whole(r["on_hand"])
if r["status"].strip().lower() == "discontinued": want[r["sku"]] = {"d": "discontinued"}
elif not r["avg_daily_sales"].strip() or oh is None or oh < 0 or s is None: want[r["sku"]] = {"d": "needs_review"}
elif Decimal(r["avg_daily_sales"]) == 0: want[r["sku"]] = {"d": "no_sales"}
else:
daily = Decimal(r["avg_daily_sales"]); avail = oh + (whole(r["on_order"]) or 0)
point = up(daily * (s[1] + safety)); w = {"d": "ok", "avail": avail, "point": point}
if avail <= point:
pack, low = int(r["pack_size"]), int(r["min_order_qty"])
need = up(daily * (s[1] + safety + cover)) - avail
qty = max(-(-need // pack) * pack, low)
w.update(d="reorder", qty=qty, cost=qty * Decimal(r["unit_cost"]), supplier=s[0], target=need + avail, need=need, packs=qty // pack)
want[r["sku"]] = w
path = root/"output/stock_review.csv"
if not path.exists():
say(False, "output/stock_review.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {r.get("sku", ""): r for r in rows}
once = sum(1 for k in want if sum(1 for r in rows if r.get("sku") == k) == 1)
say(once == len(want) and len(rows) == len(want), f"{once} of {len(want)} stock items appear once in stock_review.csv")
right = sum(1 for k, w in want.items() if (got.get(k, {}).get("decision") or "").strip() == w["d"])
say(right == len(want), f"{right} of {len(want)} decisions equal the decision recomputed from the stock file")
live = [k for k, w in want.items() if "point" in w]
pts = sum(1 for k in live if whole(got.get(k, {}).get("reorder_point")) == want[k]["point"] and whole(got.get(k, {}).get("available")) == want[k]["avail"])
say(pts == len(live), f"{pts} of {len(live)} reorder points and available counts equal the recomputed numbers")
need = [k for k, w in want.items() if w["d"] == "reorder"]
lpath = root/"output/reorder_list.csv"
lrows = list(csv.DictReader(lpath.open())) if lpath.exists() else []
lgot = {r.get("sku", ""): r for r in lrows}
say(set(lgot) == set(need) and len(lrows) == len(need), f"reorder_list.csv holds {len(set(lgot) & set(need))} of {len(need)} items that need ordering and {len(set(lgot) - set(need))} that do not")
def money(s):
try: return Decimal((s or "").replace(",", "").replace("$", "").strip())
except Exception: return None
qty = sum(1 for k in need if whole(lgot.get(k, {}).get("order_qty")) == want[k]["qty"])
say(qty == len(need), f"{qty} of {len(need)} order quantities equal the recomputed quantity in full packs at or above the minimum")
cost = sum(1 for k in need if money(lgot.get(k, {}).get("order_cost")) == want[k]["cost"] and key(lgot[k].get("supplier")) == key(want[k]["supplier"])
and money(lgot[k].get("unit_cost")) == Decimal(stock[k]["unit_cost"]) and key(lgot[k].get("item")) == key(stock[k]["item"]))
say(cost == len(need), f"{cost} of {len(need)} order lines carry the item name and unit cost from the stock file and a cost of quantity times unit cost under the right supplier")
summary = (root/"output/summary.md").read_text() if (root/"output/summary.md").exists() else ""
def has(line_or_text, amount): return any(Decimal(n.replace(",", "")) == amount for n in re.findall(r"\d[\d,]*\.\d{2}", line_or_text))
totals = {}
for k in need: totals[want[k]["supplier"]] = totals.get(want[k]["supplier"], Decimal(0)) + want[k]["cost"]
named = sum(1 for s, t in totals.items() if any(s.lower() in ln.lower() and has(ln, t) for ln in summary.splitlines()))
grand = sum(totals.values())
say(named == len(totals) and has(summary, grand), f"summary.md states the order total for {named} of {len(totals)} suppliers and the total of all orders, {grand:,.2f}")
# Numbers in the reasons and the summary: beside one item they must be that item's own figures, beside a supplier its count and total.
def figures(s): return [Decimal(n.replace(",", "")) for n in re.findall(r"(?<![\w.])\d[\d,]*(?:\.\d+)?(?![\w]|\.\d)", re.sub(r"\bSKU-\d+\b", " ", s))]
def own(k):
r, w = stock[k], want[k]; s = sup.get(key(r["supplier"]))
f = {Decimal(n) for c in ("item", "on_hand", "on_order", "avg_daily_sales", "pack_size", "min_order_qty", "unit_cost") for n in re.findall(r"\d+(?:\.\d+)?", r[c])} | {Decimal(0), Decimal(safety), Decimal(cover)}
f |= {Decimal(str(w[c])) for c in ("avail", "point", "qty", "cost", "target", "need", "packs") if c in w}
if s: f |= {Decimal(s[1]), Decimal(s[1] + safety), Decimal(s[1] + safety + cover)}
return f
seen = wrong = 0; odd = []
for k in want:
for n in figures(got.get(k, {}).get("reason") or ""):
seen += 1
if n not in own(k): wrong += 1; odd.append(f"{n} for {k}")
tally = {}
for w in want.values(): tally[w["d"]] = tally.get(w["d"], 0) + 1
world = {Decimal(x) for x in (len(want), raw_rows, raw_rows - len(want), len(need), len(totals), safety, cover)} | {Decimal(v) for v in tally.values()} | {grand}
for ln in summary.splitlines():
skus = re.findall(r"\bSKU-\d+\b", ln); here = [s for s in totals if s.lower() in ln.lower()]
for k in skus: # an item number must be real and sit beside its own item name
seen += 1
if k not in stock or (any(key(r["item"]) in key(ln) for r in stock.values()) and key(stock[k]["item"]) not in key(ln)): wrong += 1; odd.append(k)
known = [k for k in skus if k in stock]
if known: allowed = set().union(*(own(k) for k in known))
elif here: allowed = set().union(*({Decimal(sum(1 for k in need if want[k]["supplier"] == s)), totals[s]} for s in here))
else: allowed = world
for n in figures(ln):
seen += 1
if n not in allowed: wrong += 1; odd.append(str(n))
say(seen > 0 and wrong == 0, f"{seen - wrong} of {seen} numbers in the reasons and in summary.md are that item's own figures, that supplier's count and total, or a count of the whole file" + (": not " + ", ".join(odd[:3]) if odd else ""))
sys.exit(0 if ok else 1)
reorder_rules.md: sample data written by Atris. Fingerprint f131c00e5c27.
stock.csv: sample data written by Atris. Fingerprint 992c3e5379d9.
suppliers.csv: sample data written by Atris. Fingerprint f2dfbde63c15.
reorder_list.csv: written by the agent. Fingerprint a006c42dc58b.
stock_review.csv: written by the agent. Fingerprint 9b859a6e9398.
summary.md: written by the agent. Fingerprint bdfb4eeab310.