Commit 7daf8995 authored by Julien Muchembled's avatar Julien Muchembled

UnrestrictedMethod: replace unefficient use of UnrestrictedMethod

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30413 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6248418d
......@@ -85,6 +85,7 @@ class AppliedRule(XMLObject):
return self.getSpecialiseValue().isAccountable(movement)
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
@UnrestrictedMethod
def expand(self, **kw):
"""
Expands the current movement downward.
......@@ -94,10 +95,6 @@ class AppliedRule(XMLObject):
An applied rule can be expanded only if its parent movement
is expanded.
"""
expand = UnrestrictedMethod(self._expand)
return expand(**kw)
def _expand(self, **kw):
tv = getTransactionalVariable(self)
cache = tv.setdefault(TREE_DELIVERED_CACHE_KEY, {})
cache_enabled = cache.get(TREE_DELIVERED_CACHE_ENABLED, 0)
......
......@@ -137,16 +137,12 @@ class BPMBuilder(Alarm):
if self.isAlarmNotificationMode():
self.activate(after_tag=tag).notify(include_active=True)
def searchMovementList(self, *args, **kw):
@UnrestrictedMethod
def searchMovementList(self, **kw):
"""
defines how to query all input movements which meet certain criteria
First, select movement matching to criteria define on Builder
"""
searchMovementList = UnrestrictedMethod(self._searchMovementList)
return searchMovementList(*args, **kw)
def _searchMovementList(self, **kw):
"""This method is wrapped by UnrestrictedMethod."""
input_movement_value_list = []
# We only search Simulation Movement - Luke do not know why...
kw['portal_type'] = 'Simulation Movement' # blah!
......@@ -305,16 +301,13 @@ class BPMBuilder(Alarm):
break
return instance, property_dict
def buildDeliveryList(self, *args, **kw):
@UnrestrictedMethod
def buildDeliveryList(self, movement_group_node,
delivery_relative_url_list=None,
movement_list=None, **kw):
"""
Build deliveries from a list of movements
"""
buildDeliveryList = UnrestrictedMethod(self._buildDeliveryList)
return buildDeliveryList(*args, **kw)
def _buildDeliveryList(self, movement_group_node, delivery_relative_url_list=None,
movement_list=None,**kw):
"""This method is wrapped by UnrestrictedMethod. XXX do docstring which have a sense"""
# Parameter initialization
if delivery_relative_url_list is None:
delivery_relative_url_list = []
......@@ -676,17 +669,10 @@ class BPMBuilder(Alarm):
update_existing_movement=update_existing_movement,
force_update=force_update, activate_kw=activate_kw)
def callAfterBuildingScript(self, *args, **kw):
"""
Call script on each delivery built.
"""
callAfterBuildingScript = UnrestrictedMethod(self._callAfterBuildingScript)
return callAfterBuildingScript(*args, **kw)
def _callAfterBuildingScript(self, delivery_list, movement_list=None, **kw):
@UnrestrictedMethod
def callAfterBuildingScript(self, delivery_list, movement_list=None, **kw):
"""
Call script on each delivery built.
This method is wrapped by UnrestrictedMethod.
"""
if not len(delivery_list):
return
......
......@@ -348,16 +348,13 @@ class Delivery(XMLObject, ImmobilisationDelivery):
divergence_list.extend(movement.getDivergenceList())
return divergence_list
@UnrestrictedMethod
def updateCausalityState(self, **kw):
"""
This is often called as an activity, it will check if the
deliver is convergent, and if so it will put the delivery
in a solved state, if not convergent in a diverged state
"""
updateCausalityState = UnrestrictedMethod(self._updateCausalityState)
return updateCausalityState(**kw)
def _updateCausalityState(self, **kw):
if getattr(self, 'diverge', None) is not None \
and getattr(self, 'converge', None) is not None:
if self.isDivergent(**kw):
......@@ -667,7 +664,9 @@ class Delivery(XMLObject, ImmobilisationDelivery):
##########################################################################
# Applied Rule stuff
def updateAppliedRule(self, *args, **kw):
@UnrestrictedMethod
def updateAppliedRule(self, rule_reference=None, rule_id=None, force=0,
**kw):
"""
Create a new Applied Rule if none is related, or call expand
on the existing one.
......@@ -675,11 +674,6 @@ class Delivery(XMLObject, ImmobilisationDelivery):
The chosen applied rule will be the validated rule with reference ==
rule_reference, and the higher version number.
"""
updateAppliedRule = UnrestrictedMethod(self._updateAppliedRule)
return updateAppliedRule(*args, **kw)
def _updateAppliedRule(self, rule_reference=None, rule_id=None, force=0,
**kw):
if rule_id is not None:
from warnings import warn
warn('rule_id to updateAppliedRule is deprecated; use rule_reference instead',
......@@ -752,16 +746,13 @@ class Delivery(XMLObject, ImmobilisationDelivery):
activate_kw=activate_kw, **kw)
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, *args,**kw):
@UnrestrictedMethod
def expand(self, applied_rule_id=None, force=0, activate_kw=None,**kw):
"""
Reexpand applied rule
Also reexpand all rules related to movements
"""
expand = UnrestrictedMethod(self._expand)
return expand(*args, **kw)
def _expand(self, applied_rule_id=None, force=0, activate_kw=None,**kw):
excluded_rule_path_list = []
if applied_rule_id is not None:
my_applied_rule = self.portal_simulation.get(applied_rule_id, None)
......
......@@ -98,7 +98,8 @@ class DeliveryBuilder(OrderBuilder):
"""
pass
def searchMovementList(self, *args, **kw):
@UnrestrictedMethod
def searchMovementList(self, applied_rule_uid=None, **kw):
"""
defines how to query all Simulation Movements which meet certain criteria
(including the above path path definition).
......@@ -106,11 +107,6 @@ class DeliveryBuilder(OrderBuilder):
First, select movement matching to criteria define on DeliveryBuilder
Then, call script simulation_select_method to restrict movement_list
"""
searchMovementList = UnrestrictedMethod(self._searchMovementList)
return searchMovementList(*args, **kw)
def _searchMovementList(self, applied_rule_uid=None,**kw):
"""This method is wrapped by UnrestrictedMethod."""
movement_list = []
# We only search Simulation Movement
kw['portal_type'] = 'Simulation Movement'
......@@ -180,16 +176,13 @@ class DeliveryBuilder(OrderBuilder):
delivery_relative_url,
divergence_to_adopt_list=divergence_to_adopt_list)
def solveDeliveryGroupDivergence(self, *args, **kw):
@UnrestrictedMethod
def solveDeliveryGroupDivergence(self, delivery_relative_url,
property_dict=None):
"""
solve each divergence according to users decision (accept, adopt
or do nothing).
"""
solveDeliveryGroupDivergence = UnrestrictedMethod(self._solveDeliveryGroupDivergence)
return solveDeliveryGroupDivergence(*args, **kw)
def _solveDeliveryGroupDivergence(self, delivery_relative_url,
property_dict=None):
if property_dict in (None, {}):
return
delivery = self.getPortalObject().restrictedTraverse(delivery_relative_url)
......@@ -217,18 +210,14 @@ class DeliveryBuilder(OrderBuilder):
self._solveDivergence(delivery_relative_url,
divergence_to_accept_list=divergence_to_accept_list)
def solveDivergence(self, *args, **kw):
"""
solve each divergence according to users decision (accept, adopt
or do nothing).
"""
solveDivergence = UnrestrictedMethod(self._solveDivergence)
return solveDivergence(*args, **kw)
def _solveDivergence(self, delivery_relative_url,
divergence_to_accept_list=None,
divergence_to_adopt_list=None,
**kw):
"""
solve each divergence according to users decision (accept, adopt
or do nothing).
"""
# We have to get a delivery, else, raise a Error
delivery = self.getPortalObject().restrictedTraverse(delivery_relative_url)
......@@ -328,3 +317,5 @@ class DeliveryBuilder(OrderBuilder):
self.callAfterBuildingScript(new_delivery_list, simulation_movement_list)
return delivery_list
solveDivergence = UnrestrictedMethod(_solveDivergence)
......@@ -45,7 +45,7 @@ from Products.ERP5Type.ExtensibleTraversable import ExtensibleTraversableMixIn
from Products.ERP5Type.Cache import getReadOnlyTransactionCache
from Products.ERP5.Document.Url import UrlMixIn
from Products.ERP5.Tool.ContributionTool import MAX_REPEAT
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.UnrestrictedMethod import unrestricted_apply
from Products.ZSQLCatalog.SQLCatalog import SQLQuery
from AccessControl import Unauthorized
import zope.interface
......@@ -195,8 +195,7 @@ class PermanentURLMixIn(ExtensibleTraversableMixIn):
# but we may ask him to login if such a document exists
isAuthorizationForced = getattr(self, 'isAuthorizationForced', None)
if isAuthorizationForced is not None and isAuthorizationForced():
getDocumentValue = UnrestrictedMethod(self.getDocumentValue)
if getDocumentValue(name=name, portal=portal) is not None:
if unrestricted_apply(self.getDocumentValue, (name, portal)) is not None:
# force user to login as specified in Web Section
raise Unauthorized
......
......@@ -150,7 +150,8 @@ class OrderBuilder(XMLObject, Amount, Predicate):
delivery_module = getattr(self.getPortalObject(), self.getDeliveryModule())
getattr(delivery_module, delivery_module_before_building_script_id)()
def searchMovementList(self, *args, **kw):
@UnrestrictedMethod
def searchMovementList(self, applied_rule_uid=None, **kw):
"""
Defines how to query all Simulation Movements which meet certain
criteria (including the above path path definition).
......@@ -159,11 +160,6 @@ class OrderBuilder(XMLObject, Amount, Predicate):
Then, call script simulation_select_method to restrict
movement_list.
"""
searchMovementList = UnrestrictedMethod(self._searchMovementList)
return searchMovementList(*args, **kw)
def _searchMovementList(self, applied_rule_uid=None,**kw):
"""This method is wrapped by UnrestrictedMethod."""
from Products.ERP5Type.Document import newTempMovement
movement_list = []
for attribute, method in [('node_uid', 'getDestinationUid'),
......@@ -290,16 +286,13 @@ class OrderBuilder(XMLObject, Amount, Predicate):
break
return instance, property_dict
def buildDeliveryList(self, *args, **kw):
@UnrestrictedMethod
def buildDeliveryList(self, movement_group_node,
delivery_relative_url_list=None,
movement_list=None, **kw):
"""
Build deliveries from a list of movements
"""
buildDeliveryList = UnrestrictedMethod(self._buildDeliveryList)
return buildDeliveryList(*args, **kw)
def _buildDeliveryList(self, movement_group_node, delivery_relative_url_list=None,
movement_list=None,**kw):
"""This method is wrapped by UnrestrictedMethod."""
# Parameter initialization
if delivery_relative_url_list is None:
delivery_relative_url_list = []
......@@ -686,17 +679,10 @@ class OrderBuilder(XMLObject, Amount, Predicate):
delivery_movement._edit(force_update=1, **property_dict)
simulation_movement.edit(delivery_ratio=1)
def callAfterBuildingScript(self, *args, **kw):
"""
Call script on each delivery built.
"""
callAfterBuildingScript = UnrestrictedMethod(self._callAfterBuildingScript)
return callAfterBuildingScript(*args, **kw)
def _callAfterBuildingScript(self, delivery_list, movement_list=None, **kw):
@UnrestrictedMethod
def callAfterBuildingScript(self, delivery_list, movement_list=None, **kw):
"""
Call script on each delivery built.
This method is wrapped by UnrestrictedMethod.
"""
if not len(delivery_list):
return
......
......@@ -33,7 +33,7 @@ from Products.ERP5.Document.Domain import Domain
from Products.ERP5.Document.Document import PermanentURLMixIn
from Acquisition import ImplicitAcquisitionWrapper, aq_base, aq_inner
from Products.ERP5Type.Base import TempBase
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.UnrestrictedMethod import unrestricted_apply
from AccessControl import Unauthorized
from zLOG import LOG, WARNING
import sys
......@@ -183,8 +183,7 @@ class WebSection(Domain, PermanentURLMixIn):
# but we may ask him to login if such a document exists
isAuthorizationForced = getattr(self, 'isAuthorizationForced', None)
if isAuthorizationForced is not None and isAuthorizationForced():
getDefaultDocumentValue = UnrestrictedMethod(self.getDefaultDocumentValue)
if getDefaultDocumentValue() is not None:
if unrestricted_apply(self.getDefaultDocumentValue) is not None:
# force user to login as specified in Web Section
raise Unauthorized
if document is not None and document.getReference() is not None:
......
......@@ -80,12 +80,9 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
('collected_vat', 'receivable_vat', 'refundable_vat', vat_rate),
)
@UnrestrictedMethod
def createCategories(self):
"""Create the categories for our test. """
return UnrestrictedMethod(self._createCategories)()
def _createCategories(self):
# create categories
for cat_string in self.getNeededCategoryList() :
base_cat = cat_string.split("/")[0]
path = self.getPortal().portal_categories[base_cat]
......@@ -173,11 +170,9 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
'erp5_invoicing',
'erp5_simplified_invoicing'
)
def createInvoiceTransactionRule(self, resource=None):
return UnrestrictedMethod(
self._createSaleInvoiceTransactionRule)(resource=resource)
def _createSaleInvoiceTransactionRule(self, resource=None):
@UnrestrictedMethod
def createInvoiceTransactionRule(self, resource=None):
"""Create a sale invoice transaction rule with only one cell for
product_line/apparel and default_region
The accounting rule cell will have the provided resource, but this his more
......
......@@ -63,10 +63,8 @@ class TestNestedLineMixin(TestSaleInvoiceMixin):
# Necessary to allow Invoice Line to be included in Invoice Line.
self.allowInvoiceLineContentTypeInInvoiceLine()
@UnrestrictedMethod
def allowInvoiceLineContentTypeInInvoiceLine(self):
return UnrestrictedMethod(self._allowInvoiceLineContentTypeInInvoiceLine)()
def _allowInvoiceLineContentTypeInInvoiceLine(self):
invoice_line_type = self.portal.portal_types['Invoice Line']
content_type_set = set(invoice_line_type.getTypeAllowedContentTypeList())
content_type_set.add('Invoice Line')
......@@ -82,10 +80,8 @@ class TestNestedLineMixin(TestSaleInvoiceMixin):
def stepUpdateBuilderForMultipleLineList(self, **kw):
self.updateBuilderForMultipleLineList()
@UnrestrictedMethod
def updateBuilderForMultipleLineList(self):
return UnrestrictedMethod(self._updateBuilderForMultipleLineList)()
def _updateBuilderForMultipleLineList(self):
delivery_builder = getattr(self.portal.portal_deliveries, self.delivery_builder_id)
delivery_builder.deleteContent(delivery_builder.contentIds())
......
......@@ -83,12 +83,9 @@ class TestInvoiceMixin(TestPackingListMixin,
'erp5_invoicing', 'erp5_simplified_invoicing', 'erp5_apparel',
'erp5_project')
@UnrestrictedMethod
def createCategories(self):
"""Create the categories for our test. """
return UnrestrictedMethod(self._createCategories)()
def _createCategories(self):
# create categories
for cat_string in self.getNeededCategoryList() :
base_cat = cat_string.split("/")[0]
path = self.getPortal().portal_categories[base_cat]
......@@ -151,11 +148,8 @@ class TestInvoiceMixin(TestPackingListMixin,
"""Create the rule for accounting. """
self.createInvoiceTransactionRule(resource=sequence.get('resource'))
@UnrestrictedMethod
def createInvoiceTransactionRule(self, resource=None):
return UnrestrictedMethod(
self._createSaleInvoiceTransactionRule)(resource=resource)
def _createSaleInvoiceTransactionRule(self, resource=None):
"""Create a sale invoice transaction rule with only one cell for
product_line/apparel and default_region
The accounting rule cell will have the provided resource, but this his more
......@@ -2499,17 +2493,14 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
# fix inheritance
login = TestInvoiceMixin.login
createCategories = TestInvoiceMixin.createCategories
def _createCategories(self):
@UnrestrictedMethod
def createCategories(self):
TestPackingListMixin.createCategories(self)
TestInvoiceMixin._createCategories(self)
TestInvoiceMixin.createCategories(self)
getNeededCategoryList = TestInvoiceMixin.getNeededCategoryList
def test_01_SimpleInvoice(self, quiet=quiet):
"""
Checks that a Simple Invoice is created from a Packing List
......
......@@ -44,7 +44,6 @@ from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\
_ViewEmulator
from Products.ERP5Type import Permissions, PropertySheet, Constraint
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5.Document.File import File
from Products.ERP5.Document.Document import PermanentURLMixIn
from Products.ERP5.Document.Document import ConversionError
......
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