Commit b71cc88b authored by Kevin Deldycke's avatar Kevin Deldycke

Make getTotalPrice working on Delivery Cells


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4011 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d6d633e4
...@@ -29,16 +29,18 @@ ...@@ -29,16 +29,18 @@
from Globals import InitializeClass from Globals import InitializeClass
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5.Variated import Variated
from Products.ERP5.VariationValue import VariationValue
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.ERP5.VariationValue import VariationValue
from Products.ERP5.Variated import Variated
from Products.ERP5Type.Base import TempBase from Products.ERP5Type.Base import TempBase
from Products.CMFCategory.Renderer import Renderer from Products.CMFCategory.Renderer import Renderer
from zLOG import LOG from zLOG import LOG
class Amount(Base, Variated): class Amount(Base, Variated):
""" """
A mix-in class which provides some utilities A mix-in class which provides some utilities
...@@ -65,7 +67,7 @@ class Amount(Base, Variated): ...@@ -65,7 +67,7 @@ class Amount(Base, Variated):
, PropertySheet.SimpleItem , PropertySheet.SimpleItem
, PropertySheet.Amount , PropertySheet.Amount
, PropertySheet.Price , PropertySheet.Price
) )
# A few more mix-in methods which should be relocated # A few more mix-in methods which should be relocated
# THIS MUST BE UPDATE WITH CATEGORY ACQUISITION # THIS MUST BE UPDATE WITH CATEGORY ACQUISITION
...@@ -144,11 +146,11 @@ class Amount(Base, Variated): ...@@ -144,11 +146,11 @@ class Amount(Base, Variated):
self._setVariationCategoryList(value) self._setVariationCategoryList(value)
self.reindexObject() self.reindexObject()
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'getVariationBaseCategoryList') 'getVariationBaseCategoryList')
def getVariationBaseCategoryList(self, omit_option_base_category=0): def getVariationBaseCategoryList(self, omit_option_base_category=0):
""" """
Return the list of base_category from all variation related to Return the list of base_category from all variation related to
amount. amount.
It is maybe a nonsense, but useful for correcting user errors. It is maybe a nonsense, but useful for correcting user errors.
""" """
...@@ -225,7 +227,7 @@ class Amount(Base, Variated): ...@@ -225,7 +227,7 @@ class Amount(Base, Variated):
getVariationRangeBaseCategoryList -> notion of getVariationRangeBaseCategoryList -> notion of
getVariationBaseCategoryList is different getVariationBaseCategoryList is different
""" """
resource = self.getDefaultResourceValue() resource = self.getDefaultResourceValue()
if resource is not None: if resource is not None:
result = resource.getVariationBaseCategoryList() result = resource.getVariationBaseCategoryList()
else: else:
...@@ -242,11 +244,11 @@ class Amount(Base, Variated): ...@@ -242,11 +244,11 @@ class Amount(Base, Variated):
Return a dictionary of: Return a dictionary of:
{property_id: property_value,} {property_id: property_value,}
Each property is a variation of the resource. Each property is a variation of the resource.
The variation property list is defined on resource, The variation property list is defined on resource,
with setVariationPropertyList. with setVariationPropertyList.
""" """
property_dict = {} property_dict = {}
resource = self.getDefaultResourceValue() resource = self.getDefaultResourceValue()
if resource is not None: if resource is not None:
variation_list = resource.getVariationPropertyList() variation_list = resource.getVariationPropertyList()
for variation_property in variation_list: for variation_property in variation_list:
...@@ -255,17 +257,17 @@ class Amount(Base, Variated): ...@@ -255,17 +257,17 @@ class Amount(Base, Variated):
getattr(self, variation_property, None) getattr(self, variation_property, None)
return property_dict return property_dict
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'setVariationPropertyDict') 'setVariationPropertyDict')
def setVariationPropertyDict(self, property_dict): def setVariationPropertyDict(self, property_dict):
""" """
Take a parameter a property dict like: Take a parameter a property dict like:
{property_id: property_value,} {property_id: property_value,}
Each property is a variation of the resource. Each property is a variation of the resource.
If one of the property_id is not a variation, a exception If one of the property_id is not a variation, a exception
KeyError is raised. KeyError is raised.
""" """
resource = self.getDefaultResourceValue() resource = self.getDefaultResourceValue()
if resource is not None: if resource is not None:
variation_list = resource.getVariationPropertyList() variation_list = resource.getVariationPropertyList()
else: else:
...@@ -313,7 +315,6 @@ class Amount(Base, Variated): ...@@ -313,7 +315,6 @@ class Amount(Base, Variated):
unit_base_price = resource.getPrice(context=self) unit_base_price = resource.getPrice(context=self)
return unit_base_price return unit_base_price
security.declareProtected(Permissions.AccessContentsInformation, 'getDuration') security.declareProtected(Permissions.AccessContentsInformation, 'getDuration')
def getDuration(self): def getDuration(self):
""" """
...@@ -323,14 +324,11 @@ class Amount(Base, Variated): ...@@ -323,14 +324,11 @@ class Amount(Base, Variated):
quantity_unit = self.getQuantityUnit() quantity_unit = self.getQuantityUnit()
if quantity_unit is None: if quantity_unit is None:
return None return None
common_time_category = 'time' common_time_category = 'time'
if common_time_category in quantity_unit[:len(common_time_category)]: if common_time_category in quantity_unit[:len(common_time_category)]:
duration = quantity duration = quantity
else: else:
duration = None duration = None
return duration return duration
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalBasePrice') security.declareProtected(Permissions.AccessContentsInformation, 'getTotalBasePrice')
...@@ -342,13 +340,14 @@ class Amount(Base, Variated): ...@@ -342,13 +340,14 @@ class Amount(Base, Variated):
efficiency = self.getEfficiency() efficiency = self.getEfficiency()
if efficiency != 0: if efficiency != 0:
resource_price = self.getResourcePrice() resource_price = self.getResourcePrice()
if resource_price is None: if resource_price is not None:
return None return resource_price * self.getConvertedQuantity() / efficiency
result = resource_price * self.getConvertedQuantity() / efficiency price = self.getPrice()
quantity = self.getQuantity()
if type(price) in (type(1.0), type(1)) and type(quantity) in (type(1.0), type(1)):
result = quantity * price
return result return result
# Conversion to standard unit # Conversion to standard unit
security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedQuantity') security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedQuantity')
def getConvertedQuantity(self): def getConvertedQuantity(self):
...@@ -586,4 +585,3 @@ class Amount(Base, Variated): ...@@ -586,4 +585,3 @@ class Amount(Base, Variated):
def _setLostQuantity(self, value): def _setLostQuantity(self, value):
return self._setProfitQuantity(- value) return self._setProfitQuantity(- value)
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