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):
return self.getParentValue().getParentValue().isAccountable()
security.declareProtected(Permissions.AccessContentsInformation, 'getPrice')
def getPrice(self, context=None, REQUEST=None, **kw):
def getPrice(self, *args, **kw):
"""
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,
'getRootDeliveryValue')
......
......@@ -114,24 +114,18 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated,
"""
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. """
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:
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()])
if not self.hasCellContent(base_id='movement'):
return Movement._getTotalPrice(self, 0.0, context)
elif fast: # Use MySQL
return self.DeliveryLine_zGetTotal()[0].total_price or 0.0
return sum(cell.getTotalPrice(default=0.0, context=context)
for cell in self.getCellValueList())
security.declareProtected( Permissions.AccessContentsInformation,
'getTotalQuantity')
def getTotalQuantity(self, fast=1):
def getTotalQuantity(self, fast=0):
"""
Returns the quantity if no cell or the total quantity if cells
......
......@@ -88,21 +88,10 @@ class OrderLine(DeliveryLine):
else: return quantity * price
if fast is argument true, then a SQL method will be used.
"""
base_id = 'movement'
if self.hasLineContent():
return sum(l.getTotalPrice() for l in
self.contentValues(meta_type=self.meta_type))
elif self.hasCellContent(base_id=base_id):
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
return sum(l.getTotalPrice(context=context)
for l in self.contentValues(meta_type=self.meta_type))
return DeliveryLine._getTotalPrice(self, context=context, fast=fast)
security.declareProtected(Permissions.AccessContentsInformation,
'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