extension.erp5.CRMMigration.py 2.65 KB
Newer Older
1 2
##############################################################################
#
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
3
# Copyright (c) 2011 Nexedi SA and Contributors. All Rights Reserved.
4 5
#
# WARNING: This program as such is intended to be used by professional
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
6
# programmers who take the whole responsibility of assessing all potential
7 8
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
9
# guarantees and support are strongly adviced to contract a Free Software
10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 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
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 26 27 28 29 30
#
##############################################################################

from Products.ERP5Type.patches.WorkflowTool import WorkflowHistoryList

def migrateEventWorkflowHistory(self):
31 32 33
  """
  Migrate event_workflow history to event_simulation_workflow history.
  """
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  portal_type = self.getPortalType()
  portal = self.getPortalObject()
  if portal_type not in portal.getPortalEventTypeList():
    return
  workflow_history = getattr(self, 'workflow_history', None)
  if workflow_history is None:
    return
  event_workflow = workflow_history.get('event_workflow', None)
  if event_workflow is None:
    return
  event_simulation_workflow = workflow_history.get('event_simulation_workflow', None)
  if event_simulation_workflow is not None:
    # already migrated.
    return
  self.workflow_history['event_simulation_workflow'] = \
      WorkflowHistoryList(event_workflow[:])
  migrate_state_dict = {
    'acknowledged':'delivered',
    'assigned':'stopped',
    'expired':'delivered',
    'new':'stopped',
    'ordered':'confirmed',
    'responded':'delivered',
  }
  current_state = event_workflow[-1]['simulation_state']
  new_state = migrate_state_dict.get(current_state, None)
  if new_state is None:
    # no need to change the state.
    return
  workflow_tool = portal.portal_workflow
  workflow_tool._jumpToStateFor(self, new_state)
65
  self.reindexObject()
66 67
  return 'Event workflow migration on %s : %s -> %s' % (
      self.getPath(), current_state, new_state)