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): ...@@ -116,11 +116,19 @@ class Delivery(XMLObject):
if hasattr(aq_base(c), 'updatePrice'): if hasattr(aq_base(c), 'updatePrice'):
c.updatePrice() c.updatePrice()
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice') security.declareProtected( Permissions.AccessContentsInformation,
def getTotalPrice(self, src__=0, **kw): 'getTotalPrice')
""" def getTotalPrice(self, fast=1, src__=0, **kw):
Returns the total price for this order """ 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['explanation_uid'] = self.getUid()
kw.update(self.portal_catalog.buildSQLQuery(**kw)) kw.update(self.portal_catalog.buildSQLQuery(**kw))
if src__: if src__:
...@@ -129,10 +137,17 @@ class Delivery(XMLObject): ...@@ -129,10 +137,17 @@ class Delivery(XMLObject):
return aggregate.total_price or 0 return aggregate.total_price or 0
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity') security.declareProtected(Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self, src__=0, **kw): def getTotalQuantity(self, fast=1, src__=0, **kw):
""" """ Returns the total quantity of this order.
Returns the quantity if no cell or the total quantity if cells 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['explanation_uid'] = self.getUid()
kw.update(self.portal_catalog.buildSQLQuery(**kw)) kw.update(self.portal_catalog.buildSQLQuery(**kw))
if src__: if src__:
......
...@@ -118,19 +118,24 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated): ...@@ -118,19 +118,24 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated):
""" """
return self.aq_parent.isAccountable() and (not self.hasCellContent()) 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' base_id = 'movement'
if not self.hasCellContent(base_id=base_id): if not self.hasCellContent(base_id=base_id):
quantity = self.getQuantity() or 0.0 quantity = self.getQuantity() or 0.0
price = self.getPrice(context=context) or 0.0 price = self.getPrice(context=context) or 0.0
return quantity * price return quantity * price
else: else:
# Use MySQL if fast : # Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0] aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.total_price or 0.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') security.declareProtected( Permissions.AccessContentsInformation,
def getTotalQuantity(self): 'getTotalQuantity')
def getTotalQuantity(self, fast=0):
""" """
Returns the quantity if no cell or the total quantity if cells Returns the quantity if no cell or the total quantity if cells
""" """
...@@ -138,9 +143,10 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated): ...@@ -138,9 +143,10 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated):
if not self.hasCellContent(base_id=base_id): if not self.hasCellContent(base_id=base_id):
return self.getQuantity() return self.getQuantity()
else: else:
# Use MySQL if fast : # Use MySQL
aggregate = self.DeliveryLine_zGetTotal()[0] aggregate = self.DeliveryLine_zGetTotal()[0]
return aggregate.total_quantity or 0.0 return aggregate.total_quantity or 0.0
return sum([cell.getQuantity() for cell in self.getCellValueList()])
security.declareProtected(Permissions.View, 'hasCellContent') security.declareProtected(Permissions.View, 'hasCellContent')
def hasCellContent(self, base_id='movement'): def hasCellContent(self, base_id='movement'):
......
...@@ -64,19 +64,21 @@ class Invoice(AccountingTransaction): ...@@ -64,19 +64,21 @@ class Invoice(AccountingTransaction):
security.declareProtected( security.declareProtected(
Permissions.AccessContentsInformation, 'getTotalPrice') Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self): def getTotalPrice(self, **kw):
""" Returns the total price for this invoice """ """ Returns the total price for this invoice """
return Delivery.getTotalPrice(self, kw.update({
portal_type = self.getPortalObject()\ 'portal_type': self.getPortalObject()\
.getPortalInvoiceMovementTypeList()) .getPortalInvoiceMovementTypeList() })
return Delivery.getTotalPrice(self, **kw)
security.declareProtected( security.declareProtected(
Permissions.AccessContentsInformation, 'getTotalQuantity') Permissions.AccessContentsInformation, 'getTotalQuantity')
def getTotalQuantity(self): def getTotalQuantity(self, **kw):
""" Returns the total quantity for this invoice """ """ Returns the total quantity for this invoice """
return Delivery.getTotalQuantity(self, kw.update({
portal_type = self.getPortalObject()\ 'portal_type': self.getPortalObject()\
.getPortalInvoiceMovementTypeList()) .getPortalInvoiceMovementTypeList() })
return Delivery.getTotalQuantity(self, **kw)
security.declareProtected( security.declareProtected(
Permissions.AccessContentsInformation, 'getTotalNetPrice') 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