Commit acb32428 authored by Alexandre Boeglin's avatar Alexandre Boeglin

Patch by Julien Muchembled (jm at nexedi dot com):

* factorize getTotalPrice
* set default value of fast to 0


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20854 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d3542609
...@@ -91,11 +91,18 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement): ...@@ -91,11 +91,18 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
return self.getParentValue().getParentValue().isAccountable() return self.getParentValue().getParentValue().isAccountable()
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice') security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
def getPrice(self, context=None, REQUEST=None, **kw): def getPrice(self, *args, **kw):
""" """
call Movement.getPrice call Movement.getPrice
""" """
return Movement.getPrice(self, context=context, REQUEST=REQUEST, **kw) return Movement.getPrice(self, *args, **kw)
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self, *args, **kw):
"""
call Movement.getTotalPrice
"""
return Movement.getTotalPrice(self, *args, **kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getRootDeliveryValue') 'getRootDeliveryValue')
......
...@@ -114,24 +114,18 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated, ...@@ -114,24 +114,18 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated,
""" """
return self.getParentValue().isAccountable() and (not self.hasCellContent()) return self.getParentValue().isAccountable() and (not self.hasCellContent())
def _getTotalPrice(self, context, fast=1): def _getTotalPrice(self, context, fast=0):
""" Returns the total price for this line or the cells it contains. """ """ Returns the total price for this line or the cells it contains. """
base_id = 'movement' if not self.hasCellContent(base_id='movement'):
if not self.hasCellContent(base_id=base_id): return Movement._getTotalPrice(self, 0.0, context)
quantity = self.getQuantity() or 0.0 elif fast: # Use MySQL
price = self.getPrice(context=context) or 0.0 return self.DeliveryLine_zGetTotal()[0].total_price or 0.0
return quantity * price return sum(cell.getTotalPrice(default=0.0, context=context)
else: for cell in self.getCellValueList())
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, security.declareProtected( Permissions.AccessContentsInformation,
'getTotalQuantity') 'getTotalQuantity')
def getTotalQuantity(self, fast=1): 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
......
...@@ -88,21 +88,10 @@ class OrderLine(DeliveryLine): ...@@ -88,21 +88,10 @@ class OrderLine(DeliveryLine):
else: return quantity * price else: return quantity * price
if fast is argument true, then a SQL method will be used. if fast is argument true, then a SQL method will be used.
""" """
base_id = 'movement'
if self.hasLineContent(): if self.hasLineContent():
return sum(l.getTotalPrice() for l in return sum(l.getTotalPrice(context=context)
self.contentValues(meta_type=self.meta_type)) for l in self.contentValues(meta_type=self.meta_type))
elif self.hasCellContent(base_id=base_id): return DeliveryLine._getTotalPrice(self, context=context, fast=fast)
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()])
else:
quantity = self.getQuantity() or 0.0
price = self.getPrice(context=context) or 0.0
return quantity * price
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getTotalQuantity') 'getTotalQuantity')
......
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