National Commerce Docs
n8n flows

Hourly: Create Draft POs

Evaluates the replenishment report each hour and writes draft purchase orders and line items into Supabase.

This is the automated replenishment engine. Every hour it checks which SKUs need reordering and creates or updates draft purchase orders, grouped by warehouse and brand, so buyers have ready-to-review drafts waiting for them.

At a glance

  • Status: Active
  • Trigger: Schedule Trigger, every hour at minute 10. A disabled webhook (/webhook/inventory_updated) exists for an alternative live mode but is off.
  • Runs on: The hourly schedule.
  • Talks to: Supabase (a replenishment RPC plus the Draft PO, Draft PO Line Items, Base SKUs, Brands, and Vendors tables); pings Notify: New Draft PO Created.

How it works

  1. Run Inventory Report calls the Supabase RPC inventory_replen_report_for_draft_PO_creation (trailing 14 days, order interval 7, safety stock 4) over REST.
  2. A filter keeps only Active items where available stock (on-hand plus inbound) is below the reorder threshold and minimum_reorder_qty > 0; a guard node short-circuits when nothing is due.
  3. Each item is enriched with its Base SKU and brand_id.
  4. Loop Over Items walks each SKU: it either updates an existing draft PO line item or creates a new one.
  5. The line item attaches to an existing draft PO for that warehouse and brand, or a new Draft PO is created (random-suffixed name, status Draft) after looking up the brand and vendor.
  6. When a new PO is created, the flow fires the draft-PO notification webhook.

Notes

  • Supabase auth tokens are hardcoded in the report node's headers.
  • The live webhook mode was deliberately disabled because it consumed too many executions (explained in a sticky note).
  • Shared error-handler set as the error workflow.

On this page