Commit 6af89795 authored by Jérome Perrin's avatar Jérome Perrin

accounting: stop using portal_catalog.getObject

This is not public API and is not supposed to be used outside of catalog
tool.
using getObject here is also wrong because it does not apply security
and does not check provided argument type.
parent bdc4326e
......@@ -8,7 +8,6 @@ request = portal.REQUEST
getInventoryList_ = portal.portal_simulation.getInventoryList
traverse = portal.restrictedTraverse
portal_catalog = portal.portal_catalog
getObject = portal_catalog.getObject
Base_translateString = portal.Base_translateString
selected_gap = gap_root
traverseCategory = portal.portal_categories.restrictedTraverse
......@@ -551,6 +550,8 @@ if node_uid_of_strict_account_type_to_group_by_payment:
if src__:
return src_list
TRANSLATED_NONE = Base_translateString('None')
node_title_and_id_cache = {}
def getNodeTitleAndId(node_relative_url):
try:
......@@ -575,11 +576,10 @@ def getSectionPriceCurrencyFromSectionUid(uid):
try:
return section_price_currency_dict[uid]
except KeyError:
section = getObject(uid)
if section is None:
price_currency = ''
else:
price_currency = section.getProperty('price_currency_reference')
price_currency = ''
brain_list = portal.portal_catalog(uid=uid)
if brain_list:
price_currency = brain_list[0].getObject().getProperty('price_currency_reference')
section_price_currency_dict[uid] = price_currency
return price_currency
......@@ -590,15 +590,45 @@ def getAnalyticTitleFromUid(uid):
try:
return analytic_title_dict[uid]
except KeyError:
node = getObject(uid)
title = node.getTranslatedTitle()
reference = node.getReference()
if reference:
title = '%s - %s' % (reference, title)
title = TRANSLATED_NONE
brain_list = portal.portal_catalog(uid=uid)
if brain_list:
node = brain_list[0].getObject()
title = node.getTranslatedTitle()
reference = node.getReference()
if reference:
title = '%s - %s' % (reference, title)
analytic_title_dict[uid] = title
return title
TRANSLATED_NONE = Base_translateString('None')
mirror_section_title_dict = {None: ''}
def getMirrorSectionTitleFromUid(uid):
if uid is MARKER:
return ''
try:
return mirror_section_title_dict[uid]
except KeyError:
title = TRANSLATED_NONE
brain_list = portal.portal_catalog(uid=uid)
if brain_list:
node = brain_list[0].getObject()
title = node.getTitle()
mirror_section_title_dict[uid] = title
return title
payment_title_dict = {None: TRANSLATED_NONE}
def getPaymentTitleFromUid(uid):
try:
return payment_title_dict[uid]
except KeyError:
title = TRANSLATED_NONE
brain_list = portal.portal_catalog(uid=uid)
if brain_list:
node = brain_list[0].getObject()
title = node.getTitle()
payment_title_dict[uid] = title
return title
line_list = []
for key, data in line_per_account.iteritems():
node_relative_url = key[0]
......@@ -606,10 +636,8 @@ for key, data in line_per_account.iteritems():
payment_uid = key[2]
analytic_key_list = key[3:]
if expand_accounts and mirror_section_uid is not MARKER:
mirror_section_title = getObject(mirror_section_uid).getTitle()
else:
mirror_section_title = None
if expand_accounts:
mirror_section_title = getMirrorSectionTitleFromUid(mirror_section_uid)
node_uid, node_title, node_id, node_string_index, node = getNodeTitleAndId(node_relative_url)
......@@ -617,9 +645,7 @@ for key, data in line_per_account.iteritems():
continue
if payment_uid is not MARKER:
node_title += " (%s)" % (
TRANSLATED_NONE if payment_uid is None else getObject(payment_uid).getTitle(),
)
node_title += " (%s)" % getPaymentTitleFromUid(payment_uid)
if not node_string_index:
node_string_index = '%-10s' % node_id
......@@ -670,7 +696,7 @@ for key, data in line_per_account.iteritems():
if not show_empty_accounts:
line_list = [
line for line in line_list
l for l in line_list
if line['debit'] or
line['credit'] or
line['initial_credit_balance'] or
......
......@@ -142,18 +142,16 @@ def getAccountName(account_relative_url):
account_name_cache[account_relative_url] = name
return name
getObject = portal.portal_catalog.getObject
title_for_uid_cache = {}
title_for_uid_cache = {None: ''}
def getTitleForUid(uid):
try:
return title_for_uid_cache[uid]
except KeyError:
name = ''
if uid:
document = getObject(uid)
if document is not None:
name = document.getTitle()
brain_list = portal.portal_catalog(uid=uid)
if brain_list:
name = brain_list[0].getObject().getTitle()
title_for_uid_cache[uid] = name
return name
......
......@@ -5,7 +5,6 @@ except:
Redirect = 'Redirect'
portal = context.getPortalObject()
stool = portal.portal_selections
getObject = portal.portal_catalog.getObject
countMessage = portal.portal_activities.countMessage
invoice_type_list = portal.getPortalInvoiceTypeList()
......@@ -13,7 +12,7 @@ stool.updateSelectionCheckedUidList(selection_name, listbox_uid, uids)
selection_uid_list = context.portal_selections.getSelectionCheckedUidsFor(
selection_name)
if selection_uid_list:
object_list = [getObject(uid) for uid in selection_uid_list]
object_list = [brain.getObject() for brain in portal.portal_catalog(uid=selection_uid_list)]
else:
object_list = stool.callSelectionFor(selection_name)
......
......@@ -5,14 +5,13 @@ except:
Redirect = 'Redirect'
portal = context.getPortalObject()
stool = portal.portal_selections
getObject = portal.portal_catalog.getObject
countMessage = portal.portal_activities.countMessage
stool.updateSelectionCheckedUidList(selection_name, listbox_uid, uids)
selection_uid_list = context.portal_selections.getSelectionCheckedUidsFor(
selection_name)
if selection_uid_list:
object_list = [getObject(uid) for uid in selection_uid_list]
object_list = [brain.getObject() for brain in portal.portal_catalog(uid=selection_uid_list)]
else:
object_list = stool.callSelectionFor(selection_name)
......
......@@ -42,8 +42,7 @@ if section_category:
checked_uid_list = \
portal_selections.getSelectionCheckedUidsFor(selection_name)
if checked_uid_list:
getObject = portal.portal_catalog.getObject
delivery_list = [getObject(uid) for uid in checked_uid_list]
delivery_list = [brain.getObject() for brain in portal.portal_catalog(uid=checked_uid_list)]
else:
params = portal_selections.getSelectionParamsFor(selection_name)
params['limit'] = None # XXX potentially very big report
......
......@@ -26,13 +26,16 @@ def getAccountNumber(account_url):
portal.restrictedTraverse(account_url).Account_getGapId()
return account_number_memo[account_url]
section_title_memo = {}
section_title_memo = {None: ''}
def getSectionTitle(uid):
try:
return section_title_memo[uid]
except KeyError:
section_title_memo[uid] =\
portal.portal_catalog.getObject(uid).getTranslatedTitle()
section_title = ''
brain_list = portal.portal_catalog(uid=uid)
if brain_list:
section_title = brain_list[0].getObject().getTranslatedTitle()
section_title_memo[uid] = section_title
return section_title_memo[uid]
last_period_id = 'period_%s' % len(period_list)
......
......@@ -7,15 +7,14 @@ portal = context.getPortalObject()
selection_name = \
context.AccountingTransactionModule_viewGroupingFastInputDialog.listbox.get_value('selection_name')
getobject = portal.portal_catalog.getobject
selected_uid_list = portal.portal_selections.getSelectionCheckedUidsFor(selection_name)
total_selected_amount = 0
# calculate total selected amount
for uid in selected_uid_list or []:
line = getobject(uid)
if line.AccountingTransaction_isSourceView():
total_selected_amount += (line.getSourceInventoriatedTotalAssetPrice() or 0)
else:
total_selected_amount += (line.getDestinationInventoriatedTotalAssetPrice() or 0)
selected_uid_list = portal.portal_selections.getSelectionCheckedUidsFor(selection_name)
if selected_uid_list:
for line in portal.portal_catalog(uid=selected_uid_list):
line = line.getObject()
if line.AccountingTransaction_isSourceView():
total_selected_amount += (line.getSourceInventoriatedTotalAssetPrice() or 0)
else:
total_selected_amount += (line.getDestinationInventoriatedTotalAssetPrice() or 0)
return total_selected_amount
......@@ -4,7 +4,6 @@ Used as a fast input dialog action.
from ZTUtils import make_query
from ZODB.POSException import ConflictError
portal = context.getPortalObject()
getobject = portal.portal_catalog.getobject
stool = portal.portal_selections
Base_translateString = portal.Base_translateString
psm = Base_translateString('Nothing matches.')
......@@ -37,8 +36,8 @@ portal.portal_selections.setSelectionParamsFor(
# calculate total selected amount
total_selected_amount = 0
if uids:
for uid in uids:
line = getobject(uid)
for line in portal.portal_catalog(uid=uids):
line = line.getObject()
if line.AccountingTransaction_isSourceView(): # XXX not optimal !
total_selected_amount += (line.getSourceInventoriatedTotalAssetPrice() or 0)
else:
......@@ -113,13 +112,15 @@ if grouping == 'grouping':
else:
assert grouping == 'ungrouping'
# XXX is uids multi page safe here ?
line_list = [getobject(line_uid) for line_uid in uids]
ungrouped_line_list = []
line_list = []
if uids:
line_list = [brain.getObject() for brain in portal.portal_catalog(uid=uids)]
ungrouped_line_list = []
for line in line_list:
if line.getGroupingReference():
ungrouped_line_list.extend(line.AccountingTransactionLine_resetGroupingReference())
psm = Base_translateString('${ungrouped_line_count} lines ungrouped.',
mapping=dict(ungrouped_line_count=len(ungrouped_line_list)))
......
......@@ -12,7 +12,7 @@ def getAccountingPeriodStartDateForSectionCategory(section_category, date):
period_start_date = None
for uid in section_uid:
if uid == -1: continue # Base_getSectionUidListForSectionCategory returns [-1] if no section_uid exists
section = portal.portal_catalog.getObject(uid)
section = portal.portal_catalog(uid=uid)[0].getObject()
for ap in section.contentValues(portal_type='Accounting Period',
checked_permission='Access contents information'):
if ap.getSimulationState() not in ('planned', 'confirmed',
......
......@@ -10,7 +10,7 @@ def getCurrencyForSectionCategory(section_category, section_category_strict):
for section_uid in portal.Base_getSectionUidListForSectionCategory(
section_category, section_category_strict):
if section_uid != -1:
section = portal.portal_catalog.getObject(section_uid)
section = portal.portal_catalog(uid=section_uid)[0].getObject()
currency = section.getPriceCurrency()
if currency:
currency_set.add(currency)
......
......@@ -4,9 +4,9 @@ try:
return request.other[context.mirror_section_uid]
except KeyError:
if context.mirror_section_uid:
mirror_section = context.getPortalObject().portal_catalog.getobject(context.mirror_section_uid)
if mirror_section is not None:
mirror_section_title = mirror_section.getTitle()
brain_list = context.getPortalObject().portal_catalog(uid=context.mirror_section_uid)
if brain_list:
mirror_section_title = brain_list[0].getObject().getTitle()
request.other[context.mirror_section_uid] = mirror_section_title
return mirror_section_title
......@@ -4,9 +4,9 @@ try:
return request.other[context.payment_uid]
except KeyError:
if context.payment_uid:
payment = context.getPortalObject().portal_catalog.getobject(context.payment_uid)
if payment is not None:
payment_title = payment.getTitle()
brain_list = context.getPortalObject().portal_catalog(uid=context.payment_uid)
if brain_list:
payment_title = brain_list[0].getObject().getTitle()
request.other[context.payment_uid] = payment_title
return payment_title
......@@ -4,9 +4,9 @@ try:
return request.other[context.project_uid]
except KeyError:
if context.project_uid:
project = context.getPortalObject().portal_catalog.getobject(context.project_uid)
if project is not None:
project_title = project.getTitle()
brain_list = context.getPortalObject().portal_catalog(uid=context.project_uid)
if brain_list:
project_title = brain_list[0].getObject().getTitle()
request.other[context.project_uid] = project_title
return project_title
if brain.payment_uid:
bank_account = context.getPortalObject().portal_catalog.getObject(brain.payment_uid)
if bank_account is not None:
result_list = context.getPortalObject().portal_catalog(uid=brain.payment_uid)
if result_list:
bank_account = result_list[0].getObject()
# XXX use preference ?
if bank_account.getReference():
return '%s - %s' % (bank_account.getReference(), bank_account.getTitle())
......
......@@ -72,14 +72,12 @@ net_balance = 0.0
# accounts from PL have a balance calculated differently
is_pl_account = False
if params.get('node_uid'):
if context.getUid() == params['node_uid']:
if context.getUid() == params['node_uid']: # shortcut
node = context
is_pl_account = context.isMemberOf('account_type/expense')\
or context.isMemberOf('account_type/income')
else:
node = portal.portal_catalog.getObject(params['node_uid'])
is_pl_account = node.isMemberOf('account_type/expense')\
or node.isMemberOf('account_type/income')
node = portal.portal_catalog(uid=params['node_uid'])[0].getObject()
is_pl_account = node.isMemberOf('account_type/expense')\
or node.isMemberOf('account_type/income')
# remove unknown catalog keys from params
params.pop('detailed_from_date_summary', None)
......@@ -197,11 +195,11 @@ if from_date or is_pl_account:
node_translated_title=node.getTranslatedTitle()
)
if params.get('mirror_section_uid'):
mirror_section = portal.portal_catalog.getObject(params['mirror_section_uid'])
mirror_section = portal.portal_catalog(uid=params['mirror_section_uid'])[0].getObject()
previous_balance.edit(
mirror_section_title=mirror_section.getTitle()
)
section = portal.portal_catalog.getObject(section_uid)
section = portal.portal_catalog(uid=section_uid)[0].getObject()
previous_balance.edit(
Movement_getSectionPriceCurrency=section.getPriceCurrencyReference(),
resource_reference=section.getPriceCurrencyReference(),
......
......@@ -74,7 +74,8 @@ if period_start_date and params.get('node_uid'):
if context.getUid() == params['node_uid']: # I bet it's context
node = context
else:
node = portal.portal_catalog.getObject(params['node_uid'])
node, = portal.portal_catalog(uid=params['node_uid'])
node = node.getObject()
if node.isMemberOf('account_type/expense') or\
node.isMemberOf('account_type/income'):
# For expense or income accounts, we only take into account transactions
......
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