Commit 7a8017c6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

newTemp*() deprecation (1bce8563, 04b49859): Replace static/direct newTemp*() calls.

parent 35176926
......@@ -22,9 +22,8 @@ else:
shopping_cart_id = 'shopping_cart'
session = portal_sessions[session_id]
if not shopping_cart_id in session.keys():
from Products.ERP5Type.Document import newTempOrder
web_site = context.getWebSiteValue()
shopping_cart = newTempOrder(portal_sessions, shopping_cart_id)
shopping_cart = context.getPortalObject().newContent(temp_object=True, portal_type='Order', id=shopping_cart_id)
shopping_cart.setPriceCurrency(web_site.WebSite_getShoppingCartDefaultCurrency().getRelativeUrl())
session[shopping_cart_id] = shopping_cart
......
......@@ -58,9 +58,9 @@ class TestContributionRegistryTool(ERP5TypeTestCase):
##parameters=predicate=None
##title=
##
from Products.ERP5Type.Document import newTempEvent
event = newTempEvent(context, 'subobject', data=context.getData())
event = context.newContent(temp_object=True, portal_type='Event',
id='subobject', data=context.getData())
subject = event.getContentInformation().get('Subject', None)
if subject == 'Fax':
......
from Products.ERP5Type.Document import newTempDomain
portal = context.getPortalObject()
portal_type_list = portal.getPortalEventTypeList()
portal_types = portal.portal_types
......
request = context.REQUEST
from Products.ERP5Type.Document import newTempBase
from Products.ERP5Type.Document import newTempMappedValue
from AccessControl import getSecurityManager
u=getSecurityManager().getUser()
......
from Products.ERP5Type.Message import translateString
from Products.ERP5Type.Document import newTempDocument
return_list = []
i = 1
portal = context.getPortalObject()
......@@ -9,7 +8,7 @@ for worklist in context.portal_workflow.listActionInfos():
# Worklist translation process is a bit tricky. We translate only the first part of "X to Validate (count)"
title, count = title.split(' (', 1)
title = "%s (%s" % ( translateString(title), count )
o = newTempDocument(portal, str(i))
o = portal.newContent(temp_object=True, portal_type='Document', id=str(i))
o.edit(
count=worklist['count'],
title=title,
......
......@@ -2,7 +2,6 @@ import zope
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Document import newTempDocument
import hashlib
from zLOG import LOG, WARNING
import datetime
......@@ -343,7 +342,7 @@ class PayzenService(XMLObject, PayzenSOAP):
if message_list:
raise ValidationFailed, message_list
temp_document = newTempDocument(self, 'id')
temp_document = self.newContent(temp_object=True, portal_type='Document', id='id')
temp_document.edit(
link_url_string=self.getLinkUrlString(),
title='title',
......
......@@ -20,7 +20,7 @@
</item>
<item>
<key> <string>description</string> </key>
<value> <string>This portal type is an abstract portal type, so that newTempOrder calls can succeed; one should never have to use this portal type for persistent objects.</string> </value>
<value> <string>This portal type is an abstract portal type, so that newContent(temp_object=True) calls can succeed; one should never have to use this portal type for persistent objects.</string> </value>
</item>
<item>
<key> <string>factory</string> </key>
......
......@@ -29,7 +29,6 @@
import hashlib
import json
import validictory
from Products.ERP5Type.Document import newTempFile
from Products.ERP5Type.UnrestrictedMethod import super_user
......@@ -71,7 +70,7 @@ def WebSection_getDocumentValue(self, key, portal=None, language=None,\
follow_up_uid=data_set.getUid(),
validation_state='published')]
temp_file = newTempFile(self, '%s.txt' % key)
temp_file = self.newContent(temp_object=True, portal_type='File', id='%s.txt' % key)
temp_file.setData(json.dumps(document_list))
temp_file.setContentType('application/json')
return temp_file.getObject()
......
......@@ -401,7 +401,6 @@ class BalanceTransaction(AccountingTransaction, Inventory):
This method must return a function that accepts properties keywords
arguments and returns a temp object edited with those properties.
"""
from Products.ERP5Type.Document import newTempAccountingTransactionLine
# When have to reindex temp objects with quantity 0 in
# order to update stock if delta become 0, but but redefining
# isMovement we do not insert 0 lines in stock
......@@ -409,7 +408,9 @@ class BalanceTransaction(AccountingTransaction, Inventory):
return self.getProperty('total_price', 0) != 0 or \
self.getProperty('quantity', 0) != 0
def factory(*args, **kw):
doc = newTempAccountingTransactionLine(self, kw.pop('id', self.getId()),
doc = self.newContent(temp_object=True,
portal_type='Accounting Transaction Line',
id=kw.pop('id', self.getId()),
uid=self.getUid())
doc.portal_type = 'Balance Transaction Line'
relative_url = kw.pop('relative_url', None)
......
......@@ -144,7 +144,9 @@ class Inventory(Delivery):
if temp_constructor is None:
from Products.ERP5Type.Document import newTempMovement as temp_constructor
def temp_constructor(self, id, *args, **kw):
return self.newContent(temp_object=True, portal_type='Movement',
id=id, *args, **kw)
stop_date = self.getStopDate()
stock_object_list = []
......
......@@ -51,10 +51,10 @@ from zLOG import LOG, WARNING
def getExchangeRate(currency_value, section_currency, date):
currency = currency_value.getRelativeUrl()
if currency != section_currency:
from Products.ERP5Type.Document import newTempAccountingTransactionLine
return currency_value.getPrice(context=newTempAccountingTransactionLine(
currency_value.getPortalObject(),
"accounting_line",
return currency_value.getPrice(context=currency_value.getPortalObject().newContent(
temp_object=True,
portal_type='Accounting Transaction Line',
id="accounting_line",
resource=currency,
start_date=date,
price_currency=section_currency
......
......@@ -82,7 +82,6 @@ class Order(Delivery):
# Find amounts from the result of getAggregatedAmountList.
# Call getAggregatedAmountList and sum all the amounts which
# base_contribution category is matched with.
from Products.ERP5Type.Document import newTempTradeModelLine
from Products.ERP5.PropertySheet.TradeModelLine import TARGET_LEVEL_MOVEMENT
trade_condition = self.getSpecialiseValue()
if trade_condition is None:
......@@ -103,8 +102,9 @@ class Order(Delivery):
# We cannot find any amount so that the result is 0.
return 0
current_aggregated_amount_list = trade_condition.getAggregatedAmountList(self, rounding=rounding, force_create_line=True)
trade_model_line = newTempTradeModelLine(
self, '_temp_' + self.getId(), notify_workflow=False)
trade_model_line = self.newContent(temp_object=True,
portal_type='Trade Model Line',
id='_temp_' + self.getId(), notify_workflow=False)
# prevent invoking interaction workflows.
trade_model_line.portal_type = ''
trade_model_line.edit(target_level=TARGET_LEVEL_MOVEMENT, price=1,
......
......@@ -74,7 +74,6 @@ class GeneratedAmountList(list):
Groups amounts with same price, efficiency, reference and categories, merge
them by summing their quantities, and return the new amounts in a new list.
"""
from Products.ERP5Type.Document import newTempAmount
# XXX: Do we handle rounding correctly ?
# What to do if only total price is rounded ??
aggregate_dict = {}
......@@ -92,7 +91,10 @@ class GeneratedAmountList(list):
# Before we ignore 'quantity==0' amount here for better performance,
# but it is not a good idea, especially when the first expand causes
# non-zero quantity and then quantity becomes zero.
aggregate = newTempAmount(amount.aq_parent, '', notify_workflow=False)
aggregate = amount.aq_parent.newContent(temp_object=True,
portal_type='Amount',
id='',
notify_workflow=False)
aggregate.__dict__.update(amount.aq_base.__dict__)
aggregate._setQuantity(quantity)
if isinstance(amount, RoundingProxy):
......
......@@ -47,8 +47,7 @@ class ContributionRegistryTool(BaseTool):
# if a context is passed, ignore other arguments
if context is None:
# Build a temp object edited with provided parameters
from Products.ERP5Type.Document import newTempFile
context = newTempFile(self, '_')
context = self.newContent(temp_object=True, portal_type='File', id='_')
context.edit(**kw)
for predicate in self.objectValues(sort_on='int_index'):
......
......@@ -412,8 +412,7 @@ class NotificationTool(BaseTool):
else:
# CRM is not installed - only notification by email is possible
# So create a temp object directly
from Products.ERP5Type.Document import newTempEvent
new_event = newTempEvent(self, '_')
new_event = self.newContent(temp_object=True, portal_type='Event', id='_')
event_list = [new_event]
if event in event_list:
......
......@@ -987,7 +987,6 @@ class TemplateTool (BaseTool):
update_only: return only bt that needs to be updated
template_list: only returns bt within the given list
"""
from Products.ERP5Type.Document import newTempBusinessTemplate
result_list = []
template_set = None
if template_list is not None:
......@@ -1051,13 +1050,16 @@ class TemplateTool (BaseTool):
installed_revision = ''
version_state = 'new'
uid = self.encodeRepositoryBusinessTemplateUid(repository, id)
obj = newTempBusinessTemplate(self, 'temp_' + uid,
version_state = version_state,
obj = self.newContent(temp_object=True,
portal_type='Business Template',
id='temp_' + uid,
version_state=version_state,
version_state_title=version_state.title(),
filename = filename,
installed_version = installed_version,
installed_revision = installed_revision,
repository = repository, **property_dict)
filename=filename,
installed_version=installed_version,
installed_revision=installed_revision,
repository=repository,
**property_dict)
obj.setUid(uid)
result_list.append(obj)
result_list.sort(key=lambda x: x.getTitle())
......
......@@ -14,7 +14,7 @@
</item>
<item>
<key> <string>description</string> </key>
<value> <string>This portal type is an abstract portal type, so that newTempAmount calls can succeed; one should never have to use this portal type for persistent objects.</string> </value>
<value> <string>This portal type is an abstract portal type, so that Amount temp_objects can be created; one should never have to use this portal type for persistent objects.</string> </value>
</item>
<item>
<key> <string>factory</string> </key>
......
......@@ -16,7 +16,7 @@
<key> <string>description</string> </key>
<value> <string>The purpose of an Event object is to keep track of the interface between the ERP and third parties.\n
\n
This portal type is an abstract portal type, so that newTempEvent calls can succeed; one should never have to use this portal type for persistent objects.</string> </value>
This portal type is an abstract portal type, so that Event temp_objects can be created; one should never have to use this portal type for persistent objects.</string> </value>
</item>
<item>
<key> <string>factory</string> </key>
......
......@@ -14,7 +14,7 @@
</item>
<item>
<key> <string>description</string> </key>
<value> <string>This portal type is an abstract portal type, so that newTempMovement calls can succeed; one should never have to use this portal type for persistent objects.</string> </value>
<value> <string>This portal type is an abstract portal type, so that Movement temp_objects can be created; one should never have to use this portal type for persistent objects.</string> </value>
</item>
<item>
<key> <string>factory</string> </key>
......
......@@ -6,7 +6,6 @@
# is a list of variation categories that are relevant for the produced resource
from Products.ERP5Type.Document import newTempMovement
# List of dictionaries:
# { id:resource_id,
......@@ -22,7 +21,8 @@ for transformation_relative_url, variation_list_list in transformation_item_list
if resource is None:
continue
for variation_list in variation_list_list:
movement = newTempMovement(resource, 'temp',
movement = resource.newContent(temp_object=True, portal_type='Movement',
id='temp',
specialise_value=transformation,
variation_category_list=variation_list,
resource_value=resource,
......
......@@ -273,7 +273,6 @@ class AmountGeneratorMixin:
very likely not - proxying before or after must be decided
"""
# It is the only place where we can import this
from Products.ERP5Type.Document import newTempAmount
portal = self.getPortalObject()
getRoundingProxy = portal.portal_roundings.getRoundingProxy
amount_generator_line_type_list = \
......@@ -470,9 +469,9 @@ class AmountGeneratorMixin:
if getattr(self.aq_base, 'create_line', None) == 0:
property_dict['resource'] = None
# Create an Amount object
amount = newTempAmount(portal,
amount = portal.newContent(temp_object=True, portal_type='Amount',
# we only want the id to be unique so we pick a random causality
property_dict['causality_value_list'][-1]
id=property_dict['causality_value_list'][-1]
.getRelativeUrl().replace('/', '_'),
notify_workflow=False)
amount._setCategoryList(property_dict.pop('category_list', ()))
......
......@@ -902,16 +902,17 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
def stepCreateMatchableInvoiceMovements(self, sequence, **kw) :
""" Create a temp movement that will be matched by the
default_invoice_transaction_rule """
from Products.ERP5Type.Document import newTempMovement
product_notebook_region_france_movement = newTempMovement(
sequence.get('invoice'),
'test1',
product_notebook_region_france_movement = sequence.get('invoice').newContent(
temp_object=True,
portal_type='Movement',
id='test1',
resource = sequence.get('notebook').getRelativeUrl(),
destination = sequence.get('client_fr').getRelativeUrl(),
)
product_barebone_region_france_movement = newTempMovement(
sequence.get('invoice'),
'test2',
product_barebone_region_france_movement = sequence.get('invoice').newContent(
temp_object=True,
portal_type='Movement',
id='test2',
resource = sequence.get('barebone').getRelativeUrl(),
destination = sequence.get('client_fr').getRelativeUrl(),
)
......@@ -1005,16 +1006,17 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
def stepCreateNotMatchableInvoiceMovements(self, sequence, **kw) :
""" create a temp movement that not any cell could match. """
from Products.ERP5Type.Document import newTempMovement
bad_movement1 = newTempMovement(
sequence.get("invoice"),
'test3',
bad_movement1 = sequence.get("invoice").newContent(
temp_object=True,
portal_type='Movement',
id='test3',
product = None,
destination = sequence.get('client').getRelativeUrl(),
)
bad_movement2 = newTempMovement(
sequence.get("invoice"),
'test4',
bad_movement2 = sequence.get("invoice").newContent(
temp_object=True,
portal_type='Movement',
id='test4',
gap = 'gap/1',
destination = sequence.get('client').getRelativeUrl(),
)
......
......@@ -82,8 +82,8 @@ class CurrencyExchangeTestCase(AccountingTestCase):
def _getPriceContext(self, **kw):
"""Returns a temp movement that we can use for getPrice(context=
"""
from Products.ERP5Type.Document import newTempMovement
return newTempMovement(self.portal, 'tmp', **kw)
return self.portal.newContent(temp_object=True, portal_type='Movement',
id='tmp', **kw)
class TestCurrencyExchangeLine(CurrencyExchangeTestCase):
......
......@@ -826,10 +826,9 @@ return getBaseAmountQuantity""")
('tax_share/A',): .5,
('tax_share/B',): .6,
}, base_application=(0,))
from Products.ERP5Type.Document import newTempAmount
for x in ((100, 30, 10, 0, 0, 20, 5, 12),
(500, 150, 20, 90, 40, 120, 55, 96)):
amount = newTempAmount(self.portal, '_',
amount = self.portal.newContent(temp_object=True, portal_type='Amount', id='_',
quantity=x[0], price=1,
base_contribution=base_amount)
amount_list = trade_condition.getGeneratedAmountList((amount,))
......@@ -882,10 +881,9 @@ return context""" % (base_amount, base_amount))
sum((x.getTotalPrice() for x in amount_list), total_price))
def test_05_dependencyResolution(self):
from Products.ERP5Type.Document import newTempAmount, newTempTradeModelLine
from Products.ERP5.mixin.amount_generator import BaseAmountResolver
delivery_amount = newTempAmount(self.portal, '')
trade_model_line = newTempTradeModelLine(self.portal, '')
delivery_amount = self.portal.newContent(temp_object=True, portal_type='Amount', id='')
trade_model_line = self.portal.newContent(temp_object=True, portal_type='Trade Model Line', id='')
def case(*lines):
return BaseAmountResolver({}, {}), [{
None: trade_model_line,
......
......@@ -309,14 +309,15 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion):
)
swimsuit_quantity = 4.0
from Products.ERP5Type.Document import newTempAmount
n = 1
# Check that getAggregatedAmount returns the expected results, a.k.a.
# that our Transformation is set up correctly.
for i, size in enumerate(self.size_category_list):
for colour in self.colour_category_list:
# id does not matter, just make it unique
temp_amount = newTempAmount(transformation, "foo_%s_%s" % (size, colour))
temp_amount = transformation.newContent(temp_object=True,
portal_type='Amount',
id="foo_%s_%s" % (size, colour))
temp_amount.edit(
quantity = swimsuit_quantity,
variation_category_list = [size, colour],
......
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