See llms.txt for all machine-readable content.

Back to Templates

Draft weekly purchase orders from stock and sales with OpenAI and Gmail

Quick overview

This workflow runs every Monday morning to calculate weekly reorder quantities from n8n Data Tables stock and 28‑day sales, uses OpenAI to generate and verify Japanese purchase reasons, emails the plan for Gmail approval, and creates per-supplier Gmail draft purchase orders while logging outcomes.

How it works

  1. Runs every Monday at 09:00 on a schedule.
  2. Loads reorder settings, then reads stock/open-order/lead-time data from the n8n Data Table reorder_stock and 28-day sales totals from reorder_sales.
  3. Calculates which SKUs need reordering based on sales velocity, lead time, safety days, current stock plus open orders, and rounds quantities up to minimum order quantities.
  4. If there are items to order, uses OpenAI to write a one-line Japanese reason and risk note per SKU and then performs a second OpenAI pass to verify and correct any numbers against the calculated plan.
  5. Sends the plan to the buyer via Gmail with approve/decline buttons and waits up to three days for a response.
  6. If approved, groups lines by supplier, creates one Gmail draft purchase order email per supplier, and logs the drafts to the reorder_log Data Table; if declined, logs the declined plan to reorder_log.

Setup

  1. Create three n8n Data Tables named reorder_stock, reorder_sales, and reorder_log, and ensure they contain the columns referenced by the workflow (SKUs, stock/on-order/lead-time/MOQ, sales in last 28 days, and log fields).
  2. Populate reorder_stock and reorder_sales with your real inventory and sales data (or run the manual “Load Sample Data” branch once to insert sample rows).
  3. Add a Gmail OAuth2 credential, replace REPLACE_WITH_BUYER_EMAIL and the company name in Set Reorder Settings, and add each supplier's order email to the supplier_email column of reorder_stock.
  4. Add an OpenAI credential and confirm the selected chat model is available in your account.
  5. Adjust safety days, order cycle days, and the Monday 09:00 schedule to match your purchasing cadence.