Commit ee5141a3 authored by Julien Muchembled's avatar Julien Muchembled

Fix testInventoryAPI

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@38564 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 712142b9
......@@ -2,6 +2,9 @@
<portal_type id="Component">
<item>DefaultImage</item>
</portal_type>
<portal_type id="Measure Cell">
<item>Amount</item>
</portal_type>
<portal_type id="Product">
<item>DefaultImage</item>
</portal_type>
......
Component | DefaultImage
Measure Cell | Amount
Product | DefaultImage
Supply Cell | Reference
\ No newline at end of file
......@@ -65,6 +65,17 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi
PropertySheet.Rule
)
security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable')
def isAccountable(self, movement):
"""
Tells whether generated movement needs to be accounted or not.
Invoice movement are never accountable, so simulation movement for
invoice movements should not be accountable either.
"""
return False
def _getMovementGenerator(self, context):
"""
Return the movement generator to use in the expand process
......
......@@ -64,6 +64,17 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
PropertySheet.Rule
)
security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable')
def isAccountable(self, movement):
"""
Tells whether generated movement needs to be accounted or not.
Invoice movement are never accountable, so simulation movement for
invoice movements should not be accountable either.
"""
return False
def _getMovementGenerator(self, context):
"""
Return the movement generator to use in the expand process
......
......@@ -67,6 +67,16 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica
PropertySheet.Rule
)
security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable')
def isAccountable(self, movement):
"""Tells wether generated movement needs to be accounted or not.
Order movement are never accountable, so simulation movement for
order movements should not be accountable either.
"""
return False
def _getMovementGenerator(self, context):
"""
Return the movement generator to use in the expand process
......
......@@ -218,6 +218,16 @@ class RuleMixin:
for movement in applied_rule.getMovementList():
movement.expand(**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable')
def isAccountable(self, movement):
"""Tells wether generated movement needs to be accounted or not.
Only account movements which are not associated to a delivery;
Whenever delivery is there, delivery has priority
"""
return movement.getDeliveryValue() is None
# Implementation of IDivergenceController # XXX-JPS move to IDivergenceController only mixin for
security.declareProtected( Permissions.AccessContentsInformation,
'isDivergent')
......
......@@ -50,6 +50,7 @@ from Products.ERP5Type.Base import _aq_reset
class InventoryAPITestCase(ERP5TypeTestCase):
"""Base class for Inventory API Tests {{{
"""
business_process = 'business_process_module/erp5_default_business_process'
GROUP_CATEGORIES = ( 'group/test_group/A1/B1/C1',
'group/test_group/A1/B1/C2',
......@@ -122,36 +123,18 @@ class InventoryAPITestCase(ERP5TypeTestCase):
self.other_item = self.getItemModule().newContent(title='Other Item')
self.getInventory = self.getSimulationTool().getInventory
def _safeTic(self):
"""Like tic, but swallowing errors, usefull for teardown"""
try:
transaction.commit()
self.tic()
except RuntimeError:
pass
def beforeTearDown(self):
"""Clear everything for next test."""
self._safeTic()
for module in [ 'organisation_module',
'person_module',
'product_module',
'portal_simulation',
'inventory_module',
self.folder.getId() ]:
folder = getattr(self.getPortal(), module, None)
if folder:
[x.unindexObject() for x in folder.objectValues()]
self._safeTic()
folder.manage_delObjects([x.getId() for x in folder.objectValues()])
self._safeTic()
# cancel remaining messages
activity_tool = self.getPortal().portal_activities
for message in activity_tool.getMessageList():
activity_tool.manageCancel(message.object_path, message.method_id)
ZopeTestCase._print('\nCancelling active message %s.%s()\n'
% (message.object_path, message.method_id) )
folder = self.portal[module]
folder.manage_delObjects(list(folder.objectIds()))
transaction.commit()
self.tic()
def login(self, quiet=0, run=1):
uf = self.getPortal().acl_users
......@@ -202,6 +185,10 @@ class InventoryAPITestCase(ERP5TypeTestCase):
'erp5_trade', 'erp5_apparel', 'erp5_project',
'erp5_simulation_test')
def getRule(self, **kw):
return self.portal.portal_rules.searchFolder(
sort_on='version', sort_order='descending', **kw)[0].getObject()
# TODO: move this to a base class {{{
@reindex
def _makeOrganisation(self, **kw):
......@@ -214,27 +201,26 @@ class InventoryAPITestCase(ERP5TypeTestCase):
@reindex
def _makeProject(self, **kw):
"""Creates an project."""
prj = self.getPortal().project_module.newContent(
return self.portal.project_module.newContent(
portal_type='Project',
**kw)
return prj
@reindex
def _makeSalePackingList(self, **kw):
"""Creates a sale packing list."""
spl = self.getPortal().sale_packing_list_module.newContent(
portal_type='Sale Packing List',)
spl.edit(**kw)
return spl
return self.portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List',
specialise=self.business_process,
**kw)
@reindex
def _makeSaleInvoice(self, created_by_builder=0, **kw):
"""Creates a sale invoice."""
sit = self.getPortal().accounting_module.newContent(
return self.portal.accounting_module.newContent(
portal_type='Sale Invoice Transaction',
created_by_builder=created_by_builder)
sit.edit(**kw)
return sit
created_by_builder=created_by_builder,
specialise=self.business_process,
**kw)
@reindex
def _makeProduct(self, **kw):
......@@ -264,9 +250,8 @@ class InventoryAPITestCase(ERP5TypeTestCase):
def _makeSimulationMovement(self, **kw):
"""Creates a simulation movement.
"""
ar = self.getSimulationTool().newContent(portal_type='Applied Rule')
# we created a default_order_rule in setUp
ar.setSpecialise('portal_rules/default_order_rule')
ar = self.getSimulationTool().newContent(portal_type='Applied Rule',
specialise_value=self.getRule(reference='default_delivery_rule'))
mvt = ar.newContent(portal_type='Simulation Movement')
kw.setdefault('destination_section_value', self.section)
kw.setdefault('source_section_value', self.mirror_section)
......@@ -1165,7 +1150,6 @@ class TestInventoryList(InventoryAPITestCase):
price=m[3],
)
self._safeTic()
simulation_tool = self.getSimulationTool()
def valuate(method):
r = simulation_tool.getInventoryAssetPrice(
......@@ -1235,8 +1219,6 @@ class TestInventoryList(InventoryAPITestCase):
d = DateTime('%s/15 15:00 UTC' % month)
self._makeMovement(start_date=d, resource_uid=resource_uid, **mov)
self._safeTic()
# and check
for cur in sorted(data)[1:]:
# month+1
......@@ -2722,7 +2704,8 @@ class BaseTestUnitConversion(InventoryAPITestCase):
InventoryAPITestCase.afterSetUp(self)
self.setUpUnitDefinition()
self._safeTic()
transaction.commit()
self.tic()
@reindex
def makeMovement(self, quantity, resource, *variation, **kw):
......@@ -2812,7 +2795,8 @@ class TestUnitConversion(BaseTestUnitConversion):
m.newContent(portal_type='Measure Cell', quantity=quantity) \
._setMembershipCriterionCategory('colour/' + colour)
self._safeTic()
transaction.commit()
self.tic()
def testConvertedInventoryList(self):
self.makeMovement(2, self.resource, 'colour/green', 'size/big')
......@@ -2878,8 +2862,6 @@ class TestUnitConversionDefinition(BaseTestUnitConversion):
self.resource_byunit.setQuantityUnit('unit/unit')
self._safeTic()
base_unit = self.resource_bylot_overriding.newContent(
portal_type='Quantity Unit Conversion Group',
quantity_unit='unit/unit',)
......@@ -2893,7 +2875,8 @@ class TestUnitConversionDefinition(BaseTestUnitConversion):
quantity=1.0/50,)
unit.validate()
self._safeTic()
transaction.commit()
self.tic()
def beforeTearDown(self):
# invalidating definitions is enough
......@@ -3068,8 +3051,7 @@ class TestUnitConversionBackwardCompatibility(BaseTestUnitConversion):
self.portal.portal_caches.clearCache(('erp5_content_long',))
def testBackwardCompatibility(self):
delivery_rule = self.getRuleTool().default_delivery_rule
delivery_rule.validate()
self.getRule(reference='default_delivery_rule').validate()
resource = self.portal.product_module.newContent(
portal_type='Product',
......@@ -3079,6 +3061,7 @@ class TestUnitConversionBackwardCompatibility(BaseTestUnitConversion):
portal_type='Organisation')
delivery = self.portal.purchase_packing_list_module.newContent(
portal_type='Purchase Packing List',
specialise=self.business_process,
start_date='2010-01-26',
price_currency='currency_module/EUR',
destination_value=node,
......
......@@ -48,6 +48,17 @@ class OrderRule(DeliveryRule):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable')
def isAccountable(self, movement):
"""
Tells whether generated movement needs to be accounted or not.
Order movement are never accountable, so simulation movement for
order movements should not be accountable either.
"""
return 0
# Simulation workflow
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw):
......
# -*- coding: utf-8 -*-
##############################################################################
# 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
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from Products.ERP5Legacy.tests import Legacy_getBusinessTemplateList
from Products.ERP5.tests.testInventoryAPI import *
Legacy_getBusinessTemplateList(InventoryAPITestCase)
InventoryAPITestCase.business_process = None
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