From e88206621e5ac06af1c875ab5d8c6a33ebe46266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 27 Sep 2006 10:17:03 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10351 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/Movement.py | 43 ++++++++++++++++++++++++++----- product/ERP5/Document/Resource.py | 14 ++++++++-- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/product/ERP5/Document/Movement.py b/product/ERP5/Document/Movement.py index 6d3aa44229..60b239bb2b 100644 --- a/product/ERP5/Document/Movement.py +++ b/product/ERP5/Document/Movement.py @@ -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 @@ class Movement(XMLObject, Amount): # 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, diff --git a/product/ERP5/Document/Resource.py b/product/ERP5/Document/Resource.py index 1c5e07acf8..f882b9a2c6 100644 --- a/product/ERP5/Document/Resource.py +++ b/product/ERP5/Document/Resource.py @@ -635,10 +635,20 @@ class Resource(XMLMatrix, CoreResource, Variated): 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 @@ class Resource(XMLMatrix, CoreResource, Variated): return 0 - \ No newline at end of file + -- 2.30.9