Commit a4cc0f30 authored by Jérome Perrin's avatar Jérome Perrin

BT : Fix template_keep_path_list for CatalogMethodTemplateItem

For years, erp5_calendar was keeping a duplicated copy of [`z_catalog_stock_list`](https://lab.nexedi.com/nexedi/erp5/blob/985bbc0f716397c899e6af69ef431db86923ab34/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_catalog_stock_list.sql). In a79ca4c1, the functionality was merged in erp5_mysql_innodb and the duplicated copy was removed from erp5_calendar.

Problem is that when we update erp5_calendar, `z_catalog_stock_list` is removed.

We discussed in a79ca4c1 (comment 15577) and suggested to use *Path of objects that should be kept* like we already did in some other business templates.

I tried, but it did not work, because [`CatalogMethod.preinstall`](https://lab.nexedi.com/nexedi/erp5/blob/985bbc0f716397c899e6af69ef431db86923ab34/product/ERP5/Document/BusinessTemplate.py#L2995)  overwrites the returned value of [`ObjectTemplateItem.preinstall`](https://lab.nexedi.com/nexedi/erp5/blob/985bbc0f716397c899e6af69ef431db86923ab34/product/ERP5/Document/BusinessTemplate.py#L1117)  (which supports template_keep_path_list) with the returned value of [`BaseTemplateItem.preinstall`](https://lab.nexedi.com/nexedi/erp5/blob/985bbc0f716397c899e6af69ef431db86923ab34/product/ERP5/Document/BusinessTemplate.py#L485) which does not support it.

My understanding is that the former is necessary to install the z sql methods and later to install the configuration on the catalog
 ( see efe5294e ), but the order does not really mater, so it's safe to give priority to `ObjectTemplateItem.preinstall`.

I also add some tests for template_keep_path_list, I think it was not tested, and modified erp5_calendar as suggested.

/cc @seb @kazuhiko @aurel @tiwariayush @gabriel 

/reviewed-on !260
parents b30fb33a 916ef8c4
portal_catalog/erp5_mysql_innodb/z_catalog_stock_list
\ No newline at end of file
...@@ -2954,8 +2954,15 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -2954,8 +2954,15 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
return xml_data return xml_data
def preinstall(self, context, installed_item, **kw): def preinstall(self, context, installed_item, **kw):
modified_object_dict = ObjectTemplateItem.preinstall(self, context, installed_item, **kw) """Compute diffs from catalog methods metadata and objects.
modified_object_dict.update(BaseTemplateItem.preinstall(self, context, installed_item, **kw))
To support `template_keep_path_list`, we give priority to
ObjectTemplateItem.preinstall which may return 'Removed but should be kept'
"""
# from catalog methods properies (from generateXML)
modified_object_dict = BaseTemplateItem.preinstall(self, context, installed_item, **kw)
# diffs from actual objects
modified_object_dict.update(ObjectTemplateItem.preinstall(self, context, installed_item, **kw))
return modified_object_dict return modified_object_dict
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
......
...@@ -6815,6 +6815,107 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -6815,6 +6815,107 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.portal.manage_delObjects(['geek_module']) self.portal.manage_delObjects(['geek_module'])
self.tic() self.tic()
def test_update_business_template_with_template_keep_path_list(self):
"""Tests for `template_keep_path_list` feature
"""
# Simulate the case where we have an installed business template providing
# the path test_document
new_object = self.portal.newContent(portal_type='File', id='test_document')
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title=self.id(),
template_path_list=('test_document',),)
self.tic()
bt.build()
self.tic()
export_dir = tempfile.mkdtemp()
try:
bt.export(path=export_dir, local=True)
self.tic()
new_bt = self.portal.portal_templates.download(
url='file://%s' % export_dir)
finally:
shutil.rmtree(export_dir)
new_bt.install()
# In a new version of the business template, this path is no longer included
# but we have configured this path as *keep_path_list*
# build and reimport this business template
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title=self.id(),
template_keep_path_list=('test_document',),)
self.tic()
bt.build()
self.tic()
export_dir = tempfile.mkdtemp()
try:
bt.export(path=export_dir, local=True)
self.tic()
new_bt = self.portal.portal_templates.download(
url='file://%s' % export_dir)
finally:
shutil.rmtree(export_dir)
self.assertEqual(
{'test_document': ('Removed but should be kept', 'Path')},
new_bt.preinstall())
def test_update_business_template_with_template_keep_path_list_catalog_method(self):
"""Tests for `template_keep_path_list` feature for the special case of catalog methods
"""
# Simulate the case where we have an installed business template providing
# the catalog method z_fake_method
catalog = self.getCatalogTool().getSQLCatalog()
catalog.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod(
id='z_fake_method',
title='',
connection_id='erp5_sql_connection',
arguments='',
template='')
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title=self.id(),
template_catalog_method_id_list=['erp5_mysql_innodb/z_fake_method'])
self.tic()
bt.build()
self.tic()
export_dir = tempfile.mkdtemp()
try:
bt.export(path=export_dir, local=True)
self.tic()
new_bt = self.portal.portal_templates.download(
url='file://%s' % export_dir)
finally:
shutil.rmtree(export_dir)
new_bt.install()
# In a new version of the business template, this catalog method is no
# longer included, but we have configured this path as *keep_path_list*
# (note that the syntax is the actual path of the object, so it includes portal_catalog)
# build and reimport this business template
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title=self.id(),
template_keep_path_list=('portal_catalog/erp5_mysql_innodb/z_fake_method',),)
self.tic()
bt.build()
self.tic()
export_dir = tempfile.mkdtemp()
try:
bt.export(path=export_dir, local=True)
self.tic()
new_bt = self.portal.portal_templates.download(
url='file://%s' % export_dir)
finally:
shutil.rmtree(export_dir)
self.assertEqual(
{'portal_catalog/erp5_mysql_innodb/z_fake_method':
('Removed but should be kept', 'CatalogMethod')},
new_bt.preinstall())
def test_BusinessTemplateWithTest(self): def test_BusinessTemplateWithTest(self):
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_string = '\ sequence_string = '\
......
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