omi icon indicating copy to clipboard operation
omi copied to clipboard

Shopify analytics subtracts discounts twice from net sales

Open kaijakagi-sys opened this issue 2 months ago • 2 comments

plugins/omi-shopify-app/main.py currently sums subtotal_price as gross_sales, then computes net_sales = gross_sales - total_discounts - total_refunds (pinned source). Shopify's REST Order documentation defines subtotal_price as “The price of the order in the shop currency after discounts but before shipping, duties, taxes, and tips.” The discount is therefore counted twice for an ordinary discounted order.

I reproduced this offline by executing the full unchanged tool_get_analytics and format_currency function bodies with request/auth/provider/response stubs, without a live Shopify store. For one USD order with pre-discount merchandise value 100, subtotal_price="90.00", total_discounts="10.00", zero tax/shipping and no refunds, the output reports Gross Sales $90, Discounts $10 (11.1%), and Net Sales $80. The expected net sales for that fixture is $90; a before-discount gross label would correspond to $100 and a 10% discount. Undiscounted ($100/$0) and empty-order controls output $100 and $0 net sales respectively. This is a reproduction, not a completed fix or live-store verification.

I'd propose one focused PR to align the gross/net labels and discount convention so discounts are applied once, use decimal-safe arithmetic for the affected monetary calculation, and add regression coverage for the discounted case plus undiscounted/empty controls in the appropriate existing test lane. Refund accounting, tax-inclusive reporting, currency conversion and API migration would remain explicitly outside this narrow claim.

Validation plan: run the component’s discovered test runner and the repository’s required make preflight and PR-body checks, with hermetic tests exercising the production handler. No passing fix suite is claimed yet.

@josancamon19, is this exact scope available under the contribution bounty program, and would a proposed $25 reward be appropriate? Scope and reward are unconfirmed; I have not implemented the fix.

kaijakagi-sys avatar Sep 08 '26 18:09 kaijakagi-sys

I have read the issue and confirmed the double subtraction: in plugins/omi-shopify-app/main.py around line 475, net_sales is computed as gross_sales - total_discounts - total_refunds while subtotal_price already has discounts removed per Shopify's own REST documentation. My fix is to replace the subtotal_price base with total_line_items_price as gross before deductions, or simply drop total_discounts from the net calculation. I can have a tested PR up within 24 hours and am starting now.

Nordikdata avatar Sep 09 '26 03:09 Nordikdata

Opened PR #13527. Net sales no longer subtract discounts that Shopify already applied in subtotal_price.

Nukeys avatar Sep 11 '26 20:09 Nukeys