[Erp5-report] r10351 - in /erp5/trunk/products/ERP5/Document: Movement.py Resource.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Sep 27 12:17:05 CEST 2006


Author: jerome
Date: Wed Sep 27 12:17:03 2006
New Revision: 10351

URL: http://svn.erp5.org?rev=10351&view=rev
Log:
getPrice and getTotalPrice can receive the default argument from getProperty, this commit only makes those methods accept default to be passed as a positional argument.


Modified:
    erp5/trunk/products/ERP5/Document/Movement.py
    erp5/trunk/products/ERP5/Document/Resource.py

Modified: erp5/trunk/products/ERP5/Document/Movement.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Movement.py?rev=10351&r1=10350&r2=10351&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Movement.py (original)
+++ erp5/trunk/products/ERP5/Document/Movement.py Wed Sep 27 12:17:03 2006
@@ -26,9 +26,12 @@
 #
 ##############################################################################
 
+from warnings import warn
 from AccessControl import ClassSecurityInfo
 
 from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
+from Products.ERP5Type.Base import Base
+
 from Products.ERP5.Core import MetaNode, MetaResource
 
 from Products.ERP5Type.XMLObject import XMLObject
@@ -199,38 +202,64 @@
     # Call a script on the context
     return context.Movement_lookupPrice()
 
-  def _getTotalPrice(self, context):
+  def _getTotalPrice(self, default=None, context=None):
     price = self.getPrice(context=context)
     quantity = self.getQuantity()
     if type(price) in (type(1.0), type(1)) and \
         type(quantity) in (type(1.0), type(1)):
       return quantity * price
     else:
-      return None
+      return default
 
   security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
-  def getPrice(self, context=None, REQUEST=None, **kw):
+  def getPrice(self, default=None, context=None, REQUEST=None, **kw):
     """
       Get the Price in the context.
 
       If price is not stored locally, lookup a price and store it.
     """
+    # XXX As all accessors can recieve the default value as first positional
+    # argument, so we changed the first positional argument from context to
+    # default. Here we try to provide backward compatibility for scripts
+    # passing the context as first positional argument, and advice them to use:
+    #   context.getPrice(context=context)
+    # instead of:
+    #   context.getPrice(context)
+    if isinstance(default, Base) and context is None:
+      msg = 'getPrice first argument is supposed to be the default value'\
+            ' accessor, the context should be passed as with the context='\
+            ' keyword argument'
+      warn(msg, DeprecationWarning)
+      LOG('ERP5', WARNING, msg)
+      context = default
+      default = None
+
     local_price = self._baseGetPrice()
     if local_price is None:
       # We must find a price for this movement
-      local_price = self._getPrice(self.asContext(
+      local_price = self._getPrice(context=self.asContext(
                             context=context, REQUEST=REQUEST, **kw))
       # And store it localy
-      if local_price is not None: self.setPrice(local_price)
+      if local_price is not None:
+        self.setPrice(local_price)
     return local_price
 
   security.declareProtected( Permissions.AccessContentsInformation,
                              'getTotalPrice')
-  def getTotalPrice(self, context=None, REQUEST=None, **kw):
+  def getTotalPrice(self, default=None, context=None, REQUEST=None, **kw):
     """
       Get the Total Price in the context.
     """
-    return self._getTotalPrice(self.asContext(context=context,
+    # see getPrice
+    if isinstance(default, Base) and context is None:
+      msg = 'getTotalPrice first argument is supposed to be the default value'\
+            ' accessor, the context should be passed as with the context='\
+            ' keyword argument'
+      warn(msg, DeprecationWarning)
+      LOG('ERP5', WARNING, msg)
+      context = default
+      default = None
+    return self._getTotalPrice(default=default, context=self.asContext(context=context,
                                 REQUEST=REQUEST, **kw),**kw)
 
   security.declareProtected( Permissions.AccessContentsInformation,

Modified: erp5/trunk/products/ERP5/Document/Resource.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Resource.py?rev=10351&r1=10350&r2=10351&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Resource.py (original)
+++ erp5/trunk/products/ERP5/Document/Resource.py Wed Sep 27 12:17:03 2006
@@ -635,10 +635,20 @@
 
     security.declareProtected(Permissions.AccessContentsInformation, 
                               'getPrice')
-    def getPrice(self, context=None, REQUEST=None, **kw):
+    def getPrice(self, default=None, context=None, REQUEST=None, **kw):
       """
       Return the unit price of a resource in a specific context.
       """
+      # see Movement.getPrice
+      if isinstance(default, Base) and context is None:
+        msg = 'getPrice first argument is supposed to be the default value'\
+              ' accessor, the context should be passed as with the context='\
+              ' keyword argument'
+        warn(msg, DeprecationWarning)
+        LOG('ERP5', WARNING, msg)
+        context = default
+        default = None
+      
       price_parameter_dict = self._getPriceParameterDict(
                                      context=context, REQUEST=REQUEST, **kw)
       # Calculate the unit price
@@ -716,4 +726,4 @@
       return 0
 
 
-        
+        




More information about the Erp5-report mailing list