From 58ed920f8c4ac889cced679ab72a6ce3a5ff42bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Mon, 22 Oct 2007 09:00:33 +0000 Subject: [PATCH] support group_by_date in inventory API git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17080 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Tool/SimulationTool.py | 8 ++++++-- product/ERP5/tests/testInventoryAPI.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py index 640c15b177..8418651aff 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 ade0d69513..10219f06f0 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) -- 2.30.9