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