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

Also catalog non accountable movements in stock table

parent 4f0931e7
......@@ -395,8 +395,8 @@ class BalanceTransaction(AccountingTransaction, Inventory):
from Products.ERP5Type.Document import newTempAccountingTransactionLine
# When have to reindex temp objects with quantity 0 in
# order to update stock if delta become 0, but but redefining
# isAccountable we do not insert 0 lines in stock
def isAccountable(self):
# isMovement we do not insert 0 lines in stock
def isMovement(self):
return self.getProperty('total_price', 0) != 0 or \
self.getProperty('quantity', 0) != 0
def factory(*args, **kw):
......@@ -408,7 +408,7 @@ class BalanceTransaction(AccountingTransaction, Inventory):
if destination_total_asset_price is not None:
kw['destination_total_asset_price'] = destination_total_asset_price
doc._edit(*args, **kw)
doc.isAccountable = types.MethodType(isAccountable, doc)
doc.isMovement = types.MethodType(isMovement, doc)
if relative_url:
......
......@@ -32,6 +32,7 @@ selection_report\r\n
ignore_variation\r\n
standardize\r\n
omit_simulation\r\n
only_accountable\r\n
section_filtered\r\n
omit_input\r\n
omit_output\r\n
......@@ -197,7 +198,9 @@ WHERE\n
<dtml-if omit_simulation>\n
AND catalog.portal_type != \'Simulation Movement\'\n
</dtml-if>\n
\n
<dtml-if only_accountable>\n
AND <dtml-var stock_table_id>.is_accountable\n
</dtml-if>\n
<dtml-if selection_domain>\n
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=stock_table_id, join_column=\'node_uid\')">\n
</dtml-if>\n
......
......@@ -427,6 +427,7 @@ selection_report\r\n
ignore_variation\r\n
standardize\r\n
omit_simulation\r\n
only_accountable\r\n
omit_input\r\n
omit_output\r\n
omit_asset_increase\r\n
......@@ -540,6 +541,9 @@ WHERE\n
<dtml-if omit_simulation>\n
AND catalog.portal_type != \'Simulation Movement\'\n
</dtml-if>\n
<dtml-if only_accountable>\n
AND stock.is_accountable\n
</dtml-if>\n
\n
<dtml-if omit_input>\n
AND ( ( stock.is_cancellation AND stock.quantity > 0 )\n
......
41067
\ No newline at end of file
41068
\ No newline at end of file
......@@ -128,8 +128,9 @@ VALUES\n
<dtml-sqlvar expr="row_item[8]" type="int" optional>,\n
<dtml-sqlvar expr="row_item[9]" type="int" optional>,\n
<dtml-sqlvar expr="row_item[10]" type="int" optional>,\n
<dtml-sqlvar expr="row_item[11]" type="int">, \n
<dtml-sqlvar expr="row_item[11]" type="int">,\n
<dtml-sqlvar expr="row_item[12]" type="float" optional>,\n
1, <dtml-comment>only accountable</dtml-comment>\n
<dtml-sqlvar expr="row_item[13]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[14]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[15]" type="float" optional>,\n
......
......@@ -94,7 +94,7 @@ WHERE\n
\n
<dtml-let row_list="[]" uid_dict="{}">\n
<dtml-in prefix="loop" expr="_.range(_.len(uid))">\n
<dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and isAccountable[loop_item] and getResourceUid[loop_item]">\n
<dtml-if "not(isInventoryMovement[loop_item]) and isMovement[loop_item] and getResourceUid[loop_item]">\n
<dtml-if "getDestinationUid[loop_item]">\n
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">\n
<dtml-call expr="row_list.append([\n
......@@ -112,6 +112,7 @@ WHERE\n
getResourceUid[loop_item],\n
getInventoriatedQuantity[loop_item],\n
isCancellationAmount[loop_item],\n
isAccountable[loop_item],\n
getStopDate[loop_item], \n
getStartDate[loop_item], \n
getDestinationInventoriatedTotalAssetPrice[loop_item], \n
......@@ -137,6 +138,7 @@ WHERE\n
getResourceUid[loop_item],\n
-(getInventoriatedQuantity[loop_item] or 0), \n
isCancellationAmount[loop_item],\n
isAccountable[loop_item],\n
getStartDate[loop_item], \n
getStopDate[loop_item],\n
getSourceInventoriatedTotalAssetPrice[loop_item], \n
......@@ -168,13 +170,14 @@ VALUES\n
<dtml-sqlvar expr="row_item[11]" type="int">, \n
<dtml-sqlvar expr="row_item[12]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[13]" type="int">, \n
<dtml-sqlvar expr="row_item[14]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[14]" type="int">,\n
<dtml-sqlvar expr="row_item[15]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[16]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[17]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[16]" type="datetime" optional>,\n
<dtml-sqlvar expr="row_item[17]" type="float" optional>,\n
<dtml-sqlvar expr="row_item[18]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[19]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[20]" type="string" optional>\n
<dtml-sqlvar expr="row_item[20]" type="string" optional>,\n
<dtml-sqlvar expr="row_item[21]" type="string" optional>\n
)\n
<dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n
......
......@@ -34,6 +34,7 @@
`mirror_node_uid` BIGINT UNSIGNED,\n
`resource_uid` BIGINT UNSIGNED,\n
`quantity` real ,\n
`is_accountable` BOOLEAN,\n
`date` datetime,\n
`mirror_date` datetime,\n
`total_price` real ,\n
......
......@@ -71,6 +71,7 @@ CREATE TABLE `stock` (\n
`resource_uid` BIGINT UNSIGNED,\n
`quantity` real,\n
`is_cancellation` BOOLEAN,\n
`is_accountable` BOOLEAN,\n
`date` datetime,\n
`mirror_date` datetime,\n
`total_price` real ,\n
......
239
\ No newline at end of file
243
\ No newline at end of file
......@@ -288,8 +288,8 @@ class TestInventory(InventoryAPITestCase):
def test_SimulationMovementisAccountable(self):
"""Test Simulation Movements are not accountable if related to a delivery.
"""
sim_mvt = self._makeSimulationMovement(quantity=100)
mvt = self._makeMovement(quantity=100)
sim_mvt = self._makeSimulationMovement(quantity=2)
mvt = self._makeMovement(quantity=3)
# simulation movement are accountable,
self.failUnless(sim_mvt.isAccountable())
# unless connected to a delivery movement
......@@ -297,8 +297,10 @@ class TestInventory(InventoryAPITestCase):
self.failIf(sim_mvt.isAccountable())
# not accountable movement are not counted by getInventory
self.tic() # (after reindexing of course)
self.assertInventoryEquals(100, section_uid=self.section.getUid())
self.assertInventoryEquals(3, section_uid=self.section.getUid())
# unless you pass only_accountable=False
self.assertInventoryEquals(5, section_uid=self.section.getUid(), only_accountable=False)
def test_OmitSimulation(self):
"""Test omit_simulation argument to getInventory.
"""
......@@ -1788,7 +1790,25 @@ class TestMovementHistoryList(InventoryAPITestCase):
omit_simulation=1)
self.assertEquals(1, len(movement_history_list))
self.assertEquals(100, movement_history_list[0].quantity)
def test_OnlyAccountable(self):
"""Test that only_accountable works with getMovementHistoryList"""
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self._makeMovement(quantity=2)
self._makeMovement(quantity=3, is_accountable=False)
# by default, only accountable movements are returned
movement_history_list = getMovementHistoryList(
section_uid=self.section.getUid(),)
self.assertEquals(1, len(movement_history_list))
self.assertEquals(2, movement_history_list[0].quantity)
# unless only_accountable=False is passed
movement_history_list = getMovementHistoryList(
section_uid=self.section.getUid(),
only_accountable=False)
self.assertEquals(2, len(movement_history_list))
self.assertEquals(sorted((2,3)), sorted(
brain.quantity for brain in movement_history_list))
def test_RunningTotalQuantity(self):
"""Test that a running_total_quantity attribute is set on brains
"""
......
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