From 78cf1c94c455a7b45070cf288111a447677acb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Thu, 21 Oct 2021 17:14:37 +0900 Subject: [PATCH] core: Extend Category import with an option to force deletion of categories in use Category spreadsheet import did not delete categories if some documents where related to these categories. While this may make sense when using this import in site with already some data, in many cases, we want to be able to delete the categories, so that the result is that the category tree match the imported spreadsheet. This extend the dialog to support a new "force delete" mode that delete categories even if they are use, leaving the documents using categories with broken relations. --- .../CategoryTool_importCategoryFile.py | 5 ++- .../your_existing_category_list.xml | 6 +++- product/ERP5OOo/tests/testOOoImport.py | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py index ef5888f907..af5e591908 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py @@ -153,15 +153,14 @@ for base_category, category_list in category_list_spreadsheet_dict.iteritems(): message="Kept category", ) kept_category_counter += 1 - elif hasRelation(category): - # TODO: add a dialog parameter allowing to delete this path + elif hasRelation(category) and existing_category_list != 'force_delete': report( level='warning', field_type='Warning', field_category=category.getRelativeUrl(), message="Category is used and can not be deleted or expired ", ) - elif existing_category_list == 'delete': + elif existing_category_list in ('delete', 'force_delete'): recurse = False deleted_category_counter += 1 report( diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_viewImportCategoryFileDialog/your_existing_category_list.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_viewImportCategoryFileDialog/your_existing_category_list.xml index 3cbf8326f6..29f3ce08ae 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_viewImportCategoryFileDialog/your_existing_category_list.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_viewImportCategoryFileDialog/your_existing_category_list.xml @@ -228,9 +228,13 @@ expire - Delete Categories + Delete Categories (Unless They are Used) delete + + Delete Categories (Even if They are Used) + force_delete + diff --git a/product/ERP5OOo/tests/testOOoImport.py b/product/ERP5OOo/tests/testOOoImport.py index 55d1cfd26d..82fd825a70 100644 --- a/product/ERP5OOo/tests/testOOoImport.py +++ b/product/ERP5OOo/tests/testOOoImport.py @@ -664,6 +664,37 @@ class TestOOoImport(TestOOoImportMixin): self.assertEqual('FR', france.getCodification()) self.assertEqual(1, france.getIntIndex()) + def test_CategoryTool_importCategoryFileDeletionSupportForCategoriesInUse(self): + region = self.portal.portal_categories.region + region.newContent(id='dummy_region') + self.portal.person_module.newContent( + portal_type='Person', + region_value=region.dummy_region + ) + self.tic() + self.portal.portal_categories.CategoryTool_importCategoryFile( + import_file=makeFileUpload('import_region_category.sxc'), + existing_category_list='delete') + self.tic() + self.assertEqual(3, len(region)) + # dummy region is in used so it was not deleted + self.assertTrue('dummy_region' in region.objectIds()) + + def test_CategoryTool_importCategoryFileForcedDeletionSupportForCategoriesInUse(self): + region = self.portal.portal_categories.region + region.newContent(id='dummy_region') + self.portal.person_module.newContent( + portal_type='Person', + region_value=region.dummy_region + ) + self.tic() + self.portal.portal_categories.CategoryTool_importCategoryFile( + import_file=makeFileUpload('import_region_category.sxc'), + existing_category_list='force_delete') + self.tic() + self.assertEqual(2, len(region)) + self.assertFalse('dummy_region' in region.objectIds()) + def test_CategoryTool_importCategoryFileExpirationSupport(self): # tests simple use of CategoryTool_importCategoryFile script region = self.portal.portal_categories.region -- 2.25.1