Commit a6af3933 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

improve _getMovementList() so as to collect all possible movement list and...

improve _getMovementList() so as to collect all possible movement list and then filter by specified portal_type(s).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26535 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 96e782dc
...@@ -202,18 +202,19 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -202,18 +202,19 @@ class Delivery(XMLObject, ImmobilisationDelivery):
def _getMovementList(self, portal_type=None, **kw): def _getMovementList(self, portal_type=None, **kw):
""" """
Return a list of movements. Return a list of movements.
First, we collect movements by movement type portal types, then
we filter the result by specified portal types.
""" """
if portal_type is None: movement_portal_type_list = self.getPortalMovementTypeList()
portal_type = self.getPortalMovementTypeList()
movement_list = [] movement_list = []
add_movement = movement_list.append add_movement = movement_list.append
extend_movement = movement_list.extend extend_movement = movement_list.extend
sub_object_list = self.objectValues(portal_type=portal_type) sub_object_list = self.objectValues(portal_type=movement_portal_type_list)
extend_sub_object = sub_object_list.extend extend_sub_object = sub_object_list.extend
append_sub_object = sub_object_list.append append_sub_object = sub_object_list.append
while sub_object_list: while sub_object_list:
sub_object = sub_object_list.pop() sub_object = sub_object_list.pop()
content_list = sub_object.objectValues(portal_type=portal_type) content_list = sub_object.objectValues(portal_type=movement_portal_type_list)
if sub_object.hasCellContent(): if sub_object.hasCellContent():
cell_list = sub_object.getCellValueList() cell_list = sub_object.getCellValueList()
if len(cell_list) != len(content_list): if len(cell_list) != len(content_list):
...@@ -226,6 +227,12 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -226,6 +227,12 @@ class Delivery(XMLObject, ImmobilisationDelivery):
extend_sub_object(content_list) extend_sub_object(content_list)
else: else:
add_movement(sub_object) add_movement(sub_object)
if isinstance(portal_type, (list, tuple)):
return [x for x in movement_list \
if x.getPortalType() in portal_type]
elif portal_type is not None:
return [x for x in movement_list \
if x.getPortalType() == portal_type]
return movement_list return movement_list
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
......
...@@ -2012,6 +2012,12 @@ class TestOrder(TestOrderMixin, ERP5TypeTestCase): ...@@ -2012,6 +2012,12 @@ class TestOrder(TestOrderMixin, ERP5TypeTestCase):
len([movement len([movement
for movement in order.getMovementList() for movement in order.getMovementList()
if movement.portal_type=='Sale Order Cell'])) if movement.portal_type=='Sale Order Cell']))
self.assertEqual(len(order.getMovementList(portal_type=['Sale Order Line',
'Sale Order Cell'])),
len([movement
for movement in order.getMovementList()
if movement.portal_type in ('Sale Order Line',
'Sale Order Cell')]))
def test_19b_getTotalQuantityAndPrice(self, quiet=0, run=run_all_test): def test_19b_getTotalQuantityAndPrice(self, quiet=0, run=run_all_test):
""" """
......
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