Commit d50cff7c authored by Jérome Perrin's avatar Jérome Perrin

expose some more attributes to rows returned by getMovementHistoryList: debit,

credit, debit_price and credit_price, it's better than doing this in scripts


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36020 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4b8703aa
...@@ -17,6 +17,7 @@ from ZTUtils import make_query ...@@ -17,6 +17,7 @@ from ZTUtils import make_query
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from zLOG import LOG, PROBLEM from zLOG import LOG, PROBLEM
from Products.ERP5Type.Message import translateString from Products.ERP5Type.Message import translateString
from ComputedAttribute import ComputedAttribute
class InventoryBrain(ZSQLBrain): class InventoryBrain(ZSQLBrain):
""" """
...@@ -381,3 +382,27 @@ class MovementHistoryListBrain(InventoryListBrain): ...@@ -381,3 +382,27 @@ class MovementHistoryListBrain(InventoryListBrain):
timezone = obj.getStopDate().timezone() timezone = obj.getStopDate().timezone()
self.date = self.date.toZone(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)
...@@ -1631,7 +1631,45 @@ class TestMovementHistoryList(InventoryAPITestCase): ...@@ -1631,7 +1631,45 @@ class TestMovementHistoryList(InventoryAPITestCase):
node_uid=self.node.getUid(), node_uid=self.node.getUid(),
omit_input=1, omit_input=1,
omit_output=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): class TestNextNegativeInventoryDate(InventoryAPITestCase):
"""Tests getInventory methods. """Tests getInventory methods.
......
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