Ecommerce Integrations : Incorrect Net Rate Calculation in _get_item_price for Tax-Inclusive Orders

I encountered a logic error in order.py specifically within the _get_item_price function when handling Tax Inclusive orders from Shopify.

In certain scenarios (likely depending on Shopify’s tax settings or region), the Shopify API payload aggregates the total tax for the entire order onto the first line item’s tax_lines array, leaving subsequent line items with an empty tax_lines list.

The current implementation calculates the item rate by subtracting the absolute tax amount found on the specific line item object. This results in the first item being undervalued (absorbing the whole order’s tax) and subsequent items being overvalued (treated as having 0 tax).

Scenario & Data:

Order Configuration: Tax Inclusive (taxes_included: true)

  • Tax Rate: 5% IGST (Total Tax: 53.62)

  • Items: 3 × 395.00 (Subtotal: 1185.00)

  • Total Discount: 59.00 (~19.67 per item)

Payload Discrepancy:

  • Item 1: Contains tax_lines: [{“price”: “53.62”}]

  • Item 2 & 3: Contains tax_lines:

Problematic Code In
ecommerce_integrations/shopify/utils/order.py:

def _get_item_price(line_item, taxes_inclusive: bool) -> float:
	price = flt(line_item.get("price"))
	qty = cint(line_item.get("quantity"))

	# remove line item level discounts
	total_discount = _get_total_discount(line_item)

	if not taxes_inclusive:
		return price - (total_discount / qty)

	total_taxes = 0.0
	for tax in line_item.get("tax_lines"):
		total_taxes += flt(tax.get("price"))

	return price - (total_taxes + total_discount) / qty

**Actual vs. Expected Behavior:
**

Item Calculation in order.py (Actual) Result Correct Logic (Expected)
Item 1 395 - (53.62 + 19.67) 321.71 (395 - 19.67) / 1.05357.45
Item 2 395 - (0.00 + 19.67) 375.33 (395 - 19.67) / 1.05357.45
Item 3 395 - (0.00 + 19.67) 375.33 (395 - 19.67) / 1.05357.45