[Erp5-report] r36020 jerome - in /erp5/trunk/products/ERP5: Extensions/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jun 7 14:41:24 CEST 2010


Author: jerome
Date: Mon Jun  7 14:41:23 2010
New Revision: 36020

URL: http://svn.erp5.org?rev=36020&view=rev
Log:
expose some more attributes to rows returned by getMovementHistoryList: debit,
credit, debit_price and credit_price, it's better than doing this in scripts

Modified:
    erp5/trunk/products/ERP5/Extensions/InventoryBrain.py
    erp5/trunk/products/ERP5/tests/testInventoryAPI.py

Modified: erp5/trunk/products/ERP5/Extensions/InventoryBrain.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Extensions/InventoryBrain.py?rev=36020&r1=36019&r2=36020&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Extensions/InventoryBrain.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Extensions/InventoryBrain.py [utf8] Mon Jun  7 14:41:23 2010
@@ -17,6 +17,7 @@
 from Products.CMFCore.utils import getToolByName
 from zLOG import LOG, PROBLEM
 from Products.ERP5Type.Message import translateString
+from ComputedAttribute import ComputedAttribute
 
 class InventoryBrain(ZSQLBrain):
   """
@@ -381,3 +382,27 @@
         timezone = obj.getStopDate().timezone()
       self.date = self.date.toZone(timezone)
 
+  def _debit(self):
+    if self.getObject().isCancellationAmount():
+      return min(self.total_quantity, 0)
+    return max(self.total_quantity, 0)
+  debit = ComputedAttribute(_debit, 1)
+
+  def _credit(self):
+    if self.getObject().isCancellationAmount():
+      return min(-(self.total_quantity or 0), 0)
+    return max(-(self.total_quantity or 0), 0)
+  credit = ComputedAttribute(_credit, 1)
+
+  def _debit_price(self):
+    if self.getObject().isCancellationAmount():
+      return min(self.total_price, 0)
+    return max(self.total_price, 0)
+  debit_price = ComputedAttribute(_debit_price, 1)
+
+  def _credit_price(self):
+    if self.getObject().isCancellationAmount():
+      return min(-(self.total_price or 0), 0)
+    return max(-(self.total_price or 0), 0)
+  credit_price = ComputedAttribute(_credit_price, 1)
+

Modified: erp5/trunk/products/ERP5/tests/testInventoryAPI.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInventoryAPI.py?rev=36020&r1=36019&r2=36020&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInventoryAPI.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testInventoryAPI.py [utf8] Mon Jun  7 14:41:23 2010
@@ -1631,7 +1631,45 @@
                                               node_uid=self.node.getUid(),
                                               omit_input=1,
                                               omit_output=1)))
-    
+
+  def test_debit_credit(self):
+    getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
+    self._makeMovement(quantity=-1, price=2,
+                       start_date=DateTime(2010, 1, 1))
+    self._makeMovement(quantity=2, price=2,
+                       start_date=DateTime(2010, 1, 2))
+    mvt_history_list = getMovementHistoryList(node_uid=self.node.getUid(),
+                                              sort_on=(('stock.date', 'ASC'),))
+    self.assertEquals(2, len(mvt_history_list))
+    self.assertEquals(0, mvt_history_list[0].debit)
+    self.assertEquals(1, mvt_history_list[0].credit)
+    self.assertEquals(0, mvt_history_list[0].debit_price)
+    self.assertEquals(2, mvt_history_list[0].credit_price)
+
+    self.assertEquals(2, mvt_history_list[1].debit)
+    self.assertEquals(0, mvt_history_list[1].credit)
+    self.assertEquals(4, mvt_history_list[1].debit_price)
+    self.assertEquals(0, mvt_history_list[1].credit_price)
+
+  def test_debit_credit_cancellation_amount(self):
+    getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
+    self._makeMovement(quantity=-1, price=2, cancellation_amount=True,
+                       start_date=DateTime(2010, 1, 1))
+    self._makeMovement(quantity=2, price=2, cancellation_amount=True,
+                       start_date=DateTime(2010, 1, 2))
+    mvt_history_list = getMovementHistoryList(node_uid=self.node.getUid(),
+                                              sort_on=(('stock.date', 'ASC'),))
+    self.assertEquals(2, len(mvt_history_list))
+    self.assertEquals(-1, mvt_history_list[0].debit)
+    self.assertEquals(0, mvt_history_list[0].credit)
+    self.assertEquals(-2, mvt_history_list[0].debit_price)
+    self.assertEquals(0, mvt_history_list[0].credit_price)
+
+    self.assertEquals(0, mvt_history_list[1].debit)
+    self.assertEquals(-2, mvt_history_list[1].credit)
+    self.assertEquals(0, mvt_history_list[1].debit_price)
+    self.assertEquals(-4, mvt_history_list[1].credit_price)
+
 
 class TestNextNegativeInventoryDate(InventoryAPITestCase):
   """Tests getInventory methods.




More information about the Erp5-report mailing list