Commit 3d2761c1 authored by Ayush Tiwari's avatar Ayush Tiwari

CommitTool: Build snapshot after checking if the transition is possible or not

parent fe89ccd1
......@@ -124,17 +124,21 @@ class BusinessCommit(Folder):
"""
This function uses the current commit to create a new snapshot
"""
portal_commit = self.aq_parent
site = self.getPortalObject()
portal_commits = self.aq_parent
# Create empty snapshot
snapshot = portal_commit.newContent(portal_type='Business Snapshot')
snapshot = portal_commits.newContent(portal_type='Business Snapshot')
# Add the current commit as predecessor. This way we can have the BI
# BPI in that commit to the Business Snapshot also.
snapshot.setSimilarValue(self)
self.setSimilarValue(snapshot)
# Build the snapshot
snapshot.buildSnapshot()
if snapshot not in [None, self]:
if site.portal_workflow.isTransitionPossible(
snapshot, 'build'):
snapshot.build()
return snapshot
......
......@@ -150,7 +150,7 @@ class BusinessSnapshot(Folder):
return None
def buildSnapshot(self):
def build(self, **kwargs):
"""
Using equivalent commit, create a snapshot of ZODB state
"""
......
......@@ -179,7 +179,7 @@ class CommitTool (BaseTool):
return self.objectValues(portal_type='Business Snapshot')
security.declarePublic('newContent')
def newContent(self, id=None, **kw):
def newContent(self, id=None, portal_type=None, **kw):
"""
Override newContent so as to use 'id' generated like hash
Also, create new commit only when all old commits are committed
......@@ -189,13 +189,13 @@ class CommitTool (BaseTool):
all_commited = all([l.getTranslatedValidationState() == 'commited'
for l in old_commit_list])
if not all_commited:
if not all_commited and (portal_type == 'Business Commit'):
raise ValueError('Please commit your last commit before creating new one')
if id is None:
id = uuid.uuid1()
new_obj = super(CommitTool, self).newContent(id, **kw)
new_obj = super(CommitTool, self).newContent(id, portal_type,**kw)
# Add the last commit as its predecessor
commit_list = [l for l
......
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