[Erp5-report] r23736 - /erp5/trunk/products/ERP5/Document/OrderLine.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Sep 22 13:48:44 CEST 2008
Author: kazuhiko
Date: Mon Sep 22 13:48:40 2008
New Revision: 23736
URL: http://svn.erp5.org?rev=23736&view=rev
Log:
make hasLineContent(), _getTotalPrice() and getTotalQuantity() faster.
now there is no need to cache results of hasLineContent().
Modified:
erp5/trunk/products/ERP5/Document/OrderLine.py
Modified: erp5/trunk/products/ERP5/Document/OrderLine.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/OrderLine.py?rev=23736&r1=23735&r2=23736&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/OrderLine.py (original)
+++ erp5/trunk/products/ERP5/Document/OrderLine.py Mon Sep 22 13:48:40 2008
@@ -30,7 +30,6 @@
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
-from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5.Document.DeliveryLine import DeliveryLine
from Products.ERP5.Document.Movement import Movement
@@ -69,21 +68,12 @@
'hasLineContent')
def hasLineContent(self):
"""Return true if the object contains lines.
- We cache results in a volatile variable.
+
+ This method only checks the first sub document because all sub
+ documents should be Order Line in reality if we have Order Line
+ inside Order Line.
"""
- transactional_variable = getTransactionalVariable(self)
- call_method_key = ('Products.ERP5.Document.OrderLine.hasLineContent', self.getPhysicalPath())
- try:
- result = transactional_variable[call_method_key]
- except KeyError:
- result = False
- meta_type = self.meta_type
- for i in self.objectValues():
- if i.meta_type==meta_type:
- result = True
- break
- transactional_variable[call_method_key] = result
- return result
+ return len(self) != 0 and self.objectValues()[0].meta_type == self.meta_type
def _getTotalPrice(self, default=0.0, context=None, fast=0):
"""Returns the total price for this order line.
@@ -96,7 +86,7 @@
if self.hasLineContent():
meta_type = self.meta_type
return sum(l.getTotalPrice(context=context)
- for l in self.contentValues() if l.meta_type==meta_type)
+ for l in self.objectValues() if l.meta_type==meta_type)
return DeliveryLine._getTotalPrice(self,
default=default,
context=context,
@@ -116,7 +106,7 @@
if self.hasLineContent():
meta_type = self.meta_type
return sum(l.getTotalQuantity() for l in
- self.contentValues() if l.meta_type==meta_type)
+ self.objectValues() if l.meta_type==meta_type)
elif self.hasCellContent(base_id=base_id):
if fast : # Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0]
More information about the Erp5-report
mailing list