Commit ee04b064 authored by Jérome Perrin's avatar Jérome Perrin

add the "fast" parameter to specify wether we should use SQLCatalog or ZODB to...

add the "fast" parameter to specify wether we should use SQLCatalog or ZODB to calculate Total Price/Quantity


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4102 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 776c8ff0
......@@ -116,11 +116,19 @@ class Delivery(XMLObject):
if hasattr(aq_base(c), 'updatePrice'):
c.updatePrice()
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self, src__=0, **kw):
"""
Returns the total price for this order
"""
security.declareProtected( Permissions.AccessContentsInformation,
'getTotalPrice')
def getTotalPrice(self, fast=1, src__=0, **kw):
""" Returns the total price for this order
if the `fast` argument is set to a true value, then it use
SQLCatalog to compute the price, otherwise it sums the total
price of objects one by one.
"""
if not fast :
kw.setdefault( 'portal_type',
self.getPortalDeliveryMovementTypeList())
return sum([ line.getTotalPrice(fast=0) for line in
self.objectValues(**kw) ])
kw['explanation_uid'] = self.getUid()
kw.update(self.portal_catalog.buildSQLQuery(**kw))
if src__:
......@@ -129,10 +137,17 @@ class Delivery(XMLObject):
return aggregate.total_price or 0
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self, src__=0, **kw):
"""
Returns the quantity if no cell or the total quantity if cells
"""
def getTotalQuantity(self, fast=1, src__=0, **kw):
""" Returns the total quantity of this order.
if the `fast` argument is set to a true value, then it use
SQLCatalog to compute the quantity, otherwise it sums the total
quantity of objects one by one.
"""
if not fast :
kw.setdefault( 'portal_type',
self.getPortalDeliveryMovementTypeList())
return sum([ line.getTotalQuantity(fast=0) for line in
self.objectValues(**kw) ])
kw['explanation_uid'] = self.getUid()
kw.update(self.portal_catalog.buildSQLQuery(**kw))
if src__:
......
......@@ -118,19 +118,24 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated):
"""
return self.aq_parent.isAccountable() and (not self.hasCellContent())
def _getTotalPrice(self, context):
def _getTotalPrice(self, context, fast=0):
""" Returns the total price for this line or the cells it contains. """
base_id = 'movement'
if not self.hasCellContent(base_id=base_id):
quantity = self.getQuantity() or 0.0
price = self.getPrice(context=context) or 0.0
return quantity * price
else:
# Use MySQL
if fast : # Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.total_price or 0.0
return sum([ ( (cell.getQuantity() or 0) *
(cell.getPrice(context=context) or 0))
for cell in self.getCellValueList()])
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self):
security.declareProtected( Permissions.AccessContentsInformation,
'getTotalQuantity')
def getTotalQuantity(self, fast=0):
"""
Returns the quantity if no cell or the total quantity if cells
"""
......@@ -138,9 +143,10 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated):
if not self.hasCellContent(base_id=base_id):
return self.getQuantity()
else:
# Use MySQL
if fast : # Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.total_quantity or 0.0
return sum([cell.getQuantity() for cell in self.getCellValueList()])
security.declareProtected(Permissions.View, 'hasCellContent')
def hasCellContent(self, base_id='movement'):
......
......@@ -64,19 +64,21 @@ class Invoice(AccountingTransaction):
security.declareProtected(
Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self):
def getTotalPrice(self, **kw):
""" Returns the total price for this invoice """
return Delivery.getTotalPrice(self,
portal_type = self.getPortalObject()\
.getPortalInvoiceMovementTypeList())
kw.update({
'portal_type': self.getPortalObject()\
.getPortalInvoiceMovementTypeList() })
return Delivery.getTotalPrice(self, **kw)
security.declareProtected(
Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self):
def getTotalQuantity(self, **kw):
""" Returns the total quantity for this invoice """
return Delivery.getTotalQuantity(self,
portal_type = self.getPortalObject()\
.getPortalInvoiceMovementTypeList())
kw.update({
'portal_type': self.getPortalObject()\
.getPortalInvoiceMovementTypeList() })
return Delivery.getTotalQuantity(self, **kw)
security.declareProtected(
Permissions.AccessContentsInformation, 'getTotalNetPrice')
......
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