| 10 | This translates to the following Query, which returns the correct results, when run natively: |
| 11 | |
| 12 | {{{ |
| 13 | SELECT "testapp_product"."id", "testapp_product"."name", "testapp_product"."qty_target", CAST(SUM("testapp_stock"."qty_available") AS NUMERIC) AS "qty_available_sum", ("testapp_product"."qty_target" - CAST(SUM("testapp_stock"."qty_available") AS NUMERIC)) AS "qty_needed" |
| 14 | FROM "testapp_product" |
| 15 | LEFT OUTER JOIN "testapp_stock" ON ("testapp_product"."id" = "testapp_stock"."product_id") |
| 16 | GROUP BY "testapp_product"."id", "testapp_product"."name", "testapp_product"."qty_target" |
| 17 | HAVING ("testapp_product"."qty_target" - CAST(SUM("testapp_stock"."qty_available") AS NUMERIC)) > 0 |
| 18 | }}} |
| 19 | |
| 20 | Using the QuerySet, it does not respect the filter condition. For details see the test below. |
| 21 | |