dimagi/rapidsms-logistics — pull request #7 by mlavin (2012-12-17 19:12:01+00:00)
Title: Reporting Inconsistencies

This addresses the inconsistencies in the report created for #6. In investigating this I found what I think is odd behavior in `ProductStock.is_below_emergency_level` and `StockCacheMixin._populate_stock_cache`.

`_populate_stock_cache` calculates a number of counts but in particular there is `low_stock_count`, `emergency_stock_count` and `emergency_plus_low`. Based on the names and a general glance over the logic in `ProductStock` I assumed that `low_stock_count` + `emergency_stock_count` would equal `emergency_plus_low`. However, this is not the case. `is_below_emergency_level` does not check that the quantity is greater than 0 like `is_below_low_supply` does meaning that `is_below_emergency_level` will also include those which are stocked out.

`is_below_emergency_level` has been updated to check that the quantity is greater than 0 so that these numbers will now add up. `StockRequest.create_from_report` was the only other location I found which was using `is_below_emergency_level` and it has been updated to also check for stockouts to preserve the current behavior.