Commit c2051c80 authored by Aurel's avatar Aurel

cache entry must also be flushed at former movement's date

parent 86c95e10
......@@ -65,10 +65,10 @@ for loop_item in xrange(len(uid)):\n
min_date = min(min_date, getStartDate[loop_item])\n
else:\n
min_date = getStartDate[loop_item]\n
if min_date:\n
try:\n
context.SimulationTool_zTrimInventoryCacheFromDateOnCatalog(date=min_date)\n
except ProgrammingError:\n
\n
try:\n
context.SimulationTool_zTrimInventoryCacheFromDateOnCatalog(uid_list=uid, min_date=min_date)\n
except ProgrammingError:\n
# Create table if it does not exits\n
# Then no need to flush an empty table\n
context.SimulationTool_zCreateInventoryCache()\n
......
......@@ -8,7 +8,8 @@
<dictionary>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>date</string> </value>
<value> <string>uid_list\r\n
min_date</string> </value>
</item>
<item>
<key> <string>connection_id</string> </key>
......@@ -22,10 +23,17 @@
<key> <string>src</string> </key>
<value> <string encoding="cdata"><![CDATA[
DELETE FROM \n
DELETE \n
FROM \n
inventory_cache \n
WHERE \n
date > <dtml-sqlvar expr="date" type="datetime">
date > (SELECT min(date) from stock where <dtml-sqltest uid_list column=uid type=int multiple>)\n
<dtml-if min_date>\n
OR\n
date > <dtml-sqlvar expr="min_date" type="datetime">\n
</dtml-if>\n
\n
]]></string> </value>
</item>
......
4
\ No newline at end of file
12
\ No newline at end of file
......@@ -2807,17 +2807,58 @@ class TestInventoryCacheTable(InventoryAPITestCase):
value + INVENTORY_QUANTITY_4 + self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
# Delete movement, so it gets unindexed
self.assertEquals(
value + 2 * INVENTORY_QUANTITY_4 + 3 * self.INVENTORY_QUANTITY_1,
self.getInventory(optimisation__=False, **inventory_kw),
)
# Move movement's start date in the future and check cache is flushed
# at former date
movement.edit(start_date=self.NOW - 1)
self.tic()
self.assertEquals(
value + INVENTORY_QUANTITY_4 + 3 * self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
self.doubleStockValue()
# Cache hit again
self.assertEquals(
value + INVENTORY_QUANTITY_4 + 3 * self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
self.assertEquals(
value + INVENTORY_QUANTITY_4 + 7 * self.INVENTORY_QUANTITY_1,
self.getInventory(optimisation__=False, **inventory_kw),
)
# Set date back in the past, cache is clear again
movement.edit(start_date=self.LAST_CACHED_MOVEMENT_DATE)
self.tic()
self.assertEquals(
value + INVENTORY_QUANTITY_4 + 7 * self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
self.doubleStockValue()
# Cache hit again
self.assertEquals(
value + INVENTORY_QUANTITY_4 + 7 * self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
self.assertEquals(
value + 2 * INVENTORY_QUANTITY_4 + 15 * self.INVENTORY_QUANTITY_1,
self.getInventory(optimisation__=False, **inventory_kw),
)
# Delete movement, so it gets unindexed and cache entry is flushed
self.folder.manage_delObjects(ids=[movement.getId(), ])
self.tic()
self.assertEquals(
value + 3 * self.INVENTORY_QUANTITY_1,
value + 15 * self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
self.doubleStockValue()
# Cache hit again
self.assertEquals(
value + 3 * self.INVENTORY_QUANTITY_1,
value + 15 * self.INVENTORY_QUANTITY_1,
self.getInventory(**inventory_kw),
)
......@@ -2860,6 +2901,7 @@ class TestInventoryCacheTable(InventoryAPITestCase):
# Make sure it is dropped
self.assertRaises(ProgrammingError,
self.portal.SimulationTool_zTrimInventoryCacheFromDateOnCatalog,
uid_list = (0,),
date=DateTime())
# Check that src__ call still works
inventory_kw={
......@@ -2870,6 +2912,7 @@ class TestInventoryCacheTable(InventoryAPITestCase):
# Table is still not created
self.assertRaises(ProgrammingError,
self.portal.SimulationTool_zTrimInventoryCacheFromDateOnCatalog,
uid_list = (0,),
date=DateTime())
# This call should not fail
# It will create table, fill it and check optimisation is used
......@@ -2887,6 +2930,7 @@ class TestInventoryCacheTable(InventoryAPITestCase):
# Make sure it is dropped
self.assertRaises(ProgrammingError,
self.portal.SimulationTool_zTrimInventoryCacheFromDateOnCatalog,
uid_list = (0,),
date=DateTime())
# Create a new movement, indexation should not fail
INVENTORY_QUANTITY_4 = 5000
......@@ -2928,12 +2972,15 @@ class TestInventoryCacheTable(InventoryAPITestCase):
# Make sure it is dropped
self.assertRaises(ProgrammingError,
self.portal.SimulationTool_zTrimInventoryCacheFromDateOnCatalog,
uid_list = (0,),
date=DateTime())
# Delete movement
self.folder.manage_delObjects(ids=[movement.getId(), ])
self.tic()
# This call must not fail as table has been created
self.portal.SimulationTool_zTrimInventoryCacheFromDateOnCatalog(date=DateTime())
self.portal.SimulationTool_zTrimInventoryCacheFromDateOnCatalog(
uid_list = (0,),
date=DateTime())
# This call should not fail
# It will create table, fill it and check optimisation is used
......
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