From fd8688f6f75ca6484892a666e4021a98c305b99f Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Mon, 7 Mar 2005 09:14:44 +0000
Subject: [PATCH] Add method getUnitBasePrice.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2644 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/SupplyLine.py | 31 +++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/product/ERP5/Document/SupplyLine.py b/product/ERP5/Document/SupplyLine.py
index 1d74f71854..294bd8153b 100755
--- a/product/ERP5/Document/SupplyLine.py
+++ b/product/ERP5/Document/SupplyLine.py
@@ -89,6 +89,36 @@ class SupplyLineMixin(ExtensionClass.Base):
 
       return XMLMatrix.newCell(self, *kw, **kwd)
     
+    security.declareProtected(Permissions.AccessContentsInformation, 'getUnitBasePrice')
+    def getUnitBasePrice(self, context=None, REQUEST=None, **kw):
+      """
+      """
+      tmp_context = self.asContext(context=context, REQUEST=REQUEST, **kw)
+
+      base_id = 'path'
+      # get Quantity
+      base_price = None
+      if tmp_context != None:
+        # We will browse the mapped values and determine which apply
+        cell_key_list = self.getCellKeyList( base_id = base_id )
+        for key in cell_key_list:
+          if self.hasCell(base_id=base_id, *key):
+            mapped_value = self.getCell(base_id=base_id, *key)
+            if mapped_value.test(tmp_context): 
+              if 'price' in mapped_value.getMappedValuePropertyList():
+                base_price = mapped_value.getProperty('price')
+
+      if base_price in [None,'']:
+        base_price = self.getBasePrice()
+
+      priced_quantity = self.getPricedQuantity()
+
+      try:
+        unit_base_price = base_price / priced_quantity
+      except: 
+        unit_base_price = None
+
+      return unit_base_price 
       
 class SupplyLine(DeliveryLine, Path):
     """
@@ -284,5 +314,6 @@ Une ligne tarifaire."""
         p.setTitle('%s <= quantity < %s' % (repr(value[i]),repr(value[i+1])))
       self._setVariationCategoryList(self.getVariationCategoryList())
 
+
 from Products.ERP5Type.Utils import monkeyPatch
 monkeyPatch(SupplyLineMixin,SupplyLine)        
-- 
2.30.9