Commit 32c8a1ef authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_interface_post: do not try to cancel "duplicates" posts

In case of Emails, several posts will be created if there are more than 1 recipients, so trying to cancel duplicates Internet Message Posts is impossible (or some customers will never receive the emails)
parent 1ed33c77
......@@ -7,7 +7,4 @@
# Priority 2 is just enough to be executed after the immediateReindexObject
tag="InterfacePostWorkflow_afterAllowExport:%s" % context.getReference()
context.activate(
serialization_tag=tag,
priority=2,
).InterfacePost_disallowExportOfSameInterfacePostListAndExport()
context.activate(tag=tag).InterfacePost_exportByActivity()
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
# Because this script can be called at the ~ same time on different
# posts, it can raise race conditions where several posts disallow
# export of each other, resulting in nothing is exported. Checking
# the current state of the post here prevents a post which has
# already been disallowed to disallow the post which disalowed it.
# 2 Posts can still be exported at same time if one isn't indexed
# correctly yet.
if context.getSimulationState() != 'exportable':
return
# 1/ Disallow export of posts for the same origin message
portal = context.getPortalObject()
module = context.getParentValue()
exportable_post_list = portal.portal_catalog(
portal_type=context.getPortalType(),
parent_uid=module.getUid(),
reference=context.getReference(),
simulation_state=['exportable', 'export_failed'],
query=SimpleQuery(uid=context.getUid(), comparison_operator="!=")
)
for exportable_post in exportable_post_list:
exportable_post.disallowExport()
# 2/ Export post
context.InterfacePost_exportAfterAllowExport()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InterfacePost_disallowExportOfSameInterfacePostListAndExport</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InterfacePost_exportAfterAllowExport</string> </value>
<value> <string>InterfacePost_exportByActivity</string> </value>
</item>
</dictionary>
</pickle>
......
context.getPortalObject().MailHost.send(context.getData())
# Export is done before sending to MailHost, as MailHost isn't transactional
# and if the workflow method fails, or if the object isn't in the correct
# workflow state, we may send several times the email.
if context.getSimulationState() == 'exportable':
context.export()
else:
raise ValueError('Object cannot be exported as its workflow state is : %s' % context.getSimulationStateTitle())
context.getPortalObject().MailHost.send(context.getData())
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