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 ef5888f9076ae647bd902e3c1342216f48a161d2..af5e591908d4871f7e6f9ad6816f11ecb3fdd8d2 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 3cbf8326f636a1540263e7a8da2762fa554499b1..29f3ce08ae2c9764009118105605ef9a97405e64 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 55d1cfd26d2828cf47ef7fad627735142422e290..82fd825a7089715dde5ccc1c8c27bd579230b237 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