Commit 733252df authored by Sebastien Robin's avatar Sebastien Robin

added week frequency


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1949 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1e982ab8
...@@ -31,6 +31,7 @@ from Products.CMFCore.utils import getToolByName ...@@ -31,6 +31,7 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Periodicity import Periodicity from Products.ERP5.Document.Periodicity import Periodicity
from Products.CMFCore.WorkflowCore import WorkflowMethod
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from DateTime import DateTime from DateTime import DateTime
...@@ -39,7 +40,7 @@ from zLOG import LOG ...@@ -39,7 +40,7 @@ from zLOG import LOG
class Alarm(XMLObject,Periodicity): class Alarm(Periodicity, XMLObject):
""" """
An Alarm is in charge of checking anything (quantity of a certain An Alarm is in charge of checking anything (quantity of a certain
resource on the stock, consistency of some order,....) periodically. resource on the stock, consistency of some order,....) periodically.
...@@ -65,10 +66,9 @@ class Alarm(XMLObject,Periodicity): ...@@ -65,10 +66,9 @@ class Alarm(XMLObject,Periodicity):
, PropertySheet.XMLObject , PropertySheet.XMLObject
, PropertySheet.CategoryCore , PropertySheet.CategoryCore
, PropertySheet.DublinCore , PropertySheet.DublinCore
, PropertySheet.Alarm , PropertySheet.Periodicity
, PropertySheet.Document , PropertySheet.Document
, PropertySheet.Task , PropertySheet.Task
, PropertySheet.Periodicity
, PropertySheet.Alarm , PropertySheet.Alarm
) )
...@@ -91,11 +91,16 @@ class Alarm(XMLObject,Periodicity): ...@@ -91,11 +91,16 @@ class Alarm(XMLObject,Periodicity):
""" """
# Set the new date # Set the new date
self.setStartDate(DateTime()) LOG('activeSense, self.getPath()',0,self.getPath())
self.setStopDate(DateTime())
#self.setStartDate(DateTime())
#self.setStopDate(DateTime())
self.setNextAlarmDate()
self.reindexObject()
method_id = self.getActiveSenseMethodId() method_id = self.getActiveSenseMethodId()
method = getattr(self.activate(),method_id) if method_id is not None:
return method() method = getattr(self.activate(),method_id)
return method()
security.declareProtected(Permissions.ModifyPortalContent, 'sense') security.declareProtected(Permissions.ModifyPortalContent, 'sense')
def sense(self): def sense(self):
...@@ -106,11 +111,25 @@ class Alarm(XMLObject,Periodicity): ...@@ -106,11 +111,25 @@ class Alarm(XMLObject,Periodicity):
previous calculation made by activeSense. previous calculation made by activeSense.
""" """
method_id = self.getSenseMethodId() method_id = self.getSenseMethodId()
method = getattr(self,method_id) process = self.getCurrentActiveProcess()
return method() value = False
if process is None:
process = self.getLastActiveProcess()
if process is None:
return value
if method_id is not None:
method = getattr(self,method_id)
value = method()
else:
for result in process.getResultList():
if result.severity > result.INFO:
value = True
break
process.setSenseValue(value)
return value
security.declareProtected(Permissions.View, 'report') security.declareProtected(Permissions.View, 'report')
def report(self): def report(self,process=None):
""" """
This methods produces a report (HTML) This methods produces a report (HTML)
This generate the output of the results. It can be used to nicely This generate the output of the results. It can be used to nicely
...@@ -118,8 +137,14 @@ class Alarm(XMLObject,Periodicity): ...@@ -118,8 +137,14 @@ class Alarm(XMLObject,Periodicity):
be made by activeSense. be made by activeSense.
""" """
method_id = self.getReportMethodId() method_id = self.getReportMethodId()
LOG('Alarm.report, method_id',0,method_id)
method = getattr(self,method_id) method = getattr(self,method_id)
return method() process = self.getCurrentActiveProcess()
if process is None:
process = self.getLastActiveProcess()
result = method(process=process)
process.setDescription(result)
return result
security.declareProtected(Permissions.ModifyPortalContent, 'solve') security.declareProtected(Permissions.ModifyPortalContent, 'solve')
def solve(self): def solve(self):
...@@ -132,15 +157,18 @@ class Alarm(XMLObject,Periodicity): ...@@ -132,15 +157,18 @@ class Alarm(XMLObject,Periodicity):
pass pass
security.declareProtected(Permissions.ModifyPortalContent, 'notify') security.declareProtected(Permissions.ModifyPortalContent, 'notify')
def notify(self): def _notify(self):
""" """
This method is called to notify people that some alarm has This method is called to notify people that some alarm has
been sensed. been sensed.
for example we can send email. for example we can send email.
We define nothing here, because we will use an interaction workflow.
""" """
pass pass
notify = WorkflowMethod(_notify, id='notify')
security.declareProtected(Permissions.View, 'getActiveProcessList') security.declareProtected(Permissions.View, 'getActiveProcessList')
def getActiveProcessList(self): def getActiveProcessList(self):
...@@ -201,6 +229,8 @@ class Alarm(XMLObject,Periodicity): ...@@ -201,6 +229,8 @@ class Alarm(XMLObject,Periodicity):
""" """
portal_activities = getToolByName(self,'portal_activities') portal_activities = getToolByName(self,'portal_activities')
active_process = portal_activities.newActiveProcess() active_process = portal_activities.newActiveProcess()
active_process.setStartDate(DateTime())
active_process.setCausalityValue(self)
process_id = active_process.getId() process_id = active_process.getId()
active_process_id_list = self.getActiveProcessIdList() active_process_id_list = self.getActiveProcessIdList()
active_process_id_list.append(process_id) active_process_id_list.append(process_id)
...@@ -214,19 +244,17 @@ class Alarm(XMLObject,Periodicity): ...@@ -214,19 +244,17 @@ class Alarm(XMLObject,Periodicity):
""" """
return getattr(self,'_active_process_id_list',[]) return getattr(self,'_active_process_id_list',[])
security.declareProtected(Permissions.View, 'getActiveProcessValueList')
def getActiveProcessValueList(self,**kw):
"""
Returns the list of process used to store results of this alarm
"""
portal_activities = getToolByName(self,'portal_activities')
return [portal_activities._getOb(x) for x in self.getActiveProcessIdList()]
security.declareProtected(Permissions.ModifyPortalContent, 'setActiveProcessIdList') security.declareProtected(Permissions.ModifyPortalContent, 'setActiveProcessIdList')
def setActiveProcessIdList(self, value): def setActiveProcessIdList(self, value):
""" """
Set the list of process ids used to store results of this alarm Set the list of process ids used to store results of this alarm
""" """
self._active_process_id_list = value self._active_process_id_list = value
# diff date in millesonds, so if *1000/86400 we do have days
#if (diff_date*1000/86400) >= alarm.getPeriodicityDay():
# alarm.activeSense()
#continue
#elif alarm.getPeriodicityWeek()
...@@ -116,12 +116,20 @@ class Periodicity(Base): ...@@ -116,12 +116,20 @@ class Periodicity(Base):
def validateWeek(self,date): def validateWeek(self,date):
periodicity_week_frequency = self.getPeriodicityWeekFrequency() periodicity_week_frequency = self.getPeriodicityWeekFrequency()
periodicity_week_day_list = self.getPeriodicityWeekDayList() periodicity_week_day_list = self.getPeriodicityWeekDayList()
if periodicity_week_frequency is None and periodicity_week_day_list in ([],None,()): periodicity_week_list = self.getPeriodicityWeekList()
if periodicity_week_frequency is None and periodicity_week_day_list in ([],None,()) \
and periodicity_week_list is None:
return 1 return 1
if periodicity_week_frequency not in ('',None): if periodicity_week_frequency not in ('',None):
return (date.week() % periodicity_week_frequency) == 0 if not((date.week() % periodicity_week_frequency) == 0):
else: return 0
return date.Day() in periodicity_week_day_list if periodicity_week_day_list not in (None,(),[]):
if not (date.Day() in periodicity_week_day_list):
return 0
if periodicity_week_list not in (None,(),[]):
if not (date.week() in periodicity_week_list):
return 0
return 1
def validateMonth(self,date): def validateMonth(self,date):
periodicity_month_frequency = self.getPeriodicityMonthFrequency() periodicity_month_frequency = self.getPeriodicityMonthFrequency()
......
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