Commit c5822540 authored by Julien Muchembled's avatar Julien Muchembled

Move legacy MRP code from erp5_mrp to new erp5_mrp_simulation_legacy

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39233 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1493f2e0
......@@ -68,28 +68,4 @@
<portal_type id="Supply Chain Module">
<item>Supply Chain</item>
</portal_type>
<portal_type id="Transformation Model Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
<portal_type id="Transformation Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
<portal_type id="Transformation Sourcing Model Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
<portal_type id="Transformation Sourcing Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
</allowed_content_type_list>
\ No newline at end of file
......@@ -63,20 +63,4 @@
<type>Supply Node</type>
<workflow>edit_workflow</workflow>
</chain>
<chain>
<type>Transformation Model Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
<chain>
<type>Transformation Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
<chain>
<type>Transformation Sourcing Model Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
<chain>
<type>Transformation Sourcing Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
</workflow_chain>
\ No newline at end of file
......@@ -40,8 +40,4 @@ Supply Chain Module | view
Supply Chain | view
Supply Chain | view_supply_node
Supply Link | view
Supply Node | view
Transformation Model Rule | view
Transformation Rule | view
Transformation Sourcing Model Rule | view
Transformation Sourcing Rule | view
\ No newline at end of file
Supply Node | view
\ No newline at end of file
......@@ -2,20 +2,4 @@ portal_deliveries/production_packing_list_builder
portal_deliveries/production_packing_list_builder/**
portal_deliveries/production_report_builder
portal_deliveries/production_report_builder/**
portal_domains/production_order_module_specialise_domain
portal_rules/default_production_order_model_root_simulation_rule
portal_rules/default_production_order_model_root_simulation_rule/**
portal_rules/default_production_order_model_rule
portal_rules/default_production_order_model_rule/**
portal_rules/default_production_order_root_simulation_rule
portal_rules/default_production_order_root_simulation_rule/**
portal_rules/default_production_order_rule
portal_rules/default_production_order_rule/**
portal_rules/default_transformation_model_rule
portal_rules/default_transformation_model_rule/**
portal_rules/default_transformation_rule
portal_rules/default_transformation_rule/**
portal_rules/default_transformation_sourcing_model_rule
portal_rules/default_transformation_sourcing_model_rule/**
portal_rules/default_transformation_sourcing_rule
portal_rules/default_transformation_sourcing_rule/**
\ No newline at end of file
portal_domains/production_order_module_specialise_domain
\ No newline at end of file
......@@ -34,20 +34,4 @@ Rule Tool | Transformation Sourcing Model Rule
Rule Tool | Transformation Sourcing Rule
Supply Chain Module | Supply Chain
Supply Chain | Supply Link
Supply Chain | Supply Node
Transformation Model Rule | Category Divergence Tester
Transformation Model Rule | Composed Divergence Tester
Transformation Model Rule | Property Divergence Tester
Transformation Model Rule | Quantity Divergence Tester
Transformation Rule | Category Divergence Tester
Transformation Rule | Composed Divergence Tester
Transformation Rule | Property Divergence Tester
Transformation Rule | Quantity Divergence Tester
Transformation Sourcing Model Rule | Category Divergence Tester
Transformation Sourcing Model Rule | Composed Divergence Tester
Transformation Sourcing Model Rule | Property Divergence Tester
Transformation Sourcing Model Rule | Quantity Divergence Tester
Transformation Sourcing Rule | Category Divergence Tester
Transformation Sourcing Rule | Composed Divergence Tester
Transformation Sourcing Rule | Property Divergence Tester
Transformation Sourcing Rule | Quantity Divergence Tester
\ No newline at end of file
Supply Chain | Supply Node
\ No newline at end of file
......@@ -17,8 +17,4 @@ Production Report Module
Supply Chain
Supply Chain Module
Supply Link
Supply Node
Transformation Model Rule
Transformation Rule
Transformation Sourcing Model Rule
Transformation Sourcing Rule
\ No newline at end of file
Supply Node
\ No newline at end of file
......@@ -44,12 +44,4 @@ Production Report | production_packing_list_workflow
Supply Chain | edit_workflow
Supply Chain | validation_workflow
Supply Link | edit_workflow
Supply Node | edit_workflow
Transformation Model Rule | edit_workflow
Transformation Model Rule | rule_validation_workflow
Transformation Rule | edit_workflow
Transformation Rule | rule_validation_workflow
Transformation Sourcing Model Rule | edit_workflow
Transformation Sourcing Model Rule | rule_validation_workflow
Transformation Sourcing Rule | edit_workflow
Transformation Sourcing Rule | rule_validation_workflow
\ No newline at end of file
Supply Node | edit_workflow
\ No newline at end of file
<allowed_content_type_list>
<portal_type id="Transformation Model Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
<portal_type id="Transformation Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
<portal_type id="Transformation Sourcing Model Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
<portal_type id="Transformation Sourcing Rule">
<item>Category Divergence Tester</item>
<item>Composed Divergence Tester</item>
<item>Property Divergence Tester</item>
<item>Quantity Divergence Tester</item>
</portal_type>
</allowed_content_type_list>
\ No newline at end of file
<workflow_chain>
<chain>
<type>Transformation Model Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
<chain>
<type>Transformation Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
<chain>
<type>Transformation Sourcing Model Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
<chain>
<type>Transformation Sourcing Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
</chain>
</workflow_chain>
\ No newline at end of file
Copyright (c) 2010 Nexedi SA
\ No newline at end of file
erp5_simulation_legacy
erp5_mrp
\ No newline at end of file
GPL
\ No newline at end of file
Transformation Model Rule | view
Transformation Rule | view
Transformation Sourcing Model Rule | view
Transformation Sourcing Rule | view
\ No newline at end of file
portal_rules/default_production_order_model_root_simulation_rule
portal_rules/default_production_order_model_root_simulation_rule/**
portal_rules/default_production_order_model_rule
portal_rules/default_production_order_model_rule/**
portal_rules/default_production_order_root_simulation_rule
portal_rules/default_production_order_root_simulation_rule/**
portal_rules/default_production_order_rule
portal_rules/default_production_order_rule/**
portal_rules/default_transformation_model_rule
portal_rules/default_transformation_model_rule/**
portal_rules/default_transformation_rule
portal_rules/default_transformation_rule/**
portal_rules/default_transformation_sourcing_model_rule
portal_rules/default_transformation_sourcing_model_rule/**
portal_rules/default_transformation_sourcing_rule
portal_rules/default_transformation_sourcing_rule/**
\ No newline at end of file
Transformation Model Rule | Category Divergence Tester
Transformation Model Rule | Composed Divergence Tester
Transformation Model Rule | Property Divergence Tester
Transformation Model Rule | Quantity Divergence Tester
Transformation Rule | Category Divergence Tester
Transformation Rule | Composed Divergence Tester
Transformation Rule | Property Divergence Tester
Transformation Rule | Quantity Divergence Tester
Transformation Sourcing Model Rule | Category Divergence Tester
Transformation Sourcing Model Rule | Composed Divergence Tester
Transformation Sourcing Model Rule | Property Divergence Tester
Transformation Sourcing Model Rule | Quantity Divergence Tester
Transformation Sourcing Rule | Category Divergence Tester
Transformation Sourcing Rule | Composed Divergence Tester
Transformation Sourcing Rule | Property Divergence Tester
Transformation Sourcing Rule | Quantity Divergence Tester
\ No newline at end of file
Transformation Model Rule
Transformation Rule
Transformation Sourcing Model Rule
Transformation Sourcing Rule
\ No newline at end of file
Transformation Model Rule | edit_workflow
Transformation Model Rule | rule_validation_workflow
Transformation Rule | edit_workflow
Transformation Rule | rule_validation_workflow
Transformation Sourcing Model Rule | edit_workflow
Transformation Sourcing Model Rule | rule_validation_workflow
Transformation Sourcing Rule | edit_workflow
Transformation Sourcing Rule | rule_validation_workflow
\ No newline at end of file
erp5_mrp_simulation_legacy
\ No newline at end of file
0.1
\ No newline at end of file
......@@ -7,6 +7,8 @@ InvoiceSimulationRule
InvoiceTransactionSimulationRule
OrderRootSimulationRule
PaymentSimulationRule
ProductionOrderModelRootSimulationRule
ProductionOrderRootSimulationRule
RootAppliedRuleCausalityMovementGroup
SimulationLegacyPatches
TradeModelSimulationRule
......
......@@ -46,6 +46,8 @@ class TestBPMMixin(ERP5TypeTestCase):
business_process_portal_type = 'Business Process'
business_link_portal_type = 'Business Link'
trade_model_path_portal_type = 'Trade Model Path'
default_business_process = \
'business_process_module/erp5_default_business_process'
normal_resource_use_category_list = ['normal']
invoicing_resource_use_category_list = ['discount', 'tax']
......@@ -77,7 +79,7 @@ class TestBPMMixin(ERP5TypeTestCase):
portal_type=self.business_process_portal_type,)
business_process = module.newContent(
portal_type=self.business_process_portal_type,
specialise_value=module.erp5_default_business_process)
specialise=self.default_business_process)
business_process._edit(**kw)
self.createTradeModelPath(business_process,
reference='default_path',
......
......@@ -59,6 +59,10 @@ class TestMRPMixin(TestBPMMixin):
if rule.getValidationState() == 'validated':
rule.invalidate()
def getRule(self, **kw):
return self.portal.portal_rules.searchFolder(
sort_on='version', sort_order='descending', **kw)[0].getObject()
def _createDocument(self, portal_type, **kw):
module = self.portal.getDefaultModule(
portal_type=portal_type)
......@@ -99,6 +103,8 @@ class TestMRPMixin(TestBPMMixin):
self.createCategoriesInCategory(category_tool.trade_phase, ['mrp',])
self.createCategoriesInCategory(category_tool.trade_phase.mrp,
['p' + str(i) for i in range(5)]) # phase0 ~ 4
self.createCategoriesInCategory(category_tool.trade_state,
('ready', 'partial', 'done'))
@reindex
def createDefaultOrder(self, transformation=None, business_process=None):
......@@ -157,41 +163,34 @@ class TestMRPMixin(TestBPMMixin):
""" mrp/p2 mrp/3
ready -------- partial_produced ------- done
"""
business_process = self.createBusinessProcess()
business_link_p2 = self.createBusinessLink(business_process)
business_link_p3 = self.createBusinessLink(business_process)
business_state_ready = self.createBusinessState(business_process)
business_state_partial = self.createBusinessState(business_process)
business_state_done = self.createBusinessState(business_process)
# organisations
source_section = self.createOrganisation(title='source_section')
source = self.createOrganisation(title='source')
destination_section = self.createOrganisation(title='destination_section')
destination = self.createOrganisation(title='destination')
business_process.edit(referential_date='stop_date')
business_link_p2.edit(id='p2',
predecessor_value=business_state_ready,
successor_value=business_state_partial,
quantity=1,
trade_phase=['mrp/p2'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
business_link_p3.edit(id='p3',
predecessor_value=business_state_partial,
successor_value=business_state_done,
quantity=1,
deliverable=1, # root explanation
trade_phase=['mrp/p3'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
business_process = self.createBusinessProcess(referential_date='stop_date')
self.createBusinessLink(business_process,
id='p2',
predecessor='trade_state/ready',
successor='trade_state/partial',
quantity=1,
trade_phase=['mrp/p2'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination)
self.createBusinessLink(business_process,
id='p3',
predecessor='trade_state/partial',
successor='trade_state/done',
quantity=1,
deliverable=1, # root explanation
trade_phase=['mrp/p3'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination)
return business_process
@reindex
......@@ -200,62 +199,43 @@ class TestMRPMixin(TestBPMMixin):
ready ======== partial_produced
mrp/p3
"""
business_process = self.createBusinessProcess()
business_link_p2 = self.createBusinessLink(business_process)
business_link_p3 = self.createBusinessLink(business_process)
business_state_ready = self.createBusinessState(business_process)
business_state_partial = self.createBusinessState(business_process)
# organisations
source_section = self.createOrganisation(title='source_section')
source = self.createOrganisation(title='source')
destination_section = self.createOrganisation(title='destination_section')
destination = self.createOrganisation(title='destination')
business_process.edit(referential_date='stop_date')
business_link_p2.edit(id='p2',
predecessor_value=business_state_ready,
successor_value=business_state_partial,
quantity=1,
trade_phase=['mrp/p2'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
business_link_p3.edit(id='p3',
predecessor_value=business_state_ready,
successor_value=business_state_partial,
quantity=1,
deliverable=1, # root explanation
trade_phase=['mrp/p3'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
business_process = self.createBusinessProcess(referential_date='stop_date')
self.createBusinessLink(business_process,
id='p2',
predecessor='trade_state/ready',
successor='trade_state/partial',
quantity=1,
trade_phase=['mrp/p2'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination)
self.createBusinessLink(business_process,
id='p3',
predecessor='trade_state/ready',
successor='trade_state/partial',
quantity=1,
deliverable=1, # root explanation
trade_phase=['mrp/p3'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination)
return business_process
@reindex
def beforeTearDown(self):
super(TestMRPMixin, self).beforeTearDown()
transaction.abort()
for module in (
self.portal.organisation_module,
self.portal.production_order_module,
self.portal.transformation_module,
self.portal.business_process_module,
# don't remove document because reuse it for testing of id
# self.portal.product_module,
self.portal.portal_simulation,):
module.manage_delObjects(list(module.objectIds()))
transaction.commit()
class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
class TestMRPImplementation(TestMRPMixin):
"""the test for implementation"""
@skip('Unfinished experimental feature')
def test_TransformationRule_getHeadProductionPathList(self):
rule = self.portal.portal_rules.default_transformation_model_rule
rule = self.getRule(reference='default_transformation_model_rule')
transformation = self.createDefaultTransformation()
......@@ -279,8 +259,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
path_p3 = '%s/p3' % business_process.getRelativeUrl()
# organisations
path = business_process.objectValues(
portal_type=self.portal.getPortalBusinessLinkTypeList())[0]
path = business_process.p2
source_section = path.getSourceSection()
source = path.getSource()
destination_section = path.getDestinationSection()
......@@ -304,7 +283,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
# test mock
applied_rule = movement.newContent(potal_type='Applied Rule')
rule = self.portal.portal_rules.default_transformation_model_rule
rule = self.getRule(reference='default_transformation_model_rule')
rule.expand(applied_rule)
# assertion
......@@ -343,8 +322,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
phase_p3 = '%s/p3' % business_process.getRelativeUrl()
# organisations
path = business_process.objectValues(
portal_type=self.portal.getPortalBusinessLinkTypeList())[0]
path = business_process.p2
source_section = path.getSourceSection()
source = path.getSource()
destination_section = path.getDestinationSection()
......@@ -369,7 +347,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
# test mock
applied_rule = movement.newContent(potal_type='Applied Rule')
rule = self.portal.portal_rules.default_transformation_model_rule
rule = self.getRule(reference='default_transformation_model_rule')
rule.expand(applied_rule)
# assertion
......@@ -412,8 +390,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
phase_p3 = '%s/p3' % business_process.getRelativeUrl()
# organisations
path = business_process.objectValues(
portal_type=self.portal.getPortalBusinessLinkTypeList())[0]
path = business_process.p2
source_section = path.getSourceSection()
source = path.getSource()
destination_section = path.getDestinationSection()
......@@ -431,7 +408,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
movement._baseSetFrozen(1)
# re-expand
rule = self.portal.portal_rules.default_transformation_model_rule
rule = self.getRule(reference='default_transformation_model_rule')
rule.expand(applied_rule)
# assertion
......@@ -510,7 +487,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
# test mock
applied_rule = movement.newContent(potal_type='Applied Rule')
rule = self.portal.portal_rules.default_transformation_sourcing_model_rule
rule = self.getRule(reference='default_transformation_sourcing_model_rule')
rule.expand(applied_rule)
# assertion
......
......@@ -30,11 +30,12 @@ def Legacy_getBusinessTemplateList(cls):
def Legacy_getBusinessTemplateList(self):
bt_list = []
for bt in getBusinessTemplateList(self):
if bt != 'erp5_simulation_test':
if bt != 'erp5_simulation_test' and bt not in bt_list:
bt_list.append(bt)
if bt == 'erp5_simulation':
bt_list.append(bt + '_legacy')
elif bt in ('erp5_accounting', 'erp5_trade', 'erp5_project'):
elif bt in ('erp5_accounting', 'erp5_mrp',
'erp5_project', 'erp5_trade'):
bt_list.append(bt + '_simulation_legacy')
return tuple(bt_list)
cls.getBusinessTemplateList = Legacy_getBusinessTemplateList
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
# Yusuke Muraoka <yusuke@nexedi.com>
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Julien Muchembled <jm@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
......@@ -22,515 +22,26 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import unittest
import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.tests.utils import reindex
from Products.ERP5Legacy.tests.testLegacyBPMCore import TestBPMMixin
from Products.ERP5Type.tests.backportUnittest import skip
class TestMRPMixin(TestBPMMixin):
transformation_portal_type = 'Transformation'
transformed_resource_portal_type = 'Transformation Transformed Resource'
product_portal_type = 'Product'
organisation_portal_type = 'Organisation'
order_portal_type = 'Production Order'
order_line_portal_type = 'Production Order Line'
def getBusinessTemplateList(self):
return TestBPMMixin.getBusinessTemplateList(self) + ('erp5_mrp', )
def invalidateRules(self):
"""
do reversely of validateRules
"""
rule_tool = self.getRuleTool()
for rule in rule_tool.contentValues(
portal_type=rule_tool.getPortalRuleTypeList()):
if rule.getValidationState() == 'validated':
rule.invalidate()
def _createDocument(self, portal_type, **kw):
module = self.portal.getDefaultModule(
portal_type=portal_type)
return self._createObject(module, portal_type, **kw)
def _createObject(self, parent, portal_type, id=None, **kw):
o = None
if id is not None:
o = parent.get(str(id), None)
if o is None:
o = parent.newContent(portal_type=portal_type)
o.edit(**kw)
return o
def createTransformation(self, **kw):
return self._createDocument(self.transformation_portal_type, **kw)
def createProduct(self, **kw):
return self._createDocument(self.product_portal_type, **kw)
def createOrganisation(self, **kw):
return self._createDocument(self.organisation_portal_type, **kw)
def createOrder(self, **kw):
return self._createDocument(self.order_portal_type, **kw)
def createOrderLine(self, order, **kw):
return self._createObject(order, self.order_line_portal_type, **kw)
def createTransformedResource(self, transformation, **kw):
return self._createObject(transformation, self.transformed_resource_portal_type, **kw)
@reindex
def createCategories(self):
category_tool = getToolByName(self.portal, 'portal_categories')
self.createCategoriesInCategory(category_tool.base_amount, ['weight'])
self.createCategoriesInCategory(category_tool.base_amount.weight, ['kg'])
self.createCategoriesInCategory(category_tool.trade_phase, ['mrp',])
self.createCategoriesInCategory(category_tool.trade_phase.mrp,
['p' + str(i) for i in range(5)]) # phase0 ~ 4
@reindex
def createDefaultOrder(self, transformation=None, business_process=None):
if transformation is None:
transformation = self.createDefaultTransformation()
if business_process is None:
business_process = self.createSimpleBusinessProcess()
base_date = DateTime()
order = self.createOrder(specialise_value=business_process,
start_date=base_date,
stop_date=base_date+3)
order_line = self.createOrderLine(order,
quantity=10,
resource=transformation.getResource(),
specialise_value=transformation)
# XXX in some case, specialise_value is not related to order_line by edit,
# but by setSpecialise() is ok, Why?
order_line.setSpecialiseValue(transformation)
return order
@reindex
def createDefaultTransformation(self):
resource1 = self.createProduct(id='1', quantity_unit_list=['weight/kg'])
resource2 = self.createProduct(id='2', quantity_unit_list=['weight/kg'])
resource3 = self.createProduct(id='3', quantity_unit_list=['weight/kg'])
resource4 = self.createProduct(id='4', quantity_unit_list=['weight/kg'])
resource5 = self.createProduct(id='5', quantity_unit_list=['weight/kg'])
transformation = self.createTransformation(resource_value=resource5)
self.createTransformedResource(transformation=transformation,
resource_value=resource1,
quantity=3,
quantity_unit_list=['weight/kg'],
trade_phase='mrp/p2')
self.createTransformedResource(transformation=transformation,
resource_value=resource2,
quantity=1,
quantity_unit_list=['weight/kg'],
trade_phase='mrp/p2')
self.createTransformedResource(transformation=transformation,
resource_value=resource3,
quantity=4,
quantity_unit_list=['weight/kg'],
trade_phase='mrp/p3')
self.createTransformedResource(transformation=transformation,
resource_value=resource4,
quantity=1,
quantity_unit_list=['weight/kg'],
trade_phase='mrp/p3')
return transformation
@reindex
def createSimpleBusinessProcess(self):
""" mrp/p2 mrp/3
ready -------- partial_produced ------- done
"""
business_process = self.createBusinessProcess()
business_path_p2 = self.createBusinessPath(business_process)
business_path_p3 = self.createBusinessPath(business_process)
business_state_ready = self.createBusinessState(business_process)
business_state_partial = self.createBusinessState(business_process)
business_state_done = self.createBusinessState(business_process)
# organisations
source_section = self.createOrganisation(title='source_section')
source = self.createOrganisation(title='source')
destination_section = self.createOrganisation(title='destination_section')
destination = self.createOrganisation(title='destination')
business_process.edit(referential_date='stop_date')
business_path_p2.edit(id='p2',
predecessor_value=business_state_ready,
successor_value=business_state_partial,
quantity=1,
trade_phase=['mrp/p2'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
business_path_p3.edit(id='p3',
predecessor_value=business_state_partial,
successor_value=business_state_done,
quantity=1,
deliverable=1, # root explanation
trade_phase=['mrp/p3'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
return business_process
@reindex
def createConcurrentBusinessProcess(self):
""" mrp/p2
ready ======== partial_produced
mrp/p3
"""
business_process = self.createBusinessProcess()
business_path_p2 = self.createBusinessPath(business_process)
business_path_p3 = self.createBusinessPath(business_process)
business_state_ready = self.createBusinessState(business_process)
business_state_partial = self.createBusinessState(business_process)
# organisations
source_section = self.createOrganisation(title='source_section')
source = self.createOrganisation(title='source')
destination_section = self.createOrganisation(title='destination_section')
destination = self.createOrganisation(title='destination')
business_process.edit(referential_date='stop_date')
business_path_p2.edit(id='p2',
predecessor_value=business_state_ready,
successor_value=business_state_partial,
quantity=1,
trade_phase=['mrp/p2'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
business_path_p3.edit(id='p3',
predecessor_value=business_state_ready,
successor_value=business_state_partial,
quantity=1,
deliverable=1, # root explanation
trade_phase=['mrp/p3'],
source_section_value=source_section,
source_value=source,
destination_section_value=destination_section,
destination_value=destination,
)
return business_process
@reindex
def beforeTearDown(self):
super(TestMRPMixin, self).beforeTearDown()
transaction.abort()
for module in (
self.portal.organisation_module,
self.portal.production_order_module,
self.portal.transformation_module,
self.portal.business_process_module,
# don't remove document because reuse it for testing of id
# self.portal.product_module,
self.portal.portal_simulation,):
module.manage_delObjects(list(module.objectIds()))
transaction.commit()
class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase):
"""the test for implementation"""
@skip('Unfinished experimental feature')
def test_TransformationRule_getHeadProductionPathList(self):
rule = self.portal.portal_rules.default_transformation_model_rule
transformation = self.createDefaultTransformation()
business_process = self.createSimpleBusinessProcess()
self.assertEquals([business_process.p2],
rule.getHeadProductionPathList(transformation, business_process))
business_process = self.createConcurrentBusinessProcess()
self.assertEquals(set([business_process.p2, business_process.p3]),
set(rule.getHeadProductionPathList(transformation, business_process)))
def test_TransformationRule_expand(self):
# mock order
order = self.createDefaultOrder()
order_line = order.objectValues()[0]
business_process = order.getSpecialiseValue()
# paths
path_p2 = '%s/p2' % business_process.getRelativeUrl()
path_p3 = '%s/p3' % business_process.getRelativeUrl()
# organisations
path = business_process.objectValues(
portal_type=self.portal.getPortalBusinessPathTypeList())[0]
source_section = path.getSourceSection()
source = path.getSource()
destination_section = path.getDestinationSection()
destination = path.getDestination()
consumed_organisations = (source_section, source, destination_section, None)
produced_organisations = (source_section, None, destination_section, destination)
# don't need another rules, just need TransformationRule for test
self.invalidateRules()
self.stepTic()
# alter simulations of the order
# root
applied_rule = self.portal.portal_simulation.newContent(portal_type='Applied Rule')
movement = applied_rule.newContent(portal_type='Simulation Movement')
applied_rule.edit(causality_value=order)
movement.edit(order_value=order_line,
quantity=order_line.getQuantity(),
resource=order_line.getResource())
# test mock
applied_rule = movement.newContent(potal_type='Applied Rule')
rule = self.portal.portal_rules.default_transformation_model_rule
rule.expand(applied_rule)
# assertion
expected_value_set = set([
((path_p2,), 'product_module/5', produced_organisations, 'mrp/p3', -10),
((path_p2,), 'product_module/1', consumed_organisations, 'mrp/p2', 30),
((path_p2,), 'product_module/2', consumed_organisations, 'mrp/p2', 10),
((path_p3,), 'product_module/5', consumed_organisations, 'mrp/p3', 10),
((path_p3,), 'product_module/3', consumed_organisations, 'mrp/p3', 40),
((path_p3,), 'product_module/4', consumed_organisations, 'mrp/p3', 10),
((path_p3,), 'product_module/5', produced_organisations, None, -10)])
movement_list = applied_rule.objectValues()
self.assertEquals(len(expected_value_set), len(movement_list))
movement_value_set = set([])
for movement in movement_list:
movement_value_set |= set([(tuple(movement.getCausalityList()),
movement.getResource(),
(movement.getSourceSection(),
movement.getSource(),
movement.getDestinationSection(),
movement.getDestination(),), # organisations
movement.getTradePhase(),
movement.getQuantity())])
self.assertEquals(expected_value_set, movement_value_set)
@skip('Unfinished experimental feature')
def test_TransformationRule_expand_concurrent(self):
business_process = self.createConcurrentBusinessProcess()
# mock order
order = self.createDefaultOrder(business_process=business_process)
order_line = order.objectValues()[0]
# phases
phase_p2 = '%s/p2' % business_process.getRelativeUrl()
phase_p3 = '%s/p3' % business_process.getRelativeUrl()
# organisations
path = business_process.objectValues(
portal_type=self.portal.getPortalBusinessPathTypeList())[0]
source_section = path.getSourceSection()
source = path.getSource()
destination_section = path.getDestinationSection()
destination = path.getDestination()
organisations = (source_section, source, destination_section, destination)
consumed_organisations = (source_section, source, destination_section, None)
produced_organisations = (source_section, None, destination_section, destination)
# don't need another rules, just need TransformationRule for test
self.invalidateRules()
self.stepTic()
# alter simulations of the order
# root
applied_rule = self.portal.portal_simulation.newContent(portal_type='Applied Rule')
movement = applied_rule.newContent(portal_type='Simulation Movement')
applied_rule.edit(causality_value=order)
movement.edit(order_value=order_line,
quantity=order_line.getQuantity(),
resource=order_line.getResource())
# test mock
applied_rule = movement.newContent(potal_type='Applied Rule')
rule = self.portal.portal_rules.default_transformation_model_rule
rule.expand(applied_rule)
# assertion
expected_value_set = set([
((phase_p2,), 'product_module/1', consumed_organisations, 'mrp/p2', 30),
((phase_p2,), 'product_module/2', consumed_organisations, 'mrp/p2', 10),
((phase_p3,), 'product_module/3', consumed_organisations, 'mrp/p3', 40),
((phase_p3,), 'product_module/4', consumed_organisations, 'mrp/p3', 10),
((phase_p2, phase_p3), 'product_module/5', produced_organisations, None, -10)])
movement_list = applied_rule.objectValues()
self.assertEquals(len(expected_value_set), len(movement_list))
movement_value_set = set([])
for movement in movement_list:
movement_value_set |= set([(tuple(movement.getCausalityList()),
movement.getResource(),
(movement.getSourceSection(),
movement.getSource(),
movement.getDestinationSection(),
movement.getDestination(),), # organisations
movement.getTradePhase(),
movement.getQuantity())])
self.assertEquals(expected_value_set, movement_value_set)
@skip('Unfinished experimental feature')
def test_TransformationRule_expand_reexpand(self):
"""
test case of difference when any movement are frozen
by using above result
"""
self.test_TransformationRule_expand_concurrent()
self.stepTic()
applied_rule = self.portal.portal_simulation.objectValues()[0]
business_process = applied_rule.getCausalityValue().getSpecialiseValue()
# phases
phase_p2 = '%s/p2' % business_process.getRelativeUrl()
phase_p3 = '%s/p3' % business_process.getRelativeUrl()
# organisations
path = business_process.objectValues(
portal_type=self.portal.getPortalBusinessPathTypeList())[0]
source_section = path.getSourceSection()
source = path.getSource()
destination_section = path.getDestinationSection()
destination = path.getDestination()
consumed_organisations = (source_section, source, destination_section, None)
produced_organisations = (source_section, None, destination_section, destination)
movement = applied_rule.objectValues()[0]
applied_rule = movement.objectValues()[0]
# these movements are made by transformation
for movement in applied_rule.objectValues():
movement.edit(quantity=1)
# set the state value of isFrozen to 1,
movement._baseSetFrozen(1)
# re-expand
rule = self.portal.portal_rules.default_transformation_model_rule
rule.expand(applied_rule)
# assertion
expected_value_set = set([
((phase_p2,), 'product_module/1', consumed_organisations, 'mrp/p2', 1), # Frozen
((phase_p2,), 'product_module/1', consumed_organisations, 'mrp/p2', 29),
((phase_p2,), 'product_module/2', consumed_organisations, 'mrp/p2', 1), # Frozen
((phase_p2,), 'product_module/2', consumed_organisations, 'mrp/p2', 9),
((phase_p3,), 'product_module/3', consumed_organisations, 'mrp/p3', 1), # Frozen
((phase_p3,), 'product_module/3', consumed_organisations, 'mrp/p3', 39),
((phase_p3,), 'product_module/4', consumed_organisations, 'mrp/p3', 1), # Frozen
((phase_p3,), 'product_module/4', consumed_organisations, 'mrp/p3', 9),
((phase_p2, phase_p3), 'product_module/5', produced_organisations, None, 1), # Frozen
((phase_p2, phase_p3), 'product_module/5', produced_organisations, None, -11)])
movement_list = applied_rule.objectValues()
self.assertEquals(len(expected_value_set), len(movement_list))
movement_value_set = set([])
for movement in movement_list:
movement_value_set |= set([(tuple(movement.getCausalityList()),
movement.getResource(),
(movement.getSourceSection(),
movement.getSource(),
movement.getDestinationSection(),
movement.getDestination(),), # organisations
movement.getTradePhase(),
movement.getQuantity())])
self.assertEquals(expected_value_set, movement_value_set)
@skip('Unfinished experimental feature')
def test_TransformationSourcingRule_expand(self):
# mock order
order = self.createDefaultOrder()
order_line = order.objectValues()[0]
# don't need another rules, just need TransformationSourcingRule for test
self.invalidateRules()
self.stepTic()
business_process = order.getSpecialiseValue()
# get last path of a business process
# in simple business path, the last is between "partial_produced" and "done"
causality_path = None
for state in business_process.objectValues(
portal_type=self.portal.getPortalBusinessStateTypeList()):
if len(state.getRemainingTradePhaseList(self.portal)) == 0:
causality_path = state.getSuccessorRelatedValue()
# phases
phase_p2 = '%s/p2' % business_process.getRelativeUrl()
# organisations
source_section = causality_path.getSourceSection()
source = causality_path.getSource()
destination_section = causality_path.getDestinationSection()
destination = causality_path.getDestination()
organisations = (source_section, source, destination_section, destination)
# sourcing resource
sourcing_resource = order_line.getResource()
# alter simulations of the order
# root
applied_rule = self.portal.portal_simulation.newContent(portal_type='Applied Rule')
movement = applied_rule.newContent(portal_type='Simulation Movement')
applied_rule.edit(causality_value=order)
movement.edit(order_value=order_line,
causality_value=causality_path,
quantity=order_line.getQuantity(),
resource=sourcing_resource,
)
self.stepTic()
# test mock
applied_rule = movement.newContent(potal_type='Applied Rule')
rule = self.portal.portal_rules.default_transformation_sourcing_model_rule
rule.expand(applied_rule)
# assertion
expected_value_set = set([
((phase_p2,), sourcing_resource, organisations, 10)])
movement_list = applied_rule.objectValues()
self.assertEquals(len(expected_value_set), len(movement_list))
movement_value_set = set([])
for movement in movement_list:
movement_value_set |= set([(tuple(movement.getCausalityList()),
movement.getResource(),
(movement.getSourceSection(),
movement.getSource(),
movement.getDestinationSection(),
movement.getDestination(),), # organisations
movement.getQuantity())])
self.assertEquals(expected_value_set, movement_value_set)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMRPImplementation))
return suite
import sys
from Products.ERP5Legacy.tests import testLegacyBPMCore
sys.modules['Products.ERP5.tests.testBPMCore'] = testLegacyBPMCore
from Products.ERP5.tests.testMRP import *
from Products.ERP5Legacy.tests import Legacy_getBusinessTemplateList
Legacy_getBusinessTemplateList(TestMRPMixin)
def createBusinessLink(self, business_process, **kw):
for x in 'predecessor', 'successor':
state_id = kw.pop(x).replace('/', '-')
try:
state = business_process[state_id]
except KeyError:
state = business_process.newContent(state_id, 'Business State')
kw[x + '_value'] = state
return business_process.newContent(portal_type='Business Path', **kw)
TestMRPMixin.createBusinessLink = createBusinessLink
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