n8n flows
Notify: PO Line Item Discrepancy
Emails the account's NC staff once per closed PO, listing every line item received short or over.
When a purchase order closes with PO line items whose received quantity does not match what was ordered, this flow sends the account's NC staff one email for the whole PO. The email lists every discrepant line. It respects per-user preferences, never emails Client Users, and sends at most once per PO.
At a glance
- Status: Active
- Trigger: Webhook (
POST /webhook/fa4e35de-c6fe-4ac3-bc89-8af1d30442ff), responds immediately. The payload is{ "po_id": <PO record id> }. - Runs on: The Purchase Order Update Handler calling it after it has written every line item of a closed PO. The database only flags a line once the PO is closed, see When a discrepancy is flagged.
- Talks to: Supabase (PO Line Items, POs, Brands, userRoles, user_settings, Auth Admin API); Gmail.
How it works
- The webhook receives the PO id.
Get Discrepant Line Itemsloads every line on the PO withdiscrepancy_detected = true. If there are none, the flow stops and nothing is sent.Build Discrepancy Rowsturns the lines into one table: SKU (shiphero_sku), description (purchase_order_line_item_name), ordered, received, andShort NorOver N.Claim PO Notificationsetsdiscrepancy_notification_senton the PO, but only if the PO is'closed'and the flag is stillfalse. If no row is updated, the PO was already emailed and the flow stops.- It resolves the PO's brand and the brand's users.
Get Users For Brandkeeps active rows only and skips Client Users (roleIdis not the Client User role).Loop Over Userscheckssend_notificationsandinventory_management.inbound_pos_issues(the Receiving Discrepancy Notification setting in Notification Settings), and each opted-in user gets one branded HTML Gmail alert with the table, linking to the receiving-discrepancies page.
Notes
- Sends at most one email per PO per user. The claim is a single database update, so two runs for the same PO cannot both send.
- Opt-in gated on two preference flags.
- Client Users are filtered out when recipients are picked, so a stored preference can't turn the email on for them.
- The SKU and description come straight from the line item, so a line whose SKU has not been classified yet is still listed.
- The flag is set before sending and is never reset. A quantity that changes after the email has gone out produces no follow-up.
- The line item's own
discrepancy_notification_sentcolumn is legacy. This flow no longer reads or writes it.
Related
Notify: New Draft PO Created
Retired. Used to email brand users when a new draft purchase order was created, respecting their notification preferences.
Missing Shipment Data Pull 2.0 (Backup)
The live 2.0 flow that pulls missing ShipHero shipment data into Supabase for every active brand and reconciles the full shipment graph.