The shop now supplies two inputs: opening balances as a JSON object and movements as CSV with item and delta columns. Your report goes straight to the buyer.
Join a CSV observation to a JSON record using a shared key.
import csv
import json
from io import StringIO
prices = json.loads('{"map": 3, "pass": 8}')
row = next(csv.DictReader(StringIO("product,count\nmap,2")))
cost = prices[row["product"]] * int(row["count"])
print(cost) # 6Reading one line ties the formats together. For the report, combine multiple movements before deciding what to order.
Implement stock_report(opening_json, movements_csv, target). Apply all signed deltas, starting new items at zero. Return a list of dictionaries with item and order for every item below the common target. Order enough units to reach the target and sort the report by item name. If you saved your earlier helper functions, you can reuse them here.
stock_report('{"tea":5}', "item,delta\ntea,-3\nmilk,1", 4)
# [{"item": "milk", "order": 3}, {"item": "tea", "order": 2}]