diff --git a/product/CMFCategory/CategoryTool.py b/product/CMFCategory/CategoryTool.py index 4c3eb3b4ecf6158316f925be32464819d119a1a8..fc8d6817640901e4ab2dfb89ff6ac08a72f059a7 100644 --- a/product/CMFCategory/CategoryTool.py +++ b/product/CMFCategory/CategoryTool.py @@ -362,7 +362,10 @@ class CategoryTool( UniqueObject, Folder, Base ): # XXX we should also go up in some other cases.... # ie. when some documents act as categories o = o.aq_parent # We want acquisition here without aq_inner - uid_set.add((o.getUid(), bo_uid, 0)) # Non Strict Membership + o_uid = o.getUid() + if o_uid == bo_uid: + break + uid_set.add((o_uid, bo_uid, 0)) # Non Strict Membership except (KeyError, AttributeError): LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path) return list(uid_set) # cast to list for <dtml-in> @@ -1631,12 +1634,22 @@ class CategoryTool( UniqueObject, Folder, Base ): """ if base_category is None: base_category = context.getBaseCategoryId() - sql_kw = { - ( + if context.portal_type == 'Base Category' and context.getId() == base_category: + # Looking for all documents which are member of context a + # (Base Category) via a relationship of its own type: assume this means + # caller wants to retrieve documents having any document related via a + # relationship of the type of context. + # XXX: ignoring "strict*" argument. It does not have much meaning in + # this case anyway. + key = 'category.base_category_uid' + else: + key = ( 'strict_' if strict_membership or strict else 'default_' - ) + base_category + '_uid': context.getUid(), + ) + base_category + '_uid' + sql_kw = { + key: context.getUid(), } if portal_type: sql_kw['portal_type'] = portal_type diff --git a/product/CMFCategory/tests/testCMFCategory.py b/product/CMFCategory/tests/testCMFCategory.py index 938e5da1b62d01c06a1c267ab2c20ed15f8244c1..c0685f06050cb712fd5256c7c6889d82f0906182 100644 --- a/product/CMFCategory/tests/testCMFCategory.py +++ b/product/CMFCategory/tests/testCMFCategory.py @@ -333,7 +333,6 @@ class TestCMFCategory(ERP5TypeTestCase): [ (cat2.getUid(), basecat.getUid(), 1), (cat1.getUid(), basecat.getUid(), 0), - (basecat.getUid(), basecat.getUid(), 0), ], ) self.assertItemsEqual( @@ -344,7 +343,6 @@ class TestCMFCategory(ERP5TypeTestCase): (cat22.getUid(), basecat.getUid(), 1), (cat2.getUid(), basecat.getUid(), 0), (cat1.getUid(), basecat.getUid(), 0), - (basecat.getUid(), basecat.getUid(), 0), ], ) # Non-canonical path @@ -356,7 +354,6 @@ class TestCMFCategory(ERP5TypeTestCase): (cat3.getUid(), basecat.getUid(), 1), (cat2.getUid(), basecat.getUid(), 0), (cat1.getUid(), basecat.getUid(), 0), - (basecat.getUid(), basecat.getUid(), 0), ], ) # Strict, implicit base category @@ -613,12 +610,12 @@ class TestCMFCategory(ERP5TypeTestCase): c1 = bc.newContent(portal_type='Category', id='1') self.tic() - self.assertItemsEqual(pc.getRelatedValueList(bc), [bc, c1]) + self.assertItemsEqual(pc.getRelatedValueList(bc), [bc]) self.assertItemsEqual(pc.getRelatedValueList(c1), [c1]) c11 = c1.newContent(portal_type='Category', id='1') self.tic() - self.assertItemsEqual(pc.getRelatedValueList(bc), [bc, c1, c11]) + self.assertItemsEqual(pc.getRelatedValueList(bc), [bc]) self.assertItemsEqual(pc.getRelatedValueList(c1), [c1, c11]) self.assertItemsEqual(pc.getRelatedValueList(c11), [c11]) @@ -671,6 +668,7 @@ class TestCMFCategory(ERP5TypeTestCase): """Test strict_membership parameter to Category Member Value List """ portal_categories = self.getCategoryTool() organisation = self.getOrganisationModule().newContent( + test0='region/europe', test1='region', portal_type='Organisation', region='europe/west/france') self.tic() @@ -681,7 +679,6 @@ class TestCMFCategory(ERP5TypeTestCase): base_category='region', strict_membership=0, portal_type='Organisation')], [organisation]) - self.assertEqual([x.getObject() for x in portal_categories.getCategoryMemberValueList( portal_categories.region.europe.west.france, @@ -695,7 +692,6 @@ class TestCMFCategory(ERP5TypeTestCase): base_category='region', strict_membership=0, portal_type='Organisation')], [organisation]) - self.assertEqual([x.getObject() for x in portal_categories.getCategoryMemberValueList( portal_categories.region.europe.west, @@ -709,6 +705,32 @@ class TestCMFCategory(ERP5TypeTestCase): base_category='region', portal_type='Organisation')], [organisation]) + self.assertEqual([x.getObject() for x in + portal_categories.getCategoryMemberValueList( + portal_categories.region, + base_category='test0', + strict_membership=0, + portal_type='Organisation')], [organisation]) + self.assertEqual([x.getObject() for x in + portal_categories.getCategoryMemberValueList( + portal_categories.region, + base_category='test0', + strict_membership=1, + portal_type='Organisation')], []) + + self.assertEqual([x.getObject() for x in + portal_categories.getCategoryMemberValueList( + portal_categories.region, + base_category='test1', + strict_membership=0, + portal_type='Organisation')], [organisation]) + self.assertEqual([x.getObject() for x in + portal_categories.getCategoryMemberValueList( + portal_categories.region, + base_category='test1', + strict_membership=1, + portal_type='Organisation')], [organisation]) + def test_20_CategoryChildTitleAndIdItemList(self): """Tests getCategoryChildTitleAndIdItemList.""" base_cat = self.getCategoryTool().newContent(portal_type='Base Category') diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py index ea6e59ff1e839881e18bc02e88f09618edd1f67c..ff560b554beed27a640e8a07bf1150ab1466b671 100644 --- a/product/ERP5/tests/testInventoryAPI.py +++ b/product/ERP5/tests/testInventoryAPI.py @@ -1227,17 +1227,18 @@ class TestInventoryList(InventoryAPITestCase): self.other_node.getUid()), group_by=('use_uid', ), select_list=['use_uid']) - self.assertEqual(4, len(inventory_list)) + self.assertEqual(3, len(inventory_list)) self.assertTrue(hasattr(inventory_list[0], 'use_uid')) self.assertEqual([r.inventory for r in inventory_list if r.use_uid == use.use1.use11.getUid()], [5]) self.assertEqual([r.inventory for r in inventory_list if r.use_uid == use.use1.use12.getUid()], [11]) - # the summary lines + # the summary line self.assertEqual([r.inventory for r in inventory_list if r.use_uid == use.use1.getUid()], [11+5]) - self.assertEqual([r.inventory for r in inventory_list - if r.use_uid == use.getUid()], [11+5]) + # no summary for base category + self.assertEqual([r.use_uid for r in inventory_list + if r.use_uid == use.getUid()], []) # the name of a column can also be used, from stock or other tables inventory_list = getInventoryList(node_uid=(self.node.getUid(),