1

I'm trying to get all stock data of a product via SQL for debugging. The part that I'm not 100% on is the salable quantity.

Here is what I have:

SELECT t1.`quantity` + SUM(t2.`quantity`) salable_quantity
FROM `inventory_source_item` t1
JOIN `inventory_reservation` t2
ON t1.`sku` = t2.`sku` AND t1.`status` = 1
WHERE t1.`sku` = 'MY-PROD-SKU'

this works most of the time, and sometimes returns NULL.

I was hoping if any magento users had to write something similar, and have any improvements on this query. Thanks.


EDIT:

Improved version of my code:

SELECT COALESCE(t1.`quantity` + SUM(t2.`quantity`), 0) salable_quantity
FROM `inventory_source_item` t1
JOIN `inventory_reservation` t2
ON t1.`sku` = t2.`sku` AND t1.`status` = 1
WHERE t1.`sku` = 'MY-PROD-SKU'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.