Commit 5d33d178 authored by Jérome Perrin's avatar Jérome Perrin

Describe returned brains returned by getInventoryList

And pitfalls introduced by `getObject`
parent 524d723f
......@@ -210,7 +210,10 @@ This method does not check that the provided parameters leads to results that ma
`getInventoryAssetPrice` returns the total "values" XXX of the movements.
## getInventoryList
`getInventoryList` can query in only one call the inventories of multiple nodes. The aggregation parameters has to be specified. For example, in the case of warehouse inventories, we want to pass `group_by_node=True` and `group_by_resource=True` to get the inventory for each node and resource.
`getInventoryList` can query in only one call the inventories of multiple nodes, it is equivalent to the *GROUP BY* SQL Statement.
The aggregation parameters has to be specified. For example, in the case of warehouse inventories, we want to pass `group_by_node=True` and `group_by_resource=True` to get the inventory for each node and resource.
Using one `getInventoryList` is usually much more efficient than doing multiple `getInventory`/`getInventoryAssetPrice` calls.
For example, this code:
......@@ -231,10 +234,33 @@ for brain in getInventoryList(node_uid=(alice.getUid(), bob.getUid()),
group_by_node=True):
print "{node}'s inventory of candy is {inventory}, value is {value}".format(
node=brain.node_title,
inventory=brain.total_inventory,
inventory=brain.total_quantity,
asset_price=brain.total_price)
```
As we saw in the above example, the returned values of getInventoryList are a sequence of `InventoryListBrain` objects.
These `InventoryListBrain` have the following attributes:
| Attribute | Description |
|----------------|-------------|
| total_quantity | The sum of quantities of all movements from this group. |
| total_price | The sum of asset price of all movements from this group. |
| node_uid | The uid of the node. Only makes sense if using `group_by_node`. Otherwise the `node_uid` of one random movement from the group will be returned ( because the underlying query relies on MySQL not using [`ONLY_FULL_GROUP_BY`](https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html) here ) |
| node_title | The title of the node. Only makes sense if using `group_by_node`. |
| resource_uid | The uid of the resource. Only makes sense if using `group_by_resource`. |
| resource_title | The title of the resource. Only makes sense if using `group_by_resource`. |
| section_uid | The uid of the section. Only makes sense if using `group_by_section`. |
| section_title | The title of the section. Only makes sense if using `group_by_section`. |
| project_uid | The uid of the project. Only makes sense if using `group_by_project`. |
| mirror_section_uid | The uid of the mirror section. Only makes sense if using `group_by_mirror_section`. |
| mirror_node_uid | The uid of the mirror node. Only makes sense if using `group_by_mirror_node`. |
| uid | The uid of one random movement from the group. |
| path | The path of one random movement from the group. |
| getObject() | Returns a random movement from the group. |
| parameters from `select_list` | All parameters that have been passed to `select_list` can also be selected. |
| everything else | An implicit `getObject` will be called and the attribute will be fetched from a movement. This can lead to errors. For example, do not use `brain.getQuantity()` or `brain.quantity` which will just return quantity of a random movement regardess of aggregation |
## getMovementHistoryList
`getMovementHistoryList` list all movements that form the inventory. The returned value is a list of `MovementHistoryListBrain` instances.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment