diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py index 640c15b177dc66f44b374df21fcbd2dc609577c5..8418651aff5207c423c7b885db12f47ba38406da 100644 --- a/product/ERP5/Tool/SimulationTool.py +++ b/product/ERP5/Tool/SimulationTool.py @@ -476,6 +476,7 @@ class SimulationTool(BaseTool): group_by_variation=0, group_by_movement=0, group_by_resource=0, + group_by_date=0, # sort_on sort_on=None, # keywords for related keys @@ -649,6 +650,8 @@ class SimulationTool(BaseTool): group_by_expression_list.append('uid') if group_by_resource: group_by_expression_list.append('resource_uid') + if group_by_date: + group_by_expression_list.append('date') if group_by_expression_list: new_kw['group_by'] = group_by_expression_list return sql_kw, new_kw @@ -827,7 +830,7 @@ class SimulationTool(BaseTool): group_by_section=0, group_by_mirror_section=0, group_by_payment=0, group_by_variation=0, group_by_sub_variation=0, - group_by_movement=0, + group_by_movement=0, group_by_date=0, group_by_resource=None, **ignored): """ @@ -843,7 +846,8 @@ class SimulationTool(BaseTool): if not ignore_group_by: if group_by_node or group_by_mirror_node or group_by_section or \ group_by_mirror_section or group_by_payment or \ - group_by_sub_variation or group_by_variation or group_by_movement: + group_by_sub_variation or group_by_variation or \ + group_by_movement or group_by_date: if group_by_resource is None: group_by_resource = 1 new_group_by_dict['group_by_resource'] = group_by_resource diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py index ade0d69513e17be844481ef2051ae43e47821de8..10219f06f0ebc07f28ca9e06ac358952e14e9548 100644 --- a/product/ERP5/tests/testInventoryAPI.py +++ b/product/ERP5/tests/testInventoryAPI.py @@ -693,6 +693,21 @@ class TestInventoryList(InventoryAPITestCase): self.assertEquals([r for r in inventory_list if r.payment_uid == self.payment_node.getUid()][0].inventory, 200) + def test_GroupByDate(self): + # group by date currently only groups by *exact* date + getInventoryList = self.getSimulationTool().getInventoryList + self._makeMovement(quantity=1, start_date=DateTime(2000, 1, 1)) + self._makeMovement(quantity=1, start_date=DateTime(2000, 1, 1)) + self._makeMovement(quantity=1, start_date=DateTime(2001, 1, 1)) + inventory_list = getInventoryList(node_uid=self.node.getUid(), + group_by_date=1) + self.assertEquals(2, len(inventory_list)) + self.assertEquals([r for r in inventory_list + if r.date.year() == 2000][0].inventory, 2) + self.assertEquals([r for r in inventory_list + if r.date.year() == 2001][0].inventory, 1) + + def test_OmitInputOmitOutput(self): getInventoryList = self.getSimulationTool().getInventoryList self._makeMovement(quantity=1, price=1)