Commit 58ed920f authored by Jérome Perrin's avatar Jérome Perrin

support group_by_date in inventory API


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17080 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d70bba19
...@@ -476,6 +476,7 @@ class SimulationTool(BaseTool): ...@@ -476,6 +476,7 @@ class SimulationTool(BaseTool):
group_by_variation=0, group_by_variation=0,
group_by_movement=0, group_by_movement=0,
group_by_resource=0, group_by_resource=0,
group_by_date=0,
# sort_on # sort_on
sort_on=None, sort_on=None,
# keywords for related keys # keywords for related keys
...@@ -649,6 +650,8 @@ class SimulationTool(BaseTool): ...@@ -649,6 +650,8 @@ class SimulationTool(BaseTool):
group_by_expression_list.append('uid') group_by_expression_list.append('uid')
if group_by_resource: if group_by_resource:
group_by_expression_list.append('resource_uid') group_by_expression_list.append('resource_uid')
if group_by_date:
group_by_expression_list.append('date')
if group_by_expression_list: if group_by_expression_list:
new_kw['group_by'] = group_by_expression_list new_kw['group_by'] = group_by_expression_list
return sql_kw, new_kw return sql_kw, new_kw
...@@ -827,7 +830,7 @@ class SimulationTool(BaseTool): ...@@ -827,7 +830,7 @@ class SimulationTool(BaseTool):
group_by_section=0, group_by_mirror_section=0, group_by_section=0, group_by_mirror_section=0,
group_by_payment=0, group_by_payment=0,
group_by_variation=0, group_by_sub_variation=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, group_by_resource=None,
**ignored): **ignored):
""" """
...@@ -843,7 +846,8 @@ class SimulationTool(BaseTool): ...@@ -843,7 +846,8 @@ class SimulationTool(BaseTool):
if not ignore_group_by: if not ignore_group_by:
if group_by_node or group_by_mirror_node or group_by_section or \ 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_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: if group_by_resource is None:
group_by_resource = 1 group_by_resource = 1
new_group_by_dict['group_by_resource'] = group_by_resource new_group_by_dict['group_by_resource'] = group_by_resource
......
...@@ -693,6 +693,21 @@ class TestInventoryList(InventoryAPITestCase): ...@@ -693,6 +693,21 @@ class TestInventoryList(InventoryAPITestCase):
self.assertEquals([r for r in inventory_list if r.payment_uid == self.assertEquals([r for r in inventory_list if r.payment_uid ==
self.payment_node.getUid()][0].inventory, 200) 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): def test_OmitInputOmitOutput(self):
getInventoryList = self.getSimulationTool().getInventoryList getInventoryList = self.getSimulationTool().getInventoryList
self._makeMovement(quantity=1, price=1) self._makeMovement(quantity=1, price=1)
......
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