[Erp5-report] r12519 - in /erp5/trunk/products/ERP5: Document/ PropertySheet/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Feb 2 11:42:21 CET 2007
Author: romain
Date: Fri Feb 2 11:42:18 2007
New Revision: 12519
URL: http://svn.erp5.org?rev=12519&view=rev
Log:
Add documents and property sheet for managing calendar.
Added:
erp5/trunk/products/ERP5/Document/Calendar.py
erp5/trunk/products/ERP5/Document/CalendarException.py
erp5/trunk/products/ERP5/Document/CalendarPeriod.py
erp5/trunk/products/ERP5/Document/LeavePeriod.py
erp5/trunk/products/ERP5/PropertySheet/CalendarException.py
Added: erp5/trunk/products/ERP5/Document/Calendar.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Calendar.py?rev=12519&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Document/Calendar.py (added)
+++ erp5/trunk/products/ERP5/Document/Calendar.py Fri Feb 2 11:42:18 2007
@@ -1,0 +1,61 @@
+##############################################################################
+#
+# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
+# Rafael Monnerat <rafael at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# 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
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+from AccessControl import ClassSecurityInfo
+from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
+from Products.ERP5Type.XMLObject import XMLObject
+from Products.ERP5.Document.Path import Path
+
+class Calendar(Path, XMLObject):
+ """
+ Calendar contains Calendar Lines.
+ """
+ # CMF Type Definition
+ meta_type = 'ERP5 Calendar'
+ portal_type = 'Calendar'
+ isPortalContent = 1
+ isRADContent = 1
+
+ # Declarative security
+ security = ClassSecurityInfo()
+ security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+ # XXX Should be removed if interface are not a good Idea.
+ #__implements__ = ( Interface.Inventory, )
+
+ # Default Properties
+ property_sheets = ( PropertySheet.Base
+ , PropertySheet.XMLObject
+ , PropertySheet.CategoryCore
+ , PropertySheet.DublinCore
+ , PropertySheet.Task
+ , PropertySheet.Arrow
+ , PropertySheet.Movement
+ , PropertySheet.Delivery
+ , PropertySheet.Path
+ )
Added: erp5/trunk/products/ERP5/Document/CalendarException.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/CalendarException.py?rev=12519&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Document/CalendarException.py (added)
+++ erp5/trunk/products/ERP5/Document/CalendarException.py Fri Feb 2 11:42:18 2007
@@ -1,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
+# Rafael Monnerat <rafael at nexedi.com>
+# Courteaud Romain <romain at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# 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
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+from AccessControl import ClassSecurityInfo
+from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
+from Products.ERP5Type.XMLObject import XMLObject
+
+class CalendarException(XMLObject):
+ """
+ Exception of Calendar Period
+ """
+ # CMF Type Definition
+ meta_type = 'ERP5 Calendar Exception'
+ portal_type = 'Calendar Exception'
+ isPortalContent = 1
+ isRADContent = 1
+
+ # Declarative security
+ security = ClassSecurityInfo()
+ security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+ # Default Properties
+ property_sheets = ( PropertySheet.Base
+ , PropertySheet.XMLObject
+ , PropertySheet.CategoryCore
+ , PropertySheet.DublinCore
+ , PropertySheet.CalendarException
+ )
Added: erp5/trunk/products/ERP5/Document/CalendarPeriod.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/CalendarPeriod.py?rev=12519&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Document/CalendarPeriod.py (added)
+++ erp5/trunk/products/ERP5/Document/CalendarPeriod.py Fri Feb 2 11:42:18 2007
@@ -1,0 +1,199 @@
+##############################################################################
+#
+# Copyright (c) 2006,2007 Nexedi SARL and Contributors. All Rights Reserved.
+# Rafael Monnerat <rafael at nexedi.com>
+# Courteaud Romain <romain at nexedi.com>
+#
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# 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
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+from Globals import InitializeClass, PersistentMapping
+from AccessControl import ClassSecurityInfo
+
+from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
+from Products.ERP5.Document.DeliveryLine import DeliveryLine
+from Products.ERP5.Document.Periodicity import Periodicity
+from Products.ERP5.Document.Movement import Movement
+
+class CalendarPeriod(Movement, Periodicity):
+ """
+ Calendar Period is used to add available time of the user in a
+ period of Time
+ """
+
+ meta_type = 'ERP5 Calendar Period'
+ portal_type = 'Calendar Period'
+
+ # Declarative security
+ security = ClassSecurityInfo()
+ security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+ # Declarative properties
+ property_sheets = ( PropertySheet.Base
+ , PropertySheet.XMLObject
+ , PropertySheet.CategoryCore
+ , PropertySheet.DublinCore
+ , PropertySheet.Amount
+ , PropertySheet.Task
+ , PropertySheet.Movement
+ , PropertySheet.Arrow
+ , PropertySheet.Periodicity
+ , PropertySheet.Path
+ )
+
+ security.declareProtected(Permissions.AccessContentsInformation,
+ 'isAccountable')
+ def isAccountable(self):
+ """
+ For now, consider that it's always accountable
+ """
+ return 1
+
+ security.declareProtected(Permissions.AccessContentsInformation,
+ 'getDestinationUid')
+ def getDestinationUid(self, *args, **kw):
+ """
+ Return the destination uid
+ """
+ # XXX Should be configurable via acquisition
+ destination_value = self.getParentValue().getDestinationValue()
+ if destination_value is not None:
+ destination_uid = destination_value.getUid()
+ else:
+ destination_uid = self.getParentUid()
+ return destination_uid
+
+ security.declareProtected(Permissions.AccessContentsInformation,
+ 'getInventoriatedQuantity')
+ def getInventoriatedQuantity(self, default=None, *args, **kw):
+ """
+ Surcharged accessor to calculate the Quantity in second.
+ """
+ quantity = self.getQuantity(*args, **kw)
+ if quantity in [None, 0]:
+ calendar_start_date = self.getStartDate()
+ calendar_stop_date = self.getStopDate()
+ if (calendar_start_date is not None) and (calendar_stop_date is not None):
+ # Convert Days to second
+ quantity = int(calendar_stop_date) - int(calendar_start_date)
+ else:
+ quantity = default
+ return quantity
+
+ security.declareProtected( Permissions.AccessContentsInformation,
+ 'asMovementList')
+ def asMovementList(self):
+ """
+ Generate multiple movement from a single one.
+ It is used for cataloging a movement multiple time in
+ the movement/stock tables.
+
+ Ex: a movement have multiple destinations.
+ asMovementList returns a list a movement context with different
+ single destination.
+ """
+ result = []
+ for from_date, to_date in self._getDatePeriodList():
+ result.append(self.asContext(self, start_date=to_date,
+ stop_date=from_date))
+ return result
+
+ def _getDatePeriodList(self):
+ """
+ Get all periods between periodicity start date
+ and periodicity stop date
+ """
+ result = []
+ exception_value_list = self.contentValues(portal_type="Calendar Exception")
+ exception_date_list = [x.getExceptionDate() \
+ for x in exception_value_list]
+ exception_date_list = [x for x in exception_date_list if x is not None]
+ exception_date_list.sort()
+ if len(exception_date_list) != 0:
+ current_exception_date = exception_date_list.pop(0).Date()
+ else:
+ current_exception_date = None
+
+ start_date = self.getStartDate()
+ if start_date is not None:
+ stop_date = self.getStopDate(start_date)
+ periodicity_stop_date = self.getPeriodicityStopDate(
+ start_date)
+ duration = stop_date - start_date
+ # First date has to respect the periodicity config
+ next_start_date = self.getNextAlarmDate(start_date-1)
+ while (next_start_date is not None) and \
+ (next_start_date <= periodicity_stop_date):
+
+ # Check that next_start_date is not an exception
+ if (current_exception_date is not None) and \
+ (current_exception_date == next_start_date.Date()):
+ # We match an exception date
+ # So, don't return this value
+ # Update the next exception date
+ if len(exception_date_list) != 0:
+ current_exception_date = exception_date_list.pop(0).Date()
+ else:
+ current_exception_date = None
+ elif (current_exception_date is not None) and \
+ (current_exception_date < next_start_date.Date()):
+ # SQL method don't like iterator
+# yield (next_start_date, next_start_date+duration)
+ result.append([next_start_date, next_start_date+duration])
+ # Update the next exception date
+ if len(exception_date_list) != 0:
+ current_exception_date = exception_date_list.pop(0).Date()
+ else:
+ current_exception_date = None
+ else:
+ # SQL method don't like iterator
+# yield (next_start_date, next_start_date+duration)
+ result.append([next_start_date, next_start_date+duration])
+ next_start_date = self.getNextAlarmDate(next_start_date)
+
+ return result
+
+ def getNextAlarmDate(self, current_date, next_start_date=None):
+ """
+ Get the next date where this periodic event should start.
+ """
+ if next_start_date is None:
+ next_start_date = current_date
+ if next_start_date > current_date:
+ return
+ else:
+ # Make sure the old date is not too far away
+ nb_days = int(current_date-next_start_date)
+ next_start_date = next_start_date + nb_days
+
+ previous_date = next_start_date
+ next_start_date += 1
+ while 1:
+ if (self.validateDay(next_start_date)) and \
+ (self.validateWeek(next_start_date)) and \
+ (self.validateMonth(next_start_date)):
+ break
+ else:
+ next_start_date += 1
+ return next_start_date
Added: erp5/trunk/products/ERP5/Document/LeavePeriod.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/LeavePeriod.py?rev=12519&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/Document/LeavePeriod.py (added)
+++ erp5/trunk/products/ERP5/Document/LeavePeriod.py Fri Feb 2 11:42:18 2007
@@ -1,0 +1,71 @@
+##############################################################################
+#
+# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
+# Courteaud Romain <romain at nexedi.com>
+#
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# 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
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+from Globals import InitializeClass, PersistentMapping
+from AccessControl import ClassSecurityInfo
+
+from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
+from Products.ERP5.Document.CalendarPeriod import CalendarPeriod
+
+class LeavePeriod(CalendarPeriod):
+ """
+ Leave Period is used to remove available time of the user in a
+ period of Time
+ """
+
+ meta_type = 'ERP5 Leave Period'
+ portal_type = 'Leave Period'
+
+ # Declarative security
+ security = ClassSecurityInfo()
+ security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+ # Declarative properties
+ property_sheets = ( PropertySheet.Base
+ , PropertySheet.XMLObject
+ , PropertySheet.CategoryCore
+ , PropertySheet.DublinCore
+ , PropertySheet.Amount
+ , PropertySheet.Task
+ , PropertySheet.Movement
+ , PropertySheet.Arrow
+ , PropertySheet.Periodicity
+ , PropertySheet.Path
+ )
+
+ security.declareProtected(Permissions.AccessContentsInformation,
+ 'getInventoriatedQuantity')
+ def getInventoriatedQuantity(self, default=None, *args, **kw):
+ """
+ Surcharged accessor to calculate the Quantity in second.
+ """
+ quantity = CalendarPeriod.getInventoriatedQuantity(
+ self, default=default,
+ *args, **kw)
+ return -quantity
Added: erp5/trunk/products/ERP5/PropertySheet/CalendarException.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/CalendarException.py?rev=12519&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/CalendarException.py (added)
+++ erp5/trunk/products/ERP5/PropertySheet/CalendarException.py Fri Feb 2 11:42:18 2007
@@ -1,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# 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
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+class CalendarException:
+ """
+ Properties for Calendar Exception
+ """
+ _properties = (
+ {
+ 'id': 'exception_date',
+ 'description': 'The date of the periodicity exception.',
+ 'type': 'date',
+ 'mode': 'w'
+ },
+ )
More information about the Erp5-report
mailing list