Skip to content

Commit

Permalink
Fixed setDefaultPriority and added a new upgrde step to set default o…
Browse files Browse the repository at this point in the history
…n existing ARs
  • Loading branch information
mikejmets committed Mar 14, 2014
1 parent 40e6fdf commit daad3aa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
9 changes: 5 additions & 4 deletions bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ def getDefaultMemberDiscount(self):
else:
return "0.00"

def getDefaultPriority(self):
def setDefaultPriority(self):
""" compute default priority """
bsc = getToolByName(self, 'bika_setup_catalog')
priorities = bsc(
Expand All @@ -848,10 +848,11 @@ def getDefaultPriority(self):
for brain in priorities:
obj = brain.getObject()
if obj.getIsDefault():
return obj
self.setPriority(obj)
return

logging.error('Priority: no priority specified')
return None
logging.error('Priority: no default priority found')
return

security.declareProtected(View, 'getResponsible')
def getResponsible(self):
Expand Down
2 changes: 1 addition & 1 deletion bika/lims/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>3019</version>
<version>3020</version>
<dependencies>
<dependency>profile-jarn.jsi18n:default</dependency>
<dependency>profile-Products.ATExtensions:default</dependency>
Expand Down
4 changes: 1 addition & 3 deletions bika/lims/subscribers/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ def AfterTransitionEventHandler(instance, event):
def ObjectInitializedEventHandler(instance, event):

if instance.portal_type != "AnalysisRequest":
#import pdb; pdb.set_trace()
return

priority = instance.getPriority()
if priority:
#print 'Got priority'
return

instance.setPriority(instance.getDefaultPriority())
instance.setDefaultPriority()
return
9 changes: 9 additions & 0 deletions bika/lims/upgrade/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,13 @@
sortkey="1"
profile="bika.lims:default"/>

<genericsetup:upgradeStep
title="Set default Priority on ARs"
description=""
source="3019"
destination="3020"
handler="bika.lims.upgrade.to3020.upgrade"
sortkey="1"
profile="bika.lims:default"/>

</configure>
21 changes: 21 additions & 0 deletions bika/lims/upgrade/to3020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from Acquisition import aq_inner
from Acquisition import aq_parent
from bika.lims import logger
from bika.lims.permissions import *
from Products.CMFCore import permissions
from Products.CMFCore.utils import getToolByName
from zExceptions import BadRequest


def upgrade(tool):
portal = aq_parent(aq_inner(tool))
portal_catalog = getToolByName(portal, 'portal_catalog')

proxies = portal_catalog(portal_type="AnalysisRequest")
ars = [proxy.getObject() for proxy in proxies]
for ar in ars:
if not ar.getPriority():
ar.setDefaultPriority()


return True

0 comments on commit daad3aa

Please sign in to comment.