From acb324286b13cc62d79d907362cb4f23ce192487 Mon Sep 17 00:00:00 2001 From: Alexandre Boeglin <alex@nexedi.com> Date: Wed, 30 Apr 2008 11:37:33 +0000 Subject: [PATCH] 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 --- product/ERP5/Document/DeliveryCell.py | 11 +++++++++-- product/ERP5/Document/DeliveryLine.py | 22 ++++++++-------------- product/ERP5/Document/OrderLine.py | 17 +++-------------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/product/ERP5/Document/DeliveryCell.py b/product/ERP5/Document/DeliveryCell.py index 228bf7c5f6..4a0e216611 100644 --- a/product/ERP5/Document/DeliveryCell.py +++ b/product/ERP5/Document/DeliveryCell.py @@ -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') diff --git a/product/ERP5/Document/DeliveryLine.py b/product/ERP5/Document/DeliveryLine.py index 5027b9a0a6..a138cc02b8 100644 --- a/product/ERP5/Document/DeliveryLine.py +++ b/product/ERP5/Document/DeliveryLine.py @@ -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 diff --git a/product/ERP5/Document/OrderLine.py b/product/ERP5/Document/OrderLine.py index 39be6ed6a9..a8f7fa6c96 100644 --- a/product/ERP5/Document/OrderLine.py +++ b/product/ERP5/Document/OrderLine.py @@ -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') -- 2.30.9