Automated inventory valuation using FIFO / weighted-average methods with category-level stock reporting.
import requests, json, pandas as pd API_STOCK = "https://api.gudang.com/v2/inventory" def fetch_inventory(warehouse_id): resp = requests.get(API_STOCK, params={"wh": warehouse_id}) return resp.json().get("items", []) def calc_valuation(items): df = pd.DataFrame(items) df["value"] = df.apply(lambda r: r["qty"] * r["unit_cost"], axis=1) report = df.groupby("category").agg( units=("qty", "sum"), total_value=("value", "sum"), method=("cost_method", "first") ).reset_index() report["avg_unit"] = report["total_value"] / report["units"] return report.to_dict("records") valuation = calc_valuation(fetch_inventory("WH-01")) print(json.dumps(valuation, indent=2))