Discount calculation problem

There is a problem calculating discounts in the Orders API when you have an ORDER scoped discount and a LINE_ITEM scoped discount that is for the full amount of the line item. It appears that the ORDER-scope discount is applied to all line items first, even though it is a fixed amount discount.

e.g. with order line items:

  1. Widget A, $5/ea, qty 100
  2. Another Thing, $10/ea, qty 1

discounts:

  • Scope LINE_ITEM, applied to item 2, $10 fixed amount
  • Scope ORDER, $100 fixed amount

We want line item 2 to appear on the order with the amount it would have been, so the customer can see what they would have been charged and the discount showing they were not charged for that item. What happens is the order discount is applied proportionally to the items, so the $100 fixed order discount applies $98 to item 1 and $2 to item 2. The line item discount for item 2 is then only $8. The correct order total would be $400, but the Orders API would give an order total of $402.

If fixed amount line item discounts could be applied to the applicable line items first, these calculations could be more correct.

Currently I’ve worked around this problem by not using line item discounts, since order-scoped discounts appear the same way on an invoice view.

:wave: Do you have an example order_id of this behavior? Currently the order should apply the fixed discount as follows:

  1. Apply item-level fixed-amount discounts to the applicable line item totals.
  2. Convert and distribute order-level fixed-amount discounts to all line item totals. The amount distributed to each line item is relative to the amount that item contributes to the order subtotal.

Order ID 6YEFd4TDZ6PLXIzHM3FEhjvtODYZY in the sandbox shows this problem. Here’s the line item that displays the problem (there are other line items not included here). As you can see, the discount--433298 discount specifies a LINE_ITEM scoped FIXED_AMOUNT of $135, but the applied amount is $46.30 because the line item also has $88.70 of the ORDER scoped FIXED_AMOUNT $500 discount applied. The total order is $761, so this $135 line item is 17.7% of the total, and got 17.7% of the $500 ORDER scoped discount applied first.

{
        "uid": "item-433298",
        "quantity": "1",
        "name": "22x28 Frame Monet",
        "base_price_money": {
          "amount": 13500,
          "currency": "USD"
        },
        "gross_sales_money": {
          "amount": 13500,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 13500,
          "currency": "USD"
        },
        "total_money": {
          "amount": 0,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 13500,
          "currency": "USD"
        },
        "applied_discounts": [
          {
            "uid": "Hc5tPDO0rZhm8cUJ8b1gYD",
            "discount_uid": "deposit",
            "applied_money": {
              "amount": 8870,
              "currency": "USD"
            }
          },
          {
            "uid": "kwTHODCsIaAbuetMc3o0hB",
            "discount_uid": "discount--433298",
            "applied_money": {
              "amount": 4630,
              "currency": "USD"
            }
          }
        ],
        "item_type": "ITEM"
      }

and the discounts:

    "discounts": [
      {
        "uid": "discount--433298",
        "name": "Discounted 22x28 Frame Monet",
        "amount_money": {
          "amount": 13500,
          "currency": "USD"
        },
        "applied_money": {
          "amount": 4630,
          "currency": "USD"
        },
        "type": "FIXED_AMOUNT",
        "scope": "LINE_ITEM"
      },
      {
        "uid": "deposit",
        "name": "Composite Deposit",
        "amount_money": {
          "amount": 50000,
          "currency": "USD"
        },
        "applied_money": {
          "amount": 50000,
          "currency": "USD"
        },
        "type": "FIXED_AMOUNT",
        "scope": "ORDER"
      }
    ],