National Commerce Docs
n8n flows

Notify: PO Line Item Discrepancy

Emails brand users when a received PO line item does not match the ordered quantity.

When a closed PO has a PO line item whose received quantity does not match what was ordered, this flow emails the relevant brand users. It respects per-user preferences and sends only once per line item.

At a glance

  • Status: Active
  • Trigger: Webhook (POST /webhook/fa4e35de-c6fe-4ac3-bc89-8af1d30442ff), responds immediately.
  • Runs on: purchase_order_line_item_discrepancy_trigger firing when discrepancy_detected turns true. The payload carries the line-item record id. The database only sets that flag once the PO is closed, so this flow never runs mid-receiving. See When a discrepancy is flagged.
  • Talks to: Supabase (PO Line Items, POs, Case/Base SKUs, Brands, userRoles, user_settings, Auth Admin API); Gmail.

How it works

  1. The webhook receives the record id; the flow reads the PO line item.
  2. It re-verifies the discrepancy by comparing total_quantity against received_quantity; equal values stop the flow.
  3. It checks discrepancy_notification_sent and sets the flag before sending.
  4. It resolves the SKU (via Case SKU or Base SKU records), then the purchase order, its account brand, and the brand's users.
  5. Loop Over Users checks send_notifications and inventory_management.inbound_pos_issues; opted-in users get a branded HTML Gmail alert detailing PO number, SKU, ordered vs received quantity, and the difference, linking to the receiving-discrepancies page.

Notes

  • Double-guarded: it re-verifies the discrepancy and checks the sent flag before emailing.
  • Opt-in gated on two preference flags.
  • The flow itself does not check whether the PO is closed. It does not need to, because the database only raises discrepancy_detected for a closed PO. If partial-receiving emails ever reappear, the cause is in update_purchase_order_line_items(), not here.
  • discrepancy_notification_sent is set before sending and is never reset, so a line item emails at most once ever. A correction to the quantities afterwards produces no follow-up.

On this page