Build quotes from prices and discount rules.
Done by an agent. Checked twice.
Each request becomes a priced quote that follows your discount rules to the cent, with unquotable lines listed and explained.
Real files in
- discount_rules.md
The seller's written quoting rules: volume and customer discounts, a cap, rounding, approval and validity. 65 lines, 2 KB. - price_list.csv
A coffee equipment seller's price list of 25 products, two of them discontinued. 26 lines, 1 KB. - quote_requests.csv
Six quote requests with 48 lines, including repeated items, items typed by name, a blank quantity and products that do not exist. 49 lines, 3 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read the rules, prices and requests
- 2.Price every line
- 3.Total each quote and write it up
Claude Sonnet 5.5, 51 seconds. No web. It never saw the check.
Checked twice
- Passed: 38 of 38 quote lines are present, one per product, with 0 lines that should not be there
- Passed: 38 of 38 lines have the product name, list price, quantity and discount the price list and rules give, with a note only on lines that replace a discontinued product
- Passed: 38 of 38 lines have the unit price and line total worked out again to the cent
- Passed: 7 of 7 lines that cannot be quoted are in issues.csv with the right reason
- Passed: 6 of 6 quote totals equal the sum of their lines, 255,454.06 in all
- Passed: 6 of 6 quotes have the right customer, line count, approval answer and valid until date, with 3 needing approval
- Passed: quotes.md shows 6 of 6 quotes with the same total
- Passed: 38 of 38 quote lines are written out in quotes.md with the right quantity, discount and line total
- Passed: 204 of 204 numbers and dates in quotes.md are the worked out figures for that line or quote, or come from that request, its products or the rules
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 12 ways on purpose. The check caught 12.
Customer type: reseller. Request date: 2026-11-24. - ESP-100 Single boiler espresso machine: qty 12 at 2280.00 each, 20% discount, line total 27360.00 - GRD-10 On demand grinder: qty 30 at 712.00 each, 20% discount, line total 21360.00 - GRD-20 Bulk shop grinder: qty 4 at 1206.00 each, 10% discount, line total 4824.00 - FLT-12 Filter cartridge case of 12: qty 60 at 152.52 each, 18% discount, line total 9151.20 - CUP-08 Paper cups 8 oz case of 1000: qty 40 at 52.72 each, 14% discount, line total 2108.80 - KNK-01 Knock box drawer: qty 10 at 76.00 each, 20% discount, line total 760.00 - SVC-INS Machine installation: qty 2 at 450.00 each, 0% discount, line total 900.00 - ESP-300 Three group espresso machine: qty 6 at 6715.00 each, 15% discount, line total 40290.00 **Quote total: 106754.00** Needs approval: yes - a line carries 20% discount (over 15%); total is above 50,000.00
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 51 seconds.
What the second review verified
- Repriced all 38 quote lines by hand from the price list and rules (the shell blocked my script). Every net price and line total matches, including the half-cent cases: TMP-58 42.50 at 5% = 40.375, rounded to 40.38; PIT-06 18.75 at 10% = 16.875, rounded to 16.88; CUP-08 61.30 at 5% = 58.235, rounded to 58.24
- Repeated items were combined and discontinued items handled correctly: 'esp 200' 2 + ESP-200 3 = 5 at 5% (20187.50); ESP-150 4 became ESP-100 and joined ESP-100 2 for 6 at 5% with the note 'replaces ESP-150' (16245.00); CUP-08 4 + 'cup-08' 3 = 7 at 5% (407.68); 'Knock box drawer' matched to KNK-01 at 20% (760.00)
- The 20% cap and the approval rule are applied correctly: Q-802 GRD-10 15% volume + 10% reseller is capped at 20%, and Q-805 BRW-40 likewise. Q-802 (106754.00), Q-804 (78799.00) and Q-805 (31614.30, a line over 15%) need approval; Q-801, Q-803 and Q-806 do not
- All 48 request rows are accounted for, each on exactly one quote line or in issues.csv, with the right reason: GRD-05 discontinued, PIT-06 qty 4 and TMP-58 qty 1 below_minimum, CUP-12 blank and KNK-01 qty 0 no_quantity, 'Milk frother wand' and BRW-99 unknown_item. All 6 totals add up (e.g. Q-801 29472.10, Q-806 4902.72), and valid_until is the request date + 30 days (e.g. 2026-11-30 gives 2026-12-30)
What this run does not show
- The price list, the rules and the six requests were written by Atris. A real price list has more products and more special cases.
- The first check did not test product name, list price, line count or the figures inside the written quotes. The stricter check tests all of them and the same output passed.
- The plain word reasons for approval and for lines left off are read only by the second review.
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 12 of 12. 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 quotes from prices and discount rules function: sales for: the inside seller who turns quote requests into quotes goal: Every request has a priced quote that follows the discount rules to the cent. Every line that could not be quoted is listed with the reason. ## 1. Read the rules, prices and requests Read input/discount_rules.md from top to bottom, then input/price_list.csv and input/quote_requests.csv. The rules file is the only rulebook. It says how to match what the customer typed to a product, which lines cannot be quoted, which discounts apply and how they combine, how to round and when a quote needs approval. Each request_id is one quote. Its rows are the lines the customer asked for. ## 2. Price every line Work through each request. Match each row to a product, combine repeats, set aside the rows the rules say cannot be quoted and price the rest. Do the arithmetic with python3, not by eye. Use exact decimal arithmetic for money, not floating point, so that half cents round the way the rules say. Write output/quote_lines.csv with columns request_id,sku,name,quantity,list_price,discount_pct,net_unit_price,line_total,note. One row per product on each quote. sku and name are as the price list writes them. discount_pct is the discount on the line as a number, for example 15. Money has two decimals. note is blank unless the rules ask for one. Write output/issues.csv with columns request_id,item,reason. One row for every request row that was left off its quote. item is what the customer typed. reason is the reason word from the rules. ## 3. Total each quote and write it up Write output/quote_totals.csv with columns request_id,customer,line_count,total,needs_approval,valid_until. One row per request. needs_approval is yes or no. valid_until is a date like 2026-03-05. Write output/quotes.md with one section per request: the customer, each line with quantity, discount and line total, the quote total, whether it needs approval and why, the date it is valid until and any lines left off with the reason in plain words. ## Done looks like - Every request row ends up on a quote line or in issues.csv, never both and never neither. - Every price can be worked out again from the price list and the rules. - Each total equals the sum of its lines.
input/discount_rules.md · 65 lines, 2 KB
# Quoting rules Fennimore Coffee Equipment, inside sales. In force from 1 October 2026. Prices are in US dollars and do not include tax or freight. ## Finding the item - Match the item to a sku on the price list. Ignore capital letters, spaces and dashes, so `esp 200` is ESP-200. - If the item is not a sku but is exactly a product name on the price list, ignoring capital letters, use that product. - If the same product appears more than once in one request, add the quantities and quote one line. - A blank customer type means standard. Ignore capital letters in the customer type. ## Lines that cannot be quoted Leave these off the quote and write them to the issues file with the reason word shown. | Reason | When | |---|---| | unknown_item | The item matches no sku and no product name. | | no_quantity | The quantity is blank or zero. | | discontinued | The product is discontinued and the price list names no replacement. | | below_minimum | The quantity, after adding repeats, is under the product's min_qty. | A discontinued product that has a replacement is quoted as the replacement, at the replacement's price, and the note on the line says which product it replaces. If the replacement is also asked for in the same request, add the quantities. ## Discounts Volume discount, by the quantity on the line: | Category | Quantity | Discount | |---|---|---| | Hardware | 1 to 4 | 0% | | Hardware | 5 to 9 | 5% | | Hardware | 10 to 24 | 10% | | Hardware | 25 or more | 15% | | Consumables | 1 to 9 | 0% | | Consumables | 10 to 49 | 4% | | Consumables | 50 or more | 8% | | Services | any | 0% | Customer discount, added to the volume discount: | Customer type | Hardware | Consumables | Services | |---|---|---|---| | standard | 0% | 0% | 0% | | reseller | 10% | 10% | 0% | | nonprofit | 5% | 5% | 0% | The two discounts are added together. No line may carry more than 20%. If the sum is higher, use 20%. ## Arithmetic - net_unit_price is list price less the discount, rounded to the cent. Half a cent rounds up. - line_total is net_unit_price times quantity. - The quote total is the sum of its line totals. ## Approval and validity - A quote needs a manager's approval when any line carries more than 15% discount or the quote total is above 50,000.00. - A quote is valid for 30 days. valid_until is the request date plus 30 days.
input/price_list.csv · 26 lines, 1 KB
sku,name,category,list_price,min_qty,status,replaced_by ESP-100,Single boiler espresso machine,Hardware,2850.00,1,active, ESP-200,Twin boiler espresso machine,Hardware,4250.00,1,active, ESP-300,Three group espresso machine,Hardware,7900.00,1,active, ESP-150,Compact espresso machine,Hardware,3100.00,1,discontinued,ESP-100 GRD-10,On demand grinder,Hardware,890.00,1,active, GRD-20,Bulk shop grinder,Hardware,1340.00,1,active, GRD-05,Hand dosing grinder,Hardware,610.00,1,discontinued, BRW-40,Batch brewer 4 litre,Hardware,1180.00,1,active, BRW-80,Batch brewer 8 litre,Hardware,1725.00,1,active, WTR-01,Water filter housing,Hardware,215.00,1,active, WTR-02,Water softener unit,Hardware,640.00,1,active, KNK-01,Knock box drawer,Hardware,95.00,2,active, TMP-58,Tamper 58 mm,Hardware,42.50,2,active, PIT-06,Milk pitcher 600 ml,Hardware,18.75,6,active, FLT-12,Filter cartridge case of 12,Consumables,186.00,1,active, CLN-24,Cleaning tablets case of 24 jars,Consumables,138.40,1,active, DSC-10,Descaler case of 10 litres,Consumables,74.60,1,active, CUP-08,Paper cups 8 oz case of 1000,Consumables,61.30,5,active, CUP-12,Paper cups 12 oz case of 1000,Consumables,68.90,5,active, LID-00,Cup lids case of 1000,Consumables,34.20,5,active, GSK-58,Group gasket pack of 10,Consumables,27.50,1,active, SVC-INS,Machine installation,Services,450.00,1,active, SVC-TRN,Barista training half day,Services,380.00,1,active, SVC-PM1,Preventive maintenance visit,Services,295.00,1,active, SVC-WTR,Water test and filter setup,Services,160.00,1,active,
input/quote_requests.csv · 49 lines, 3 KB
request_id,request_date,customer,customer_type,item,quantity Q-801,2026-11-23,Linden Row Cafes,standard,ESP-200,3 Q-801,2026-11-23,Linden Row Cafes,standard,GRD-10,6 Q-801,2026-11-23,Linden Row Cafes,standard,WTR-01,3 Q-801,2026-11-23,Linden Row Cafes,standard,SVC-INS,3 Q-801,2026-11-23,Linden Row Cafes,standard,SVC-TRN,1 Q-801,2026-11-23,Linden Row Cafes,standard,CLN-24,12 Q-801,2026-11-23,Linden Row Cafes,standard,esp 200,2 Q-801,2026-11-23,Linden Row Cafes,standard,TMP-58,6 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,ESP-100,12 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,GRD-10,30 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,grd-20,4 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,FLT-12,60 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,CUP-08,40 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,Knock box drawer,10 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,SVC-INS,2 Q-802,2026-11-24,Harbour Bean Wholesale,Reseller,ESP-300,6 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,BRW-40,2 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,CUP-12,10 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,LID-00,10 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,DSC-10,2 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,SVC-PM1,2 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,PIT-06,4 Q-803,2026-11-24,Wren Street Shelter Kitchen,nonprofit,GRD-05,1 Q-804,2026-11-25,Oakhollow Hotel Group,,ESP-300,5 Q-804,2026-11-25,Oakhollow Hotel Group,,ESP-150,4 Q-804,2026-11-25,Oakhollow Hotel Group,,ESP-100,2 Q-804,2026-11-25,Oakhollow Hotel Group,,BRW-80,10 Q-804,2026-11-25,Oakhollow Hotel Group,,WTR-02,5 Q-804,2026-11-25,Oakhollow Hotel Group,,SVC-INS,12 Q-804,2026-11-25,Oakhollow Hotel Group,,SVC-WTR,5 Q-804,2026-11-25,Oakhollow Hotel Group,,Milk frother wand,5 Q-804,2026-11-25,Oakhollow Hotel Group,,GSK-58,10 Q-805,2026-11-27,Pemberley Office Coffee,reseller,BRW-40,25 Q-805,2026-11-27,Pemberley Office Coffee,reseller,CUP-08,50 Q-805,2026-11-27,Pemberley Office Coffee,reseller,CUP-12, Q-805,2026-11-27,Pemberley Office Coffee,reseller,LID-00,100 Q-805,2026-11-27,Pemberley Office Coffee,reseller,FLT-12,9 Q-805,2026-11-27,Pemberley Office Coffee,reseller,CLN-24,10 Q-805,2026-11-27,Pemberley Office Coffee,reseller,TMP-58,1 Q-805,2026-11-27,Pemberley Office Coffee,reseller,BRW-99,3 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,ESP-100,1 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,GRD-10,1 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,PIT-06,6 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,TMP-58,2 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,SVC-TRN,2 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,CUP-08,4 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,cup-08,3 Q-806,2026-11-30,Third Wave Campus Co-op,NONPROFIT,KNK-01,0
output/issues.csv · written by the agent, 8 lines
request_id,item,reason Q-803,GRD-05,discontinued Q-803,PIT-06,below_minimum Q-804,Milk frother wand,unknown_item Q-805,CUP-12,no_quantity Q-805,BRW-99,unknown_item Q-805,TMP-58,below_minimum Q-806,KNK-01,no_quantity
output/quote_lines.csv · written by the agent, 39 lines
request_id,sku,name,quantity,list_price,discount_pct,net_unit_price,line_total,note Q-801,ESP-200,Twin boiler espresso machine,5,4250.00,5,4037.50,20187.50, Q-801,GRD-10,On demand grinder,6,890.00,5,845.50,5073.00, Q-801,WTR-01,Water filter housing,3,215.00,0,215.00,645.00, Q-801,SVC-INS,Machine installation,3,450.00,0,450.00,1350.00, Q-801,SVC-TRN,Barista training half day,1,380.00,0,380.00,380.00, Q-801,CLN-24,Cleaning tablets case of 24 jars,12,138.40,4,132.86,1594.32, Q-801,TMP-58,Tamper 58 mm,6,42.50,5,40.38,242.28, Q-802,ESP-100,Single boiler espresso machine,12,2850.00,20,2280.00,27360.00, Q-802,GRD-10,On demand grinder,30,890.00,20,712.00,21360.00, Q-802,GRD-20,Bulk shop grinder,4,1340.00,10,1206.00,4824.00, Q-802,FLT-12,Filter cartridge case of 12,60,186.00,18,152.52,9151.20, Q-802,CUP-08,Paper cups 8 oz case of 1000,40,61.30,14,52.72,2108.80, Q-802,KNK-01,Knock box drawer,10,95.00,20,76.00,760.00, Q-802,SVC-INS,Machine installation,2,450.00,0,450.00,900.00, Q-802,ESP-300,Three group espresso machine,6,7900.00,15,6715.00,40290.00, Q-803,BRW-40,Batch brewer 4 litre,2,1180.00,5,1121.00,2242.00, Q-803,CUP-12,Paper cups 12 oz case of 1000,10,68.90,9,62.70,627.00, Q-803,LID-00,Cup lids case of 1000,10,34.20,9,31.12,311.20, Q-803,DSC-10,Descaler case of 10 litres,2,74.60,5,70.87,141.74, Q-803,SVC-PM1,Preventive maintenance visit,2,295.00,0,295.00,590.00, Q-804,ESP-300,Three group espresso machine,5,7900.00,5,7505.00,37525.00, Q-804,ESP-100,Single boiler espresso machine,6,2850.00,5,2707.50,16245.00,replaces ESP-150 Q-804,BRW-80,Batch brewer 8 litre,10,1725.00,10,1552.50,15525.00, Q-804,WTR-02,Water softener unit,5,640.00,5,608.00,3040.00, Q-804,SVC-INS,Machine installation,12,450.00,0,450.00,5400.00, Q-804,SVC-WTR,Water test and filter setup,5,160.00,0,160.00,800.00, Q-804,GSK-58,Group gasket pack of 10,10,27.50,4,26.40,264.00, Q-805,BRW-40,Batch brewer 4 litre,25,1180.00,20,944.00,23600.00, Q-805,CUP-08,Paper cups 8 oz case of 1000,50,61.30,18,50.27,2513.50, Q-805,LID-00,Cup lids case of 1000,100,34.20,18,28.04,2804.00, Q-805,FLT-12,Filter cartridge case of 12,9,186.00,10,167.40,1506.60, Q-805,CLN-24,Cleaning tablets case of 24 jars,10,138.40,14,119.02,1190.20, Q-806,ESP-100,Single boiler espresso machine,1,2850.00,5,2707.50,2707.50, Q-806,GRD-10,On demand grinder,1,890.00,5,845.50,845.50, Q-806,PIT-06,Milk pitcher 600 ml,6,18.75,10,16.88,101.28, Q-806,TMP-58,Tamper 58 mm,2,42.50,5,40.38,80.76, Q-806,SVC-TRN,Barista training half day,2,380.00,0,380.00,760.00, Q-806,CUP-08,Paper cups 8 oz case of 1000,7,61.30,5,58.24,407.68,
output/quote_totals.csv · written by the agent, 7 lines
request_id,customer,line_count,total,needs_approval,valid_until Q-801,Linden Row Cafes,7,29472.10,no,2026-12-23 Q-802,Harbour Bean Wholesale,8,106754.00,yes,2026-12-24 Q-803,Wren Street Shelter Kitchen,5,3911.94,no,2026-12-24 Q-804,Oakhollow Hotel Group,7,78799.00,yes,2026-12-25 Q-805,Pemberley Office Coffee,5,31614.30,yes,2026-12-27 Q-806,Third Wave Campus Co-op,6,4902.72,no,2026-12-30
output/quotes.md · written by the agent, 126 lines
# Quotes Prices in US dollars, excluding tax and freight. ## Q-801 - Linden Row Cafes Customer type: standard. Request date: 2026-11-23. - ESP-200 Twin boiler espresso machine: qty 5 at 4037.50 each, 5% discount, line total 20187.50 - GRD-10 On demand grinder: qty 6 at 845.50 each, 5% discount, line total 5073.00 - WTR-01 Water filter housing: qty 3 at 215.00 each, 0% discount, line total 645.00 - SVC-INS Machine installation: qty 3 at 450.00 each, 0% discount, line total 1350.00 - SVC-TRN Barista training half day: qty 1 at 380.00 each, 0% discount, line total 380.00 - CLN-24 Cleaning tablets case of 24 jars: qty 12 at 132.86 each, 4% discount, line total 1594.32 - TMP-58 Tamper 58 mm: qty 6 at 40.38 each, 5% discount, line total 242.28 **Quote total: 29472.10** Needs approval: no - no line is over 15% discount and the total is not above 50,000.00 Valid until: 2026-12-23 Left off the quote: none ## Q-802 - Harbour Bean Wholesale Customer type: reseller. Request date: 2026-11-24. - ESP-100 Single boiler espresso machine: qty 12 at 2280.00 each, 20% discount, line total 27360.00 - GRD-10 On demand grinder: qty 30 at 712.00 each, 20% discount, line total 21360.00 - GRD-20 Bulk shop grinder: qty 4 at 1206.00 each, 10% discount, line total 4824.00 - FLT-12 Filter cartridge case of 12: qty 60 at 152.52 each, 18% discount, line total 9151.20 - CUP-08 Paper cups 8 oz case of 1000: qty 40 at 52.72 each, 14% discount, line total 2108.80 - KNK-01 Knock box drawer: qty 10 at 76.00 each, 20% discount, line total 760.00 - SVC-INS Machine installation: qty 2 at 450.00 each, 0% discount, line total 900.00 - ESP-300 Three group espresso machine: qty 6 at 6715.00 each, 15% discount, line total 40290.00 **Quote total: 106754.00** Needs approval: yes - a line carries 20% discount (over 15%); total is above 50,000.00 Valid until: 2026-12-24 Left off the quote: none ## Q-803 - Wren Street Shelter Kitchen Customer type: nonprofit. Request date: 2026-11-24. - BRW-40 Batch brewer 4 litre: qty 2 at 1121.00 each, 5% discount, line total 2242.00 - CUP-12 Paper cups 12 oz case of 1000: qty 10 at 62.70 each, 9% discount, line total 627.00 - LID-00 Cup lids case of 1000: qty 10 at 31.12 each, 9% discount, line total 311.20 - DSC-10 Descaler case of 10 litres: qty 2 at 70.87 each, 5% discount, line total 141.74 - SVC-PM1 Preventive maintenance visit: qty 2 at 295.00 each, 0% discount, line total 590.00 **Quote total: 3911.94** Needs approval: no - no line is over 15% discount and the total is not above 50,000.00 Valid until: 2026-12-24 Left off the quote: - GRD-05: discontinued (discontinued with no replacement named) - PIT-06: below_minimum (quantity is under the product minimum order) ## Q-804 - Oakhollow Hotel Group Customer type: standard. Request date: 2026-11-25. - ESP-300 Three group espresso machine: qty 5 at 7505.00 each, 5% discount, line total 37525.00 - ESP-100 Single boiler espresso machine: qty 6 at 2707.50 each, 5% discount, line total 16245.00 (replaces ESP-150) - BRW-80 Batch brewer 8 litre: qty 10 at 1552.50 each, 10% discount, line total 15525.00 - WTR-02 Water softener unit: qty 5 at 608.00 each, 5% discount, line total 3040.00 - SVC-INS Machine installation: qty 12 at 450.00 each, 0% discount, line total 5400.00 - SVC-WTR Water test and filter setup: qty 5 at 160.00 each, 0% discount, line total 800.00 - GSK-58 Group gasket pack of 10: qty 10 at 26.40 each, 4% discount, line total 264.00 **Quote total: 78799.00** Needs approval: yes - total is above 50,000.00 Valid until: 2026-12-25 Left off the quote: - Milk frother wand: unknown_item (not on the price list by sku or product name) ## Q-805 - Pemberley Office Coffee Customer type: reseller. Request date: 2026-11-27. - BRW-40 Batch brewer 4 litre: qty 25 at 944.00 each, 20% discount, line total 23600.00 - CUP-08 Paper cups 8 oz case of 1000: qty 50 at 50.27 each, 18% discount, line total 2513.50 - LID-00 Cup lids case of 1000: qty 100 at 28.04 each, 18% discount, line total 2804.00 - FLT-12 Filter cartridge case of 12: qty 9 at 167.40 each, 10% discount, line total 1506.60 - CLN-24 Cleaning tablets case of 24 jars: qty 10 at 119.02 each, 14% discount, line total 1190.20 **Quote total: 31614.30** Needs approval: yes - a line carries 20% discount (over 15%) Valid until: 2026-12-27 Left off the quote: - CUP-12: no_quantity (quantity blank or zero) - BRW-99: unknown_item (not on the price list by sku or product name) - TMP-58: below_minimum (quantity is under the product minimum order) ## Q-806 - Third Wave Campus Co-op Customer type: nonprofit. Request date: 2026-11-30. - ESP-100 Single boiler espresso machine: qty 1 at 2707.50 each, 5% discount, line total 2707.50 - GRD-10 On demand grinder: qty 1 at 845.50 each, 5% discount, line total 845.50 - PIT-06 Milk pitcher 600 ml: qty 6 at 16.88 each, 10% discount, line total 101.28 - TMP-58 Tamper 58 mm: qty 2 at 40.38 each, 5% discount, line total 80.76 - SVC-TRN Barista training half day: qty 2 at 380.00 each, 0% discount, line total 760.00 - CUP-08 Paper cups 8 oz case of 1000: qty 7 at 58.24 each, 5% discount, line total 407.68 **Quote total: 4902.72** Needs approval: no - no line is over 15% discount and the total is not above 50,000.00 Valid until: 2026-12-30 Left off the quote: - KNK-01: no_quantity (quantity blank or zero)
check.py · the check, written before the run
"""Prices every request again from the price list and the written rules, then compares line by line."""
import csv, re, sys
from datetime import date, timedelta
from decimal import Decimal, ROUND_HALF_UP
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 key(text): return re.sub(r"[\s-]", "", text).lower()
prices = list(csv.DictReader((root/"input/price_list.csv").open()))
by_sku = {key(p["sku"]): p for p in prices}; by_name = {p["name"].strip().lower(): p for p in prices}
VOLUME = {"Hardware": [(25, 15), (10, 10), (5, 5)], "Consumables": [(50, 8), (10, 4)], "Services": []}
CUSTOMER = {"standard": 0, "reseller": 10, "nonprofit": 5}
requests = {}
for r in csv.DictReader((root/"input/quote_requests.csv").open()): requests.setdefault(r["request_id"], []).append(r)
lines, issues, totals = {}, set(), {}
for rid, rows in requests.items():
kind = rows[0]["customer_type"].strip().lower() or "standard"; qty, typed, swapped = {}, {}, {}
for r in rows:
p = by_sku.get(key(r["item"])) or by_name.get(r["item"].strip().lower())
if not p: issues.add((rid, r["item"].strip(), "unknown_item")); continue
q = int(r["quantity"]) if r["quantity"].strip().isdigit() else 0
if q == 0: issues.add((rid, r["item"].strip(), "no_quantity")); continue
if p["status"] == "discontinued":
if not p["replaced_by"]: issues.add((rid, r["item"].strip(), "discontinued")); continue
swapped[p["replaced_by"]] = p["sku"]; p = by_sku[key(p["replaced_by"])]
qty[p["sku"]] = qty.get(p["sku"], 0) + q; typed.setdefault(p["sku"], []).append(r["item"].strip())
total = Decimal(0); count = 0
for sku, q in qty.items():
p = by_sku[key(sku)]
if q < int(p["min_qty"]):
issues.update((rid, t, "below_minimum") for t in typed[sku]); continue
pct = next((d for least, d in VOLUME[p["category"]] if q >= least), 0) + (0 if p["category"] == "Services" else CUSTOMER[kind])
pct = min(pct, 20)
net = (Decimal(p["list_price"]) * (100 - pct) / 100).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
lines[(rid, sku)] = dict(q=q, pct=pct, net=net, total=net * q, swapped=swapped.get(sku), name=p["name"].strip(), list=Decimal(p["list_price"])); total += net * q; count += 1
totals[rid] = dict(total=total, count=count, customer=rows[0]["customer"].strip(), asked=rows[0]["request_date"].strip(), approve="yes" if total > 50000 or any(v["pct"] > 15 for (r_, _), v in lines.items() if r_ == rid) else "no",
until=(date.fromisoformat(rows[0]["request_date"]) + timedelta(days=30)).isoformat())
path = root/"output/quote_lines.csv"
if not path.exists():
say(False, "output/quote_lines.csv was not written"); sys.exit(1)
def num(text):
try: return Decimal(str(text).replace(",", "").replace("$", "").replace("%", "").strip())
except Exception: return None
def same(a, b): return a is not None and abs(a - b) < Decimal("0.005")
rows = list(csv.DictReader(path.open()))
got = {((r.get("request_id") or "").strip(), (r.get("sku") or "").strip()): r for r in rows}
n = len(lines)
say(set(got) == set(lines) and len(rows) == n, f"{len(set(got) & set(lines))} of {n} quote lines are present, one per product, with {len(set(got) - set(lines))} lines that should not be there")
def note_ok(k, w):
note = (got[k].get("note") or "").strip()
return (w["swapped"] in note) if w["swapped"] else note == ""
disc = sum(1 for k, w in lines.items() if k in got and same(num(got[k].get("quantity")), w["q"]) and same(num(got[k].get("discount_pct")), w["pct"])
and (got[k].get("name") or "").strip() == w["name"] and same(num(got[k].get("list_price")), w["list"]) and note_ok(k, w))
say(disc == n, f"{disc} of {n} lines have the product name, list price, quantity and discount the price list and rules give, with a note only on lines that replace a discontinued product")
money = sum(1 for k, w in lines.items() if k in got and same(num(got[k].get("net_unit_price")), w["net"]) and same(num(got[k].get("line_total")), w["total"]))
say(money == n, f"{money} of {n} lines have the unit price and line total worked out again to the cent")
igot = {((r.get("request_id") or "").strip(), (r.get("item") or "").strip(), (r.get("reason") or "").strip()) for r in csv.DictReader((root/"output/issues.csv").open())} if (root/"output/issues.csv").exists() else set()
say(igot == issues, f"{len(igot & issues)} of {len(issues)} lines that cannot be quoted are in issues.csv with the right reason")
tgot = {(r.get("request_id") or "").strip(): r for r in csv.DictReader((root/"output/quote_totals.csv").open())} if (root/"output/quote_totals.csv").exists() else {}
tt = sum(1 for k, w in totals.items() if k in tgot and same(num(tgot[k].get("total")), w["total"]))
say(tt == len(totals) and set(tgot) == set(totals), f"{tt} of {len(totals)} quote totals equal the sum of their lines, {sum(w['total'] for w in totals.values()):,.2f} in all")
ap = sum(1 for k, w in totals.items() if k in tgot and (tgot[k].get("needs_approval") or "").strip().lower() == w["approve"] and (tgot[k].get("valid_until") or "").strip() == w["until"]
and (tgot[k].get("customer") or "").strip() == w["customer"] and same(num(tgot[k].get("line_count")), w["count"]))
say(ap == len(totals), f"{ap} of {len(totals)} quotes have the right customer, line count, approval answer and valid until date, with {sum(1 for w in totals.values() if w['approve'] == 'yes')} needing approval")
text = (root/"output/quotes.md").read_text() if (root/"output/quotes.md").exists() else ""
nums = {Decimal(x.replace(",", "")) for x in re.findall(r"\d[\d,]*\.\d{2}", text)}
shown = sum(1 for k, w in totals.items() if k in text and w["total"] in nums)
say(shown == len(totals), f"quotes.md shows {shown} of {len(totals)} quotes with the same total")
DATE = r"\d{4}-\d\d-\d\d"
def figures(t):
t = re.sub(r"\b[A-Za-z]+-[A-Za-z0-9]+\b|" + DATE, " ", t)
return [Decimal(x.rstrip(",").replace(",", "")) for x in re.findall(r"(?<![\w.])\d[\d,]*(?:\.\d+)?", t)]
ruled = set(figures((root/"input/discount_rules.md").read_text()))
def product(item): return by_sku.get(key(item)) or by_name.get(item.strip().lower())
wide = {}
for rid, rs in requests.items():
wide[rid] = set(ruled) | {totals[rid]["total"], Decimal(totals[rid]["count"]), Decimal(sum(1 for i in issues if i[0] == rid))}
for r in rs:
wide[rid] |= set(figures(" ".join(r.values()))); pr = product(r["item"])
if pr: wide[rid] |= set(figures(" ".join(pr.values())))
rid, done, shown, claims, good = None, set(), 0, 0, 0
for ln in text.splitlines():
if ln.startswith("#"): rid = next((k for k in totals if k in ln), None)
sku = next((k2 for (k1, k2) in lines if k1 == rid and (k1, k2) not in done and re.search(r"(?<![\w-])" + re.escape(k2) + r"(?![\w-])", ln)), None)
found = figures(ln)
if sku:
w = lines[(rid, sku)]; done.add((rid, sku)); shown += all(v in found for v in (Decimal(w["q"]), Decimal(w["pct"]), w["total"]))
allowed = {Decimal(w["q"]), Decimal(w["pct"]), w["net"], w["total"], w["list"]} | set(figures(w["name"]))
if w["swapped"]: allowed |= set(figures(" ".join(by_sku[key(w["swapped"])].values())))
else: allowed = wide.get(rid, ruled | {Decimal(len(totals))})
for x in found: claims += 1; good += x in allowed
for d in re.findall(DATE, ln): claims += 1; good += rid in totals and d in (totals[rid]["asked"], totals[rid]["until"])
say(shown == n, f"{shown} of {n} quote lines are written out in quotes.md with the right quantity, discount and line total")
say(claims > 0 and good == claims, f"{good} of {claims} numbers and dates in quotes.md are the worked out figures for that line or quote, or come from that request, its products or the rules")
sys.exit(0 if ok else 1)
discount_rules.md: sample data written by Atris. Fingerprint 14d01f5dab64.
price_list.csv: sample data written by Atris. Fingerprint 9317860796f0.
quote_requests.csv: sample data written by Atris. Fingerprint d4227f3947ae.
issues.csv: written by the agent. Fingerprint 41265de6bd0d.
quote_lines.csv: written by the agent. Fingerprint 4d3177d75930.
quote_totals.csv: written by the agent. Fingerprint bc05c7932cf8.
quotes.md: written by the agent. Fingerprint ff64f3922f2f.