diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py index f1626faee2af818058b466102b5bee8f4d7642e4..9e6a990c31082c65d32f3e4894634ec2122191ca 100644 --- a/product/ERP5/tests/testInventoryAPI.py +++ b/product/ERP5/tests/testInventoryAPI.py @@ -44,6 +44,7 @@ from Products.ERP5.Document.OrderRule import OrderRule from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.utils import reindex from Products.DCWorkflow.DCWorkflow import ValidationFailed +from Products.ERP5Type.Base import _aq_reset class InventoryAPITestCase(ERP5TypeTestCase): """Base class for Inventory API Tests {{{ @@ -2010,51 +2011,75 @@ class TestInventoryDocument(InventoryAPITestCase): does not allow such things """ portal = self.getPortal() - inventory_module = portal.getDefaultModule(portal_type='Inventory') - inventory = inventory_module.newContent(portal_type='Inventory') - date = self.DUPLICATE_INVENTORY_DATE - inventory.edit(destination_value=self.node, - destination_section_value=self.section, - start_date=date) - inventory_line = inventory.newContent( - resource_value = self.resource, - quantity = 1) - self.workflow_tool = portal.portal_workflow - workflow_id = 'inventory_workflow' - transition_id = 'deliver_action' - workflow_id= 'inventory_workflow' - self.workflow_tool.doActionFor(inventory, transition_id, - wf_id=workflow_id) - self.assertEquals('delivered', inventory.getSimulationState()) - get_transaction().commit() - self.tic() - - # We should detect the previous inventory and fails - new_inventory = inventory.Base_createCloneDocument(batch_mode=1) - self.assertRaises(ValidationFailed, self.workflow_tool.doActionFor, - new_inventory, transition_id, wf_id=workflow_id) - workflow_history = self.workflow_tool.getInfoFor(ob=new_inventory, - name='history', wf_id=workflow_id) - workflow_error_message = str(workflow_history[-1]['error_message']) - self.assertTrue(workflow_error_message.find('There is already an inventory')>=0) - - # Add a case in order to check a bug when the other inventory at the - # same date does not change stock values - new_inventory = inventory.Base_createCloneDocument(batch_mode=1) - new_inventory.setStartDate(self.DUPLICATE_INVENTORY_DATE + 1) - self.workflow_tool.doActionFor(new_inventory, transition_id, - wf_id=workflow_id) - self.assertEquals('delivered', new_inventory.getSimulationState()) - get_transaction().commit() - self.tic() - new_inventory = new_inventory.Base_createCloneDocument(batch_mode=1) - self.assertRaises(ValidationFailed, self.workflow_tool.doActionFor, - new_inventory, transition_id, wf_id=workflow_id) - workflow_history = self.workflow_tool.getInfoFor(ob=new_inventory, - name='history', wf_id=workflow_id) - workflow_error_message = str(workflow_history[-1]['error_message']) - self.assertTrue(workflow_error_message.find('There is already an inventory')>=0) + portal_type_name = 'Inventory' + property_sheet_name = 'InventoryConstraint' + # We set the property sheet on the portal type + ti = self.getTypesTool().getTypeInfo(portal_type_name) + ti.property_sheet_list = list(ti.property_sheet_list) +\ + [property_sheet_name] + # reset aq_dynamic cache + _aq_reset() + + try: + inventory_module = portal.getDefaultModule(portal_type='Inventory') + inventory = inventory_module.newContent(portal_type='Inventory') + date = self.DUPLICATE_INVENTORY_DATE + inventory.edit(destination_value=self.node, + destination_section_value=self.section, + start_date=date) + inventory_line = inventory.newContent( + resource_value = self.resource, + quantity = 1) + self.workflow_tool = portal.portal_workflow + workflow_id = 'inventory_workflow' + transition_id = 'deliver_action' + workflow_id= 'inventory_workflow' + self.workflow_tool.doActionFor(inventory, transition_id, + wf_id=workflow_id) + self.assertEquals('delivered', inventory.getSimulationState()) + get_transaction().commit() + self.tic() + + # We should detect the previous inventory and fails + new_inventory = inventory.Base_createCloneDocument(batch_mode=1) + self.assertRaises(ValidationFailed, self.workflow_tool.doActionFor, + new_inventory, transition_id, wf_id=workflow_id) + workflow_history = self.workflow_tool.getInfoFor(ob=new_inventory, + name='history', wf_id=workflow_id) + workflow_error_message = str(workflow_history[-1]['error_message']) + self.assertTrue(workflow_error_message.find('There is already an inventory')>=0) + + # Add a case in order to check a bug when the other inventory at the + # same date does not change stock values + new_inventory = inventory.Base_createCloneDocument(batch_mode=1) + new_inventory.setStartDate(self.DUPLICATE_INVENTORY_DATE + 1) + self.workflow_tool.doActionFor(new_inventory, transition_id, + wf_id=workflow_id) + self.assertEquals('delivered', new_inventory.getSimulationState()) + get_transaction().commit() + self.tic() + + new_inventory = new_inventory.Base_createCloneDocument(batch_mode=1) + self.assertRaises(ValidationFailed, self.workflow_tool.doActionFor, + new_inventory, transition_id, wf_id=workflow_id) + workflow_history = self.workflow_tool.getInfoFor(ob=new_inventory, + name='history', wf_id=workflow_id) + workflow_error_message = str(workflow_history[-1]['error_message']) + self.assertTrue(workflow_error_message.find('There is already an inventory')>=0) + finally: + # remove all property sheet we added to type informations + ttool = self.getTypesTool() + ti = ttool.getTypeInfo(portal_type_name) + ps_list = ti.property_sheet_list + psheet_list = [property_sheet_name] + for psheet in psheet_list: + if psheet in ps_list: + ps_list.remove(psheet) + ti.property_sheet_list = ps_list + get_transaction().commit() + _aq_reset() + def test_suite(): suite = unittest.TestSuite()