Commit 27052298 authored by Sebastien Robin's avatar Sebastien Robin

ERP5Form: relation fields must reindex when updating documents

Before, reindex was not called when you changed only a [Multi] relation field. So
it was possible to have SQL data not up to date after a change by user.

Though, most of the time this was not an issue. Usually relation fields
calls Base_edit. And even if there is no change and no reindex done by edit itself, since we
often have edit_workflow associated to documents, we usually have a reindexing.

But since we should keep the usage of edit_workflow optional, we have to call proper
setter to make sure to have updated SQL data.
parent 09df2324
##############################################################################
#
# Copyright (c) 2002-2015 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class TestMultiRelationField(ERP5TypeTestCase):
"""
A Sample Test Class
"""
def getTitle(self):
return "TestMultiRelationField"
def getBusinessTemplateList(self):
"""
Tuple of Business Templates we need to install
"""
return ('erp5_base',)
def test_01_relationFieldReindexObject(self):
"""
Check that edition of a relation field create a reindex activity.
This is necessary when only a relation field is edited on a form,
and when document is not indexed because of indirect things (like
edit_workflow).
"""
foo_object = self.portal.foo_module.newContent()
self.tic()
form = self.portal.Foo_view
relation_field = form.my_foo_category_title
category = self.portal.portal_categories.action_type.object_jump
editor = relation_field.validator.editor('my_foo_category_title', 'foo_category',
['Category'], [('Category', 'Category')], 'title', '',
[([category.getUid()], category.getUid(), category.getId(),
None, 'subfield_field_my_foo_category_title_item')], '')
self.assertFalse(foo_object.hasActivity(method_id="recursiveImmediateReindexObject"))
editor.edit(foo_object)
self.commit()
self.assertTrue(foo_object.hasActivity(method_id="recursiveImmediateReindexObject"))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testRelationField</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testRelationField</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
test.erp5.testRelationField
\ No newline at end of file
......@@ -515,13 +515,13 @@ class MultiRelationEditor:
else:
# we could call a generic method which create the setter method name
if len(relation_object_list) == 1:
set_method_name = '_set%sValue' % \
set_method_name = 'set%sValue' % \
convertToUpperCase(self.base_category)
getattr(o, set_method_name)(relation_object_list[0],
portal_type=self.portal_type_list,
checked_permission='View')
else:
set_method_name = '_set%sValueList' % \
set_method_name = 'set%sValueList' % \
convertToUpperCase(self.base_category)
getattr(o, set_method_name)(relation_object_list,
portal_type=self.portal_type_list,
......
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