[GraphQL] discountApplications incorrectly includes Order Edits - How to isolate original order state for tax?

I am currently working on a tax reporting integration using the Shopify GraphQL Admin API and have run into a roadblock regarding Order Edits, Discounts and Refunds.

The Scenario:

1. An order is created with a line-item discount and paid in full.

2. An Order Edit is performed post-payment to add a new discount (either order-level or line-item level).

3. This creates a partial refund due to the customer.

The Problem:

For tax compliance, I need to reconcile the original order state as one entry and the subsequent refund/edit as a separate entry. However, I cannot find a reliable way to distinguish between discounts applied at the time of creation versus those applied later via an edit.

What I’ve Tried:

I initially looked at the discountApplications field on the Order object. The documentation states:

A list of discounts that are applied to the order, excluding order edits and refunds. Includes discount codes, automatic discounts, and other promotions that reduce the order total.

In practice, this doesn’t seem to be the case, as the field appears to include discounts added during order edits, making it impossible to isolate the original order’s financial state.

How are others handling tax reconciliation for edited orders?

1 Like

Hey @elgreco, for tax reconciliation I suggest testing if the SalesAgreement interface via order.agreements will work for you.

Each agreement has a reason field (“ORDER” for original, “ORDER_EDIT” for edits) and contains sales records with totalDiscountAmountBeforeTaxes and totalDiscountAmountAfterTaxes fields.

Here’s the approach:

query {
  order(id: "gid://shopify/Order/YOUR_ORDER_ID") {
    agreements(first: 50) {
      edges {
        node {
          happenedAt
          reason  # "ORDER" = original, "ORDER_EDIT" = edit
          sales(first: 50) {
            edges {
              node {
                actionType
                lineType
                quantity
                totalAmount { shopMoney { amount currencyCode } }
                totalDiscountAmountBeforeTaxes { shopMoney { amount currencyCode } }
                totalDiscountAmountAfterTaxes { shopMoney { amount currencyCode } }
              }
            }
          }
        }
      }
    }
  }
}

For each edited order:

  1. The agreement with reason: "ORDER" gives you the original financial state
  2. Agreements with reason: "ORDER_EDIT" show each edit’s changes, including discount amounts on the sales lines

The edit pattern creates two sales lines: one removing the original item (negative quantity) and one adding the updated item with the new discount amounts. This lets you reconstruct the delta for each edit.