Commit 6336fcb5 authored by Jérome Perrin's avatar Jérome Perrin

Some erp5_accounting coding style fixes

Following up !308 , these are a batch of changes to fix coding style in `erp5_accounting` as reported by pylint and `Products.ERP5Type.CodingStyle`.

Also, calls to `portal_catalog.getObject` are replaced by simple `portal_catalog` calls.


/reviewed-on nexedi/erp5!309
parents 002e018c d9a2a92d
# precision for editable fields
params = context.ERP5Accounting_getParams(selection_name)
params = context.ERP5Site_getAccountingSelectionParameterDict(selection_name)
if params.get('precision', None) is not None:
context.REQUEST.set('precision', params['precision'])
......
......@@ -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
......@@ -305,7 +304,7 @@ if node_uid_of_strict_account_type_to_group_by_payment:
# include all accounts, even those not selected before (no movements in the
# period)
for node in LazyFilter(portal.account_module.contentValues(), skip=''): # XXX: context should already be account_module
for node in LazyFilter(portal.account_module.contentValues(), skip=''):
if node.getRelativeUrl() not in account_used:
getAccountProps(
{
......@@ -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,12 +576,12 @@ 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')
section_price_currency_dict[uid] = price_currency
price_currency = ''
brain_list = portal_catalog(uid=uid, limit=2)
if brain_list:
brain, = brain_list
price_currency = brain.getObject().getProperty('price_currency_reference')
section_price_currency_dict[uid] = price_currency
return price_currency
analytic_title_dict = {None: ''}
......@@ -590,15 +591,46 @@ 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 = ''
brain_list = portal_catalog(uid=uid, limit=2)
if brain_list:
brain, = brain_list
node = brain.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 = ''
brain_list = portal_catalog(uid=uid, limit=2)
if brain_list:
brain, = brain_list
title = brain.getObject().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 = ''
brain_list = portal_catalog(uid=uid, limit=2)
if brain_list:
brain, = brain_list
title = brain.getObject().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 +638,9 @@ 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
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 +648,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
......@@ -695,6 +724,7 @@ if per_account_class_summary:
for gap in account.getGapList():
if gap.startswith(current_gap):
gap_part_list = gap.split('/')
# TODO: this should not be ID
# country / accounting principle / ${class}
if len(gap_part_list) > 2:
return gap_part_list[2]
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>show_empty_accounts, expand_accounts, at_date, from_date, period_start_date, section_uid, simulation_state, precision, node_uid, gap_root=None, per_account_class_summary=0, portal_type=None, function=None, funding=None, project=None, ledger=None, group_analytic=[], mirror_section_category=None, show_detailed_balance_columns=False, src__=False, **kw</string> </value>
<value> <string>show_empty_accounts, expand_accounts, at_date, from_date, period_start_date, section_uid, simulation_state, precision, node_uid, gap_root=None, per_account_class_summary=0, portal_type=None, function=None, funding=None, project=None, ledger=None, group_analytic=(), mirror_section_category=None, show_detailed_balance_columns=False, src__=False, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
kwd = context.ERP5Accounting_getParams(selection_name)
kwd = context.ERP5Site_getAccountingSelectionParameterDict(selection_name)
# cleanup unsupported catalog parameters
kwd.pop('period_start_date', None)
kwd.pop('detailed_from_date_summary', None)
......
# Return the list of gap roots that can be used.
# gap category is typically organized such as :
# gap category is typically organized such as :
# gap / country / gap_name
# so we always use as "root" the category of depth 2.
item_list = [('', '')]
countries = context.portal_categories.gap.objectValues()
for country in countries :
for gap in country.objectValues() :
title = country.getTranslatedTitle() + '/'+ gap.getTranslatedTitle()
for country in countries:
for gap in country.objectValues():
path = gap.getRelativeUrl()
item_list.append(
((country.getTranslatedTitle() + '/'+ gap.getTranslatedTitle()),
......
portal = context.getPortalObject()
params = portal.ERP5Accounting_getParams(selection_name)
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name)
params['omit_asset_increase'] = omit_asset_increase
params['omit_asset_decrease'] = omit_asset_decrease
# For now, we omit simulation to be compatible with other reports.
params['omit_simulation'] = True
# Remove params used internally by ERP5Accounting_getParams before passing to inventory API
# Remove params used internally by ERP5Site_getAccountingSelectionParameterDict before passing to inventory API
params.pop("period_start_date", None)
params.pop("detailed_from_date_summary", None)
......
......@@ -11,48 +11,51 @@ transaction_simulation_state = request['transaction_simulation_state']
from_date = request.get('from_date', None)
result = []
params = {
'to_date' : to_date,
'section_category' : transaction_section_category,
'simulation_state' : transaction_simulation_state,
'accounting_transaction_line_currency' : None,
'report_depth' : 5
}
params = {
'to_date': to_date,
'section_category': transaction_section_category,
'simulation_state': transaction_simulation_state,
'accounting_transaction_line_currency': None,
'report_depth': 5
}
if from_date:
params['from_date'] = from_date
if from_date:
params['from_date'] = from_date
groupCategory = context.portal_categories.restrictedTraverse(transaction_section_category)
entities = groupCategory.getGroupRelatedValueList(portal_type = ('Organisation', 'Person'))
entity_columns = ( ('title', 'Title'),
('getStopDate', 'Date'),
('reference', 'Invoice No'),
('getDestinationSectionTitle', 'Third Party'),
('source_reference', 'Reference'),
('simulation_state', 'State'),
('source_debit', 'Debit'),
('source_credit', 'Credit'),
('source_balance', 'Balance'),
)
entity_columns = (
('title', 'Title'),
('getStopDate', 'Date'),
('reference', 'Invoice No'),
('getDestinationSectionTitle', 'Third Party'),
('source_reference', 'Reference'),
('simulation_state', 'State'),
('source_debit', 'Debit'),
('source_credit', 'Credit'),
('source_balance', 'Balance'),
)
for entity in entities :
result.append( ReportSection(path=context.getPhysicalPath(),
title='Bank accounts for %s'%entity.getTitle(),
level=1,
form_id=None) )
result.append(
ReportSection(
path=context.getPhysicalPath(),
title='Bank accounts for %s'%entity.getTitle(),
level=1,
form_id=None) )
for bank in entity.searchFolder(portal_type='Bank Account'):
o = bank.getObject()
o = bank.getObject()
result.append(
ReportSection(title='%s (%s)'%(o.getTitle(), entity.getTitle()),
level=2,
path=o.getPhysicalPath(),
form_id='BankAccount_viewAccountingTransactionList',
## XXX Here we must use accounting_selection, because stat scripts read this selection
selection_name = 'accounting_selection',
selection_params = params,
selection_columns = entity_columns
)
)
ReportSection(
title='%s (%s)'%(o.getTitle(), entity.getTitle()),
level=2,
path=o.getPhysicalPath(),
form_id='BankAccount_viewAccountingTransactionList',
## XXX Here we must use accounting_selection, because stat scripts read this selection
selection_name = 'accounting_selection',
selection_params = params,
selection_columns = entity_columns,))
return result
......@@ -17,10 +17,10 @@ if request.get('account_id_list_conversion_script_id'):
else:
kw['node_category'] = account_id_list
sum = 0.0
sum_ = 0.0
for inventory in portal.portal_simulation.getInventoryList(
group_by_node=1,
**kw):
if inventory.total_price < 0:
sum += (inventory.total_price or 0)
return sum
sum_ += (inventory.total_price or 0)
return sum_
......@@ -17,11 +17,11 @@ if request.get('account_id_list_conversion_script_id'):
else:
kw['node_category'] = account_id_list
sum = 0.0
sum_ = 0.0
for inventory in portal.portal_simulation.getInventoryList(
group_by_payment=1,
group_by_node=1,
**kw):
if inventory.total_price < 0:
sum += (inventory.total_price or 0)
return sum
sum_ += (inventory.total_price or 0)
return sum_
......@@ -17,10 +17,10 @@ if request.get('account_id_list_conversion_script_id'):
else:
kw['node_category'] = account_id_list
sum = 0.0
sum_ = 0.0
for inventory in portal.portal_simulation.getInventoryList(
group_by_node=1,
**kw):
if inventory.total_price > 0:
sum += inventory.total_price
return sum
sum_ += inventory.total_price
return sum_
......@@ -17,11 +17,11 @@ if request.get('account_id_list_conversion_script_id'):
else:
kw['node_category'] = account_id_list
sum = 0.0
sum_ = 0.0
for inventory in portal.portal_simulation.getInventoryList(
group_by_payment=1,
group_by_node=1,
**kw):
if inventory.total_price > 0:
sum += inventory.total_price
return sum
sum_ += inventory.total_price
return sum_
......@@ -142,18 +142,17 @@ 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, limit=2)
if brain_list:
brain, = brain_list
name = brain.getObject().getTitle()
title_for_uid_cache[uid] = name
return name
......
index = context.portal_selections.getSelectionIndexFor(selection_name)
object = brain.getObject()
object = object.getDestinationValue()
if object is None:
url = None
else:
url = object.absolute_url() + '/view?selection_index=%s&amp;selection_name=%s&amp;reset=1' % (index, selection_name)
return url
account = brain.getObject()
account = account.getDestinationValue()
if account is not None:
return '%s/view?selection_index=%s&amp;selection_name=%s&amp;reset=1' % (
account.absolute_url(), index, selection_name)
......@@ -25,14 +25,14 @@ if role_filter_list == [''] :
role_filter_list = None
section_uid = context.Base_getSectionUidListForSectionCategory(
request['section_category'],
request['section_category_strict'])
request['section_category'],
request['section_category_strict'])
result = []
params = {
'at_date' : at_date
, 'section_uid': section_uid
, 'simulation_state': simulation_state
'at_date': at_date,
'section_uid': section_uid,
'simulation_state': simulation_state
}
if from_date:
......@@ -59,16 +59,16 @@ if ledger:
simulation_tool = portal.portal_simulation
entity_columns = [
('date', 'Date'),
('Movement_getExplanationTranslatedPortalType', 'Type'),
('Movement_getNodeGapId', 'GAP'),
('Movement_getExplanationReference', 'Invoice No'),
('Movement_getExplanationTitle', 'Title'),
('Movement_getSpecificReference', 'Reference'),
('getTranslatedSimulationStateTitle', 'State'),
('debit_price', 'Debit'),
('credit_price', 'Credit'),
('running_total_price', 'Balance'),
('date', 'Date'),
('Movement_getExplanationTranslatedPortalType', 'Type'),
('Movement_getNodeGapId', 'GAP'),
('Movement_getExplanationReference', 'Invoice No'),
('Movement_getExplanationTitle', 'Title'),
('Movement_getSpecificReference', 'Reference'),
('getTranslatedSimulationStateTitle', 'State'),
('debit_price', 'Debit'),
('credit_price', 'Credit'),
('running_total_price', 'Balance'),
]
if not request['omit_grouping_reference']:
......
......@@ -2,16 +2,16 @@ from ZTUtils import make_query
from Products.PythonScripts.standard import html_quote
index = context.portal_selections.getSelectionIndexFor(selection_name)
object = brain.getObject()
account = brain.getObject()
# this is for domain_tree mode
if object.getPortalType() == "Category" :
return "#"
if account.getPortalType() == "Category":
return "#"
method = 'Account_viewAccountingTransactionList'
kw = { 'selection_index': str(index),
'selection_name' : selection_name,
'reset' : '1',
'selection_name' : selection_name,
'reset' : '1',
}
return html_quote('%s/%s?%s' % (object.absolute_url(), method, make_query(kw)))
return html_quote('%s/Account_viewAccountingTransactionList?%s' % (
account.absolute_url(), make_query(kw)))
portal = context.getPortalObject()
params = portal.ERP5Accounting_getParams(selection_name)
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name)
params['omit_asset_increase'] = omit_asset_increase
params['omit_asset_decrease'] = omit_asset_decrease
# For now, we omit simulation to be compatible with other reports.
params['omit_simulation'] = True
selection_domain = context.portal_selections.getSelectionDomainDictFor(selection_name)
selection_domain = portal.portal_selections.getSelectionDomainDictFor(selection_name)
if callable(selection_domain):
selection_domain = selection_domain()
selection_report = context.portal_selections.getSelectionReportDictFor(selection_name)
selection_report = portal.portal_selections.getSelectionReportDictFor(selection_name)
if selection_domain:
params['selection_domain'] = selection_domain
if selection_report:
......@@ -17,14 +17,14 @@ if selection_report:
if kw.get('closed_summary'):
params['closed_summary'] = kw['closed_summary']
if context.portal_selections.getSelectionInvertModeFor(selection_name):
params['node_uid'] = context.portal_selections.getSelectionInvertModeUidListFor(selection_name)
params['node_uid'] = portal.portal_selections.getSelectionInvertModeUidListFor(selection_name)
else:
selection_params = context.portal_selections.getSelectionParamsFor(selection_name)
selection_params = portal.portal_selections.getSelectionParamsFor(selection_name)
selection_params['ignore_unknown_columns'] = True
params['node_uid'] = [x.uid for x in
portal.portal_catalog(**selection_params)]
# Remove params used internally by ERP5Accounting_getParams before passing to inventory API
# Remove params used internally by ERP5Site_getAccountingSelectionParameterDict before passing to inventory API
params.pop("period_start_date", None)
params.pop("detailed_from_date_summary", None)
......
node_uid=None
if not account:
if (hasattr(context, 'getPortalType') and context.getPortalType() == 'Account') :
node_uid = context.getUid()
elif same_type(account, '') :
account = context.getPortalObject().restrictedTraverse(account)
node_uid = account.getUid()
ptype_translated_dict = {}
def translatePortalType(ptype) :
"""Translate portal_type without retrieving the object from ZODB."""
if not ptype_translated_dict.has_key(ptype) :
ptype_translated_dict[ptype] = context.Base_translateString(ptype)
return ptype_translated_dict[ptype]
section_uid = []
if section_category:
section_uid = context.Base_getSectionUidListForSectionCategory(
section_category, strict_membership=section_category_strict_membership)
item_list = [("", "")]
for entity in context.Account_zDistinctSectionList(node_uid=node_uid,
section_uid=section_uid):
item_list.append(("%s (%s)" % ( entity['title'],
translatePortalType(entity['portal_type'])),
entity['relative_url']))
return item_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>account=\'\', section_category=\'\', section_category_strict_membership=True</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Account_getDestinationSectionItemList</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>TODO: rename into AccountModule_getMirrorSectionItemList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -21,15 +21,14 @@ def display(x):
return display_cache[x]
def getGapItemList(only_preferred_gap, gap_root=None):
ctool = portal.portal_categories
if only_preferred_gap:
if gap_root:
return ctool.resolveCategory(gap_root).getCategoryChildItemList(
return portal.portal_categories.resolveCategory(gap_root).getCategoryChildItemList(
base=False, is_self_excluded=True, display_method=display,
local_sort_id=('int_index', 'reference', 'id'))
result = []
for country in ctool.gap.contentValues():
for country in portal.portal_categories.gap.contentValues():
for gap_root in country.contentValues():
result.extend(gap_root.getCategoryChildItemList(
base=False, is_self_excluded=True, display_method=display,
......
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
params = portal.ERP5Accounting_getParams(selection_name)
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name)
# this also prevents to be called directly
assert 'node_uid' in kw
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection=None, sort_on=[], node_category=None, node_category_strict_membership=None, from_date=None, selection_name=None, function=None, project_uid=None, analytic_column_list=(), **kw</string> </value>
<value> <string>selection=None, sort_on=(), node_category=None, node_category_strict_membership=None, from_date=None, selection_name=None, function=None, project_uid=None, analytic_column_list=(), **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
account = context
source_payment_set = {}
for line in account.Account_getAccountingTransactionList() :
movement_path = line.current_transaction_line_path
movement = context.restrictedTraverse(movement_path)
source_payment_set[movement.getSourcePayment()] = 1
# if movement.getSourcePayment() is None :
# context.log('Movement getSourcePayment None ', movement.getPath())
return source_payment_set.keys()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Account_getSourcePaymentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
Base_translateString = portal.Base_translateString
split_depth = 2
if default_sub_field_property_dict is None:
default_sub_field_property_dict = {}
def getSubFieldDict():
def getSubFieldDictCache():
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>item_list, value_list, default_sub_field_property_dict={}, is_right_display=0</string> </value>
<value> <string>item_list, value_list, default_sub_field_property_dict=None, is_right_display=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
from Products.ERP5Type.Message import translateString
try:
from zExceptions import Redirect
except:
Redirect = 'Redirect'
from zExceptions import Redirect
portal = context.getPortalObject()
stool = portal.portal_selections
getObject = portal.portal_catalog.getObject
countMessage = portal.portal_activities.countMessage
invoice_type_list = portal.getPortalInvoiceTypeList()
stool.updateSelectionCheckedUidList(selection_name, listbox_uid, uids)
selection_uid_list = context.portal_selections.getSelectionCheckedUidsFor(
portal.portal_selections.updateSelectionCheckedUidList(selection_name, listbox_uid, uids)
selection_uid_list = portal.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)
object_list = portal.portal_selections.callSelectionFor(selection_name)
# update selection params, because it'll be used in the selection dialog.
stool.setSelectionParamsFor('accounting_create_related_payment_selection',
portal.portal_selections.setSelectionParamsFor('accounting_create_related_payment_selection',
params=dict(node_for_related_payment=node,
payment_mode_for_related_payment=payment_mode,
payment_for_related_payment=payment))
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>node, payment_mode, payment, selection_index=None, uids=[], listbox_uid=[],selection_name=\'\', **kw</string> </value>
<value> <string>node, payment_mode, payment, selection_index=None, uids=(), listbox_uid=(),selection_name=\'\', **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
from Products.ERP5Type.Message import translateString
try:
from zExceptions import Redirect
except:
Redirect = 'Redirect'
from zExceptions import 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(
portal.portal_selections.updateSelectionCheckedUidList(selection_name, listbox_uid, uids)
selection_uid_list = portal.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)
object_list = portal.portal_selections.callSelectionFor(selection_name)
# XXX prevent to call this on the whole module:
if len(object_list) >= 1000:
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>cancellation_amount=False, date=None, plan=False, uids=[], listbox_uid=[], selection_name=\'\', form_id=\'view\', **kw</string> </value>
<value> <string>cancellation_amount=False, date=None, plan=False, uids=(), listbox_uid=(), selection_name=\'\', form_id=\'view\', **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -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
......
from Products.ERP5Form.Report import ReportSection
portal = context.getPortalObject()
request = container.REQUEST
selection_columns = (
('title', 'Title',),
......@@ -20,7 +18,7 @@ selection_columns = (
('mirror_payment_title', 'Third Party Bank Account',),
('mirror_section_region_title', 'Third Party Region',),
('function_reference',
'%s Reference' % context.AccountingTransactionLine_getFunctionBaseCategoryTitle()),
'%s Reference' % context.AccountingTransactionLine_getFunctionBaseCategoryTitle()),
('function_title',
context.AccountingTransactionLine_getFunctionBaseCategoryTitle()),
('funding_reference', 'Funding Reference',),
......
from Products.ERP5Type.Message import translateString
from Products.ERP5Form.Report import ReportSection
portal = context.getPortalObject()
request = container.REQUEST
section_category = request['section_category']
section_category_strict = request['section_category_strict']
......@@ -55,7 +54,7 @@ ledger = request.get('ledger', None)
if ledger:
selection_params['ledger'] = ledger
return [ReportSection(form_id=(detailed and
return [ReportSection(form_id=(detailed and
'AccountingTransactionModule_viewDetailedAgedBalanceReportSection' or
'AccountingTransactionModule_viewSummaryAgedBalanceReportSection'),
path=context.getPhysicalPath(),
......
......@@ -26,13 +26,17 @@ 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, limit=2)
if brain_list:
brain, = brain_list
section_title = brain.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
......@@ -111,7 +111,7 @@ for brain in portal.portal_simulation.getMovementHistoryList(
debit=debit,
credit=credit,)
analytic_info = {}
for analytic_column, analytic_column_title in analytic_column_list:
for analytic_column, analytic_column_title in analytic_column_list: # pylint: disable=unused-variable
if analytic_column == 'project':
analytic_info['project'] = brain.Movement_getProjectTitle()
elif analytic_column == 'funding':
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection, at_date, from_date, portal_type, simulation_state, section_uid, payment_mode=None, payment=None, gap_root=None, group_by=None, analytic_column_list=[], project_uid=None, ledger_uid=None, **kw</string> </value>
<value> <string>selection, at_date, from_date, portal_type, simulation_state, section_uid, payment_mode=None, payment=None, gap_root=None, group_by=None, analytic_column_list=(), project_uid=None, ledger_uid=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
from Products.PythonScripts.standard import Object
request = container.REQUEST
portal = context.getPortalObject()
return [ Object(
debit=request.get(
......
......@@ -8,7 +8,7 @@ detail_line_list = portal\
simulation_state, period_list, account_type, detail=False, **kw)
period_id_list = ['period_future']
for idx, period in enumerate(period_list):
for idx, _ in enumerate(period_list):
period_id_list.append('period_%s' % idx)
period_id_list.append('period_%s' % (idx + 1))
......
......@@ -2,8 +2,6 @@ from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery, ComplexQuery
request = container.REQUEST
portal = context.getPortalObject()
ctool = portal.portal_catalog
stool = portal.portal_simulation
# we use a different selection for dialog params, because we never want this
# selection to be reseteted
......@@ -77,7 +75,7 @@ if debit_price:
if credit_price:
try:
search_kw['stock.total_price'] = - float(credit_price['query'])
except ValueError, e:
except ValueError:
# happens when user entered a complex query (like "> 100 AND < 200")
# in that case, there is not much we can do.
search_kw['stock.total_price'] = credit_price['query']
......@@ -85,7 +83,7 @@ if date:
search_kw['stock.date'] = date
return stool.getMovementHistoryList(
return portal.portal_simulation.getMovementHistoryList(
section_uid=section_uid,
simulation_state=['stopped', 'delivered'],
sort_on=sort_on,
......
"""Set grouping reference for selected lines.
Used as a fast input dialog action.
"""
from ZTUtils import make_query
from ZODB.POSException import ConflictError
from Products.CMFCore.WorkflowCore import WorkflowException
portal = context.getPortalObject()
getobject = portal.portal_catalog.getobject
stool = portal.portal_selections
Base_translateString = portal.Base_translateString
psm = Base_translateString('Nothing matches.')
request = container.REQUEST
precision = request.get('precision', 2)
# update selected uids
stool.updateSelectionCheckedUidList(
portal.portal_selections.updateSelectionCheckedUidList(
list_selection_name, uids=uids, listbox_uid=listbox_uid, REQUEST=request)
uids = stool.getSelectionCheckedUidsFor(list_selection_name)
uids = portal.portal_selections.getSelectionCheckedUidsFor(list_selection_name)
# XXX when should it be validated ?
if node == '':
......@@ -37,8 +33,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:
......@@ -59,7 +55,7 @@ if grouping == 'grouping':
mapping=dict(grouped_line_count=len(grouped_line_list)))
# make sure nothing will be checked next time
stool.setSelectionCheckedUidsFor(list_selection_name, [])
portal.portal_selections.setSelectionCheckedUidsFor(list_selection_name, [])
# we check if we can mark some transaction as payed.
transaction_list = {}
......@@ -103,9 +99,7 @@ if grouping == 'grouping':
try:
portal.portal_workflow.doActionFor(transaction, 'clear_action',
payment_date=date)
except ConflictError:
raise
except:
except WorkflowException:
# Workflow action not supported
pass
......@@ -113,18 +107,20 @@ 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)))
# make sure nothing will be checked next time
stool.setSelectionCheckedUidsFor(list_selection_name, [])
portal.portal_selections.setSelectionCheckedUidsFor(list_selection_name, [])
request.set('portal_status_message', psm)
return context.AccountingTransactionModule_viewGroupingFastInputDialog(request)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>uids=[], listbox=None, listbox_uid=[], list_selection_name=\'\', grouping=\'\', node=\'\', mirror_section=\'\', update=0, **kw</string> </value>
<value> <string>uids=(), listbox=None, listbox_uid=(), list_selection_name=\'\', grouping=\'\', node=\'\', mirror_section=\'\', update=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
params = context.portal_selections.getSelectionParamsFor(selection_name)
params['stat'] = 1
params['omit_input'] = 1
params['omit_output'] = 0
if (params.get('operation_date') or {}).get('query'):
buildSQLQuery = context.portal_catalog.buildSQLQuery
params['source_section_where_expression'] = buildSQLQuery(
**{'delivery.start_date': params['operation_date']})['where_expression']
params['destination_section_where_expression'] = buildSQLQuery(
**{'delivery.stop_date': params['operation_date']})['where_expression']
del params['operation_date']
result = context.AccountingTransactionModule_zGetAccountingTransactionList(
selection=selection,
selection_params=params, **params)
row = result[0]
return float('%.02f' % (row.total_price and - row.total_price or 0.0))
# vim: syntax=python
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection=None, selection_name=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransactionModule_statSourceCredit</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
params = context.portal_selections.getSelectionParamsFor(selection_name)
params['stat'] = 1
params['omit_output'] = 1
params['omit_input'] = 0
if (params.get('operation_date') or {}).get('query'):
buildSQLQuery = context.portal_catalog.buildSQLQuery
params['source_section_where_expression'] = buildSQLQuery(
**{'delivery.start_date': params['operation_date']})['where_expression']
params['destination_section_where_expression'] = buildSQLQuery(
**{'delivery.stop_date': params['operation_date']})['where_expression']
del params['operation_date']
result = context.AccountingTransactionModule_zGetAccountingTransactionList(
selection=selection, selection_params = params, **params)
row = result[0]
return float('%.02f' % (row.total_price or 0.0))
# vim: syntax=python
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection=None, selection_name=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransactionModule_statSourceDebit</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>uids=[], listbox=None, listbox_uid=[], list_selection_name=\'\', node=\'\', mirror_section=\'\', cancel_url=\'\', **kw</string> </value>
<value> <string>uids=(), listbox=None, listbox_uid=(), list_selection_name=\'\', node=\'\', mirror_section=\'\', cancel_url=\'\', **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -5,7 +5,7 @@ use.
from Products.ERP5Type.Message import translateString
request = container.REQUEST
for i in range(line_count):
for _ in range(line_count):
context.newContent(portal_type=line_portal_type)
request.set('portal_status_message',
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>portal_type=[], **kw</string> </value>
<value> <string>portal_type=(), **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -12,7 +12,6 @@ from Products.ERP5Type.Utils import int2letter
lines_per_node = {}
portal = context.getPortalObject()
ctool = portal.portal_catalog
allow_grouping_with_different_quantity = portal.portal_preferences.getPreference(
'preferred_grouping_with_different_quantities', 0)
......@@ -31,8 +30,9 @@ if accounting_transaction_line_uid_list is None:
continue
accounting_transaction_line_value_list.append(line)
else:
accounting_transaction_line_value_list = [ctool.getObject(uid) for uid in
accounting_transaction_line_uid_list]
if accounting_transaction_line_uid_list:
accounting_transaction_line_value_list = [
brain.getObject() for brain in portal.portal_catalog(uid=accounting_transaction_line_uid_list)]
for line in accounting_transaction_line_value_list:
accounting_transaction = line.getParentValue()
......
......@@ -3,12 +3,12 @@ section_value = context.getDestinationSectionValue()
if section_value is None or \
section_value.getProperty('price_currency', None) is None:
# If no section defined, no way to convert currencies
return 0
return False
transaction_currency = context.getResource()
if transaction_currency is not None and\
transaction_currency != section_value.getProperty('price_currency', None):
return 1
return True
for line in context.getMovementList(
portal_type=context.getPortalAccountingMovementTypeList()):
......@@ -16,6 +16,6 @@ for line in context.getMovementList(
line.getDestinationInventoriatedTotalAssetCredit()) or (
line.getDestinationDebit() !=
line.getDestinationInventoriatedTotalAssetDebit())):
return 1
return True
return 0
return False
......@@ -3,12 +3,12 @@ section_value = context.getSourceSectionValue()
if section_value is None or \
section_value.getProperty('price_currency', None) is None:
# If no section defined, no way to convert currencies
return 0
return False
transaction_currency = context.getResource()
if transaction_currency is not None and\
transaction_currency != section_value.getProperty('price_currency', None):
return 1
return True
for line in context.getMovementList(
portal_type=context.getPortalAccountingMovementTypeList()):
......@@ -16,6 +16,6 @@ for line in context.getMovementList(
line.getSourceInventoriatedTotalAssetCredit()) or (
line.getSourceDebit() !=
line.getSourceInventoriatedTotalAssetDebit())):
return 1
return True
return 0
return False
......@@ -11,9 +11,9 @@ def getAccountingPeriodStartDateForSectionCategory(section_category, date):
section_category, strict_membership=False))
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)
for ap in section.contentValues(portal_type='Accounting Period',
if uid == -1: continue # Base_getSectionUidListForSectionCategory returns [-1] if no section_uid exists
section, = portal.portal_catalog(uid=uid, limit=2)
for ap in section.getObject().contentValues(portal_type='Accounting Period',
checked_permission='Access contents information'):
if ap.getSimulationState() not in ('planned', 'confirmed',
'started', 'stopped',
......
......@@ -32,7 +32,7 @@ def getCurrencyForSection(section_url):
# otherwise, lookup all groups top down until we find one currency
for subsection in section.getCategoryChildValueList(local_sort_id='int_index'):
member_list = section.getGroupRelatedValueList(portal_type='Organisation',
member_list = subsection.getGroupRelatedValueList(portal_type='Organisation',
strict_membership=True,
checked_permission='View')
for member in member_list:
......
......@@ -10,8 +10,8 @@ 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)
currency = section.getPriceCurrency()
section, = portal.portal_catalog(uid=section_uid, limit=2)
currency = section.getObject().getPriceCurrency()
if currency:
currency_set.add(currency)
if len(currency_set) == 1:
......
......@@ -38,13 +38,12 @@ def splitCsvLine(str_line):
return clean_list
def getSubCategory(parent, id):
def getSubCategory(parent, category_id):
try:
return parent[id]
return parent[category_id]
except KeyError:
return parent.newContent(id=id)
return parent.newContent(id=category_id)
request = context.REQUEST
csv_file_line_list = import_file.readlines()
csv_line_list = []
......@@ -54,18 +53,16 @@ for csv_line in csv_file_line_list:
object_list = []
csv_property_list = splitCsvLine(csv_line_list[0])
csv_title_list = splitCsvLine(csv_line_list[1])
for csv_line in csv_line_list[2:]:
object = {}
property_dict = {}
csv_data_list = splitCsvLine(csv_line)
data_n = 0
for property in csv_property_list:
object[property] = csv_data_list[data_n]
for property_ in csv_property_list:
property_dict[property_] = csv_data_list[data_n]
data_n += 1
object_list.append(object)
object_list.append(property_dict)
root = context.getPortalObject().portal_categories
for path in gap_root_path.split('/'):
......@@ -74,10 +71,10 @@ for path in gap_root_path.split('/'):
existing_path_list = recursiveDocumentList(root)
existing_path_list.remove(root.getPath())
for object in object_list:
description = object.get('Description', None) or ''
gap = object.get('Gap', None) or ''
title = object.get('Title', None) or ''
for property_dict in object_list:
description = property_dict.get('Description', None) or ''
gap = property_dict.get('Gap', None) or ''
title = property_dict.get('Title', None) or ''
gap = str(gap)
if gap:
gap = gap.replace('CLASSE ', '')
......@@ -95,11 +92,11 @@ for object in object_list:
existing_path_list.sort(key=len, reverse=True)
for path in existing_path_list:
object = context.restrictedTraverse(path)
description = object.getDescription() or ''
gap = object.getId() or ''
title = object.getTitle() or ''
document = context.restrictedTraverse(path)
description = document.getDescription() or ''
gap = document.getId() or ''
title = document.getTitle() or ''
print '- %s - %s - %s' % (gap or '', title or '', description or '')
object.getParentValue().deleteContent(object.getId())
document.getParentValue().deleteContent(document.getId())
return printed
......@@ -4,9 +4,10 @@ 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, limit=2)
if brain_list:
brain, = brain_list
mirror_section_title = brain.getObject().getTitle()
request.other[context.mirror_section_uid] = mirror_section_title
return mirror_section_title
......@@ -4,9 +4,10 @@ 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, limit=2)
if brain_list:
brain, = brain_list
payment_title = brain.getObject().getTitle()
request.other[context.payment_uid] = payment_title
return payment_title
......@@ -4,9 +4,10 @@ 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, limit=2)
if brain_list:
brain, = brain_list
project_title = brain.getObject().getTitle()
request.other[context.project_uid] = project_title
return project_title
......@@ -12,7 +12,7 @@ caveats:
# do we have a cache already?
if not ignore_cache:
params_cache = context.REQUEST.other.get(
'ERP5Accounting_getParams', None)
'ERP5Site_getAccountingSelectionParameterDict', None)
if params_cache is not None:
# return a copy
return dict(params_cache)
......@@ -113,5 +113,5 @@ else:
params['parent_portal_type'] = parent_portal_type
if not ignore_cache:
context.REQUEST.other['ERP5Accounting_getParams'] = params
context.REQUEST.other['ERP5Site_getAccountingSelectionParameterDict'] = params
return dict(params)
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Accounting_getParams</string> </value>
<value> <string>ERP5Site_getAccountingSelectionParameterDict</string> </value>
</item>
</dictionary>
</pickle>
......
if None not in (brain, selection):
try:
account_uid = brain.account_uid
except AttributeError:
account_uid = None
if account_uid != None:
account = context.portal_catalog.getObject(account_uid)
if account != None:
return account.Account_getGapId()
return None
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>brain=None, selection=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Entity_getAccountingTransactionGapId</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -11,8 +11,6 @@ if person is None:
from DateTime import DateTime
now = DateTime()
destination_group = section_group = None
assigned_group_set = set() # groups on which the user is assigned
for assignment in person.contentValues(portal_type='Assignment'):
if assignment.getGroup() \
......
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InternalInvoice_getAuthenticatedUserSection</string> </value>
<value> <string>InternalInvoiceTransaction_getAuthenticatedUserSection</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -10,7 +10,6 @@ Base_translateString = context.Base_translateString
if date is None:
date = DateTime()
portal = context.getPortalObject()
payment_dict = {}
is_source = context.AccountingTransaction_isSourceView()
line_portal_type = 'Accounting Transaction Line'
......@@ -58,12 +57,10 @@ related_payment = portal.accounting_module.newContent(
if is_source:
related_payment.edit(destination_payment=context.getDestinationPayment(),
source_payment=payment)
section = context.getSourceSection()
mirror_section = context.getDestinationSection()
else:
related_payment.edit(destination_payment=payment,
source_payment=context.getSourcePayment())
section = context.getDestinationSection()
mirror_section = context.getSourceSection()
bank = related_payment.newContent(
......@@ -77,30 +74,29 @@ for (line_node, line_mirror_section), quantity in\
if line_mirror_section == mirror_section:
bank_quantity += quantity
if is_source:
line = related_payment.newContent(
related_payment.newContent(
portal_type=line_portal_type,
source=line_node,
quantity=quantity)
else:
line = related_payment.newContent(
related_payment.newContent(
portal_type=line_portal_type,
destination=line_node,
quantity=-quantity)
if is_source:
bank.edit( source=node,
quantity=-bank_quantity )
bank.setSource(node)
bank.setQuantity(-bank_quantity)
else:
bank.edit( destination=node,
quantity=bank_quantity )
bank.setDestination(node)
bank.setQuantity(bank_quantity)
if plan:
related_payment.plan()
if not batch_mode:
return context.REQUEST.RESPONSE.redirect(
"%s/view?portal_status_message=%s" % (
related_payment.absolute_url(),
Base_translateString('Related payment created.')))
else:
return related_payment
return related_payment.Base_redirect(
'view',
keep_items={'portal_status_message': Base_translateString('Related payment created.')})
return related_payment
......@@ -59,7 +59,7 @@ def getIsSourceMovementItemList(invoice):
btt_is_source = btt.AccountingTransaction_isSourceView()
for btt_movement in btt.getMovementList(
portal_type=portal.getPortalAccountingMovementTypeList()):
movement_item_list.append((btt_is_source, btt_movement))
movement_item_list.append((btt_is_source, btt_movement))
return movement_item_list
......@@ -71,7 +71,6 @@ for is_source, line in getIsSourceMovementItemList(context):
if is_source:
node_value = line.getSourceValue(portal_type='Account')
line_section = line.getSourceSection()
mirror_section = line.getDestinationSection()
if quantity:
amount = -line.getQuantity()
......@@ -79,7 +78,6 @@ for is_source, line in getIsSourceMovementItemList(context):
amount = line.getSourceInventoriatedTotalAssetPrice() or 0
else:
node_value = line.getDestinationValue(portal_type='Account')
line_section = line.getDestinationSection()
mirror_section = line.getSourceSection()
if quantity:
amount = line.getQuantity()
......@@ -88,7 +86,7 @@ for is_source, line in getIsSourceMovementItemList(context):
if at_date is None and line.getGroupingReference():
continue
if node_value is not None:
if account_id is not None and node_value.getId() not in account_id:
continue
......@@ -110,7 +108,7 @@ for related_transaction in related_transaction_list:
continue
if related_transaction.getProperty('origin_id') == 'MAJO':
continue
# if we have a payment related to multiple invoices, we cannot say the
# remaining price on those invoices.
for other_invoice in [ tr for tr in related_transaction.getCausalityValueList(
......@@ -128,18 +126,18 @@ for related_transaction in related_transaction_list:
else:
other_invoice_line_account = other_line.getDestinationValue()
other_invoice_line_mirror_section = other_line.getSourceSection()
if other_invoice_line_account in accounts_in_context:
# unless this line is for another mirror_section, we cannot calculate
if mirror_section_relative_url is None or \
other_invoice_line_mirror_section == mirror_section_relative_url:
raise ValueError('Unable to calculate %s' % context.getPath())
related_transaction_is_source = related_transaction.\
AccountingTransaction_isSourceView()
for line in related_transaction.getMovementList(
portal_type=portal.getPortalAccountingMovementTypeList()):
if at_date is None and line.getGroupingReference():
continue
......@@ -148,10 +146,9 @@ for related_transaction in related_transaction_list:
raise ValueError("Unable to calculate"
", related transaction %s uses different currency" %
line.getRelativeUrl())
if related_transaction_is_source:
node_value = line.getSourceValue(portal_type='Account')
line_section = line.getSourceSection()
mirror_section = line.getDestinationSection()
if quantity:
amount = -line.getQuantity()
......@@ -160,14 +157,13 @@ for related_transaction in related_transaction_list:
date = line.getStartDate().earliestTime()
else:
node_value = line.getDestinationValue(portal_type='Account')
line_section = line.getDestinationSection()
mirror_section = line.getSourceSection()
if quantity:
amount = line.getQuantity()
else:
amount = line.getDestinationInventoriatedTotalAssetPrice() or 0
date = line.getStopDate().earliestTime()
if node_value is not None:
if account_id is not None and node_value.getId() not in account_id:
continue
......@@ -185,7 +181,7 @@ if detailed:
else:
if mirror_section_relative_url:
total_amount = 0
for (node, mirror_section), amount in total_payable_price_per_node_section.items():
for (node, mirror_section), amount in total_payable_price_per_node_section.items(): # pylint: disable=unused-variable
if mirror_section == mirror_section_relative_url:
total_amount += amount
return total_amount
......
......@@ -10,7 +10,7 @@ else:
analytic_property_list = [explanation.getReference()]
for property_name, property_title in request['analytic_column_list']:
for property_name, property_title in request['analytic_column_list']: #pylint: disable=unused-variable
# XXX it would be a little better to reuse editable field
if property_name == 'project':
analytic_property_list.append(brain.Movement_getProjectTitle())
......
if brain.payment_uid:
bank_account = context.getPortalObject().portal_catalog.getObject(brain.payment_uid)
if bank_account is not None:
brain_list = context.getPortalObject().portal_catalog(uid=brain.payment_uid, limit=2)
if brain_list:
brain, = brain_list
bank_account = brain.getObject()
# XXX use preference ?
if bank_account.getReference():
return '%s - %s' % (bank_account.getReference(), bank_account.getTitle())
......
# Example code:
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE
# Return a string identifying this script.
print "This is the", script.meta_type, '"%s"' % script.getId(),
if script.title:
print "(%s)" % html_quote(script.title),
print "in", container.absolute_url()
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Movement_statBalance</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -4,7 +4,7 @@ from Products.ERP5Type.Message import translateString
from Products.ERP5Type.Log import log
portal = context.getPortalObject()
request = portal.REQUEST
params = portal.ERP5Accounting_getParams(selection_name=selection_name)
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name=selection_name)
if params.get('precision', None) is not None:
# listbox editable float fields uses request/precision to format the value.
......@@ -72,14 +72,13 @@ 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'], limit=2)
node = node.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 +196,16 @@ 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'])
previous_balance.edit(
mirror_section_title=mirror_section.getTitle()
)
section = portal.portal_catalog.getObject(section_uid)
brain_list = portal.portal_catalog(uid=params['mirror_section_uid'], limit=2)
if brain_list:
brain, = brain_list
previous_balance.edit(
mirror_section_title=brain.getObject().getTitle()
)
# It may happen that user cannot search mirror section from catalog,
# but our own section should be found.
section, = portal.portal_catalog(uid=section_uid, limit=2)
section = section.getObject()
previous_balance.edit(
Movement_getSectionPriceCurrency=section.getPriceCurrencyReference(),
resource_reference=section.getPriceCurrencyReference(),
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>selection=None, sort_on=[], node_category=None, node_category_strict_membership=None, mirror_section_category=None, from_date=None, selection_name=None, src__=0, **kw</string> </value>
<value> <string>selection=None, sort_on=(), node_category=None, node_category_strict_membership=None, mirror_section_category=None, from_date=None, selection_name=None, src__=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery, ComplexQuery
from Products.ZSQLCatalog.SQLCatalog import Query
portal = context.getPortalObject()
params = portal.ERP5Accounting_getParams(selection_name=selection_name)
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name=selection_name)
getSelectionDomainDictFor = context.portal_selections.getSelectionDomainDictFor
if asset_price:
......@@ -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'], limit=2)
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
......
......@@ -269,7 +269,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(\'\', \'\')] + [(x.getTitle(), x.getRelativeUrl()) for x in context.portal_catalog( default_group_uid=context.portal_categories.getCategoryUid(context.getPreferredAccountingTransactionSectionCategory(\'portal_categories\')), portal_type=\'Organisation\', validation_state=\'Validated\')]</string> </value>
<value> <string>python: [(\'\', \'\')] + [(x.getTitle(), x.getRelativeUrl()) for x in context.portal_catalog( default_group_uid=context.portal_categories.getCategoryUid(context.getPreferredAccountingTransactionSectionCategory(\'portal_categories\')), portal_type=\'Organisation\', validation_state=\'validated\')]</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -2,7 +2,6 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type.Message import translateString
closing_period = state_change['object']
portal = closing_period.getPortalObject()
valid_state_list = ['started', 'stopped', 'delivered']
closing_period.Base_checkConsistency()
......@@ -25,7 +24,7 @@ for period in period_list:
raise ValidationFailed, translateString(
"${date} is already in an open accounting period.",
mapping={'date': start_date})
if len(period_list) > 1:
last_period = period_list[-1].getObject()
if last_period.getId() == closing_period.getId():
......
......@@ -4,7 +4,7 @@ from Products.ERP5Type.Message import translateString
internal_invoice = state_change['object']
old_state = state_change['old_state']
if old_state.getId() == 'draft':
if internal_invoice.InternalInvoice_getAuthenticatedUserSection() == internal_invoice.getDestinationSection():
if internal_invoice.InternalInvoiceTransaction_getAuthenticatedUserSection() == internal_invoice.getDestinationSection():
raise ValidationFailed(translateString("Your entity should not be destination."))
return state_change.getPortal().portal_workflow.accounting_workflow.scripts[script.getId()](state_change)
......@@ -113,7 +113,7 @@
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>object/InternalInvoice_getAuthenticatedUserSection</string> </value>
<value> <string>object/InternalInvoiceTransaction_getAuthenticatedUserSection</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -112,7 +112,7 @@
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>object/InternalInvoice_getAuthenticatedUserSection</string> </value>
<value> <string>object/InternalInvoiceTransaction_getAuthenticatedUserSection</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -45,28 +45,27 @@ if pref.getPreferenceState() == 'disabled':
pref.enable()
# reset selections
stool = context.getPortalObject().portal_selections
for form in context.getPortalObject().portal_skins\
.erp5_accounting.objectValues(spec=('ERP5 Form',)):
listbox = getattr(form, 'listbox', None)
if listbox is not None:
stool.setSelectionFor(listbox.get_value('selection_name'), None)
portal.portal_selections.setSelectionFor(listbox.get_value('selection_name'), None)
# also reset common selections
stool.setSelectionFor('person_selection', None)
stool.setSelectionFor('organisation_selection', None)
stool.setSelectionFor('grouping_reference_fast_input_selection', None)
stool.setSelectionFor('accounting_transaction_module_grouping_reference_fast_input', None)
stool.setSelectionFor('entity_transaction_selection', None)
stool.setSelectionFor('account_module_selection', None)
portal.portal_selections.setSelectionFor('person_selection', None)
portal.portal_selections.setSelectionFor('organisation_selection', None)
portal.portal_selections.setSelectionFor('grouping_reference_fast_input_selection', None)
portal.portal_selections.setSelectionFor('accounting_transaction_module_grouping_reference_fast_input', None)
portal.portal_selections.setSelectionFor('entity_transaction_selection', None)
portal.portal_selections.setSelectionFor('account_module_selection', None)
# set sort order on accounting module
stool.setSelectionParamsFor('accounting_selection', {}) # (this recreates selection)
stool.setSelectionSortOrder('accounting_selection', sort_on=(('operation_date', 'ascending'),))
portal.portal_selections.setSelectionParamsFor('accounting_selection', {}) # (this recreates selection)
portal.portal_selections.setSelectionSortOrder('accounting_selection', sort_on=(('operation_date', 'ascending'),))
# set sort order and columns on account module
stool.setSelectionParamsFor('account_module_selection', {}) # (this recreates selection)
stool.setSelectionSortOrder('account_module_selection', sort_on=(('preferred_gap_id', 'ascending'),))
stool.setSelectionColumns('account_module_selection',
portal.portal_selections.setSelectionParamsFor('account_module_selection', {}) # (this recreates selection)
portal.portal_selections.setSelectionSortOrder('account_module_selection', sort_on=(('preferred_gap_id', 'ascending'),))
portal.portal_selections.setSelectionColumns('account_module_selection',
[('preferred_gap_id', 'GAP Number'),
('translated_title', 'Account Name'),
('translated_validation_state_title', 'State'),
......
......@@ -36,6 +36,7 @@ from DateTime import DateTime
from Products.CMFCore.utils import _checkPermission
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.CodingStyleTestCase import CodingStyleTestCase
from Products.ERP5Type.tests.utils import reindex
from Products.DCWorkflow.DCWorkflow import ValidationFailed
from AccessControl.SecurityManagement import newSecurityManager
......@@ -4159,27 +4160,6 @@ class TestTransactions(AccountingTestCase):
self.assertEqual(500, accounting_transaction.AccountingTransaction_getTotalDebit())
self.assertEqual(400, accounting_transaction.AccountingTransaction_getTotalCredit())
def test_Account_getDestinationSectionItemList(self):
organisation1 = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Organisation 1')
organisation2 = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Organisation 2')
self._makeOne(
portal_type='Sale Invoice Transaction',
simulation_state='delivered',
destination_section_value=organisation1,
start_date=DateTime(2006, 2, 2),
lines=(dict(source_value=self.portal.account_module.receivable,
source_debit=100),
dict(source_value=self.portal.account_module.goods_sales,
source_credit=100.00)))
self.assertEqual([('', ''),
('Organisation 1 (Organisation)',
organisation1.getRelativeUrl())],
self.portal.Account_getDestinationSectionItemList())
def test_AccountingTransaction_getListBoxColumnList_does_not_enable_section_column_when_only_two_sections(self):
# AccountingTransaction_getListBoxColumnList is the script returning the
# columns to display in AccountingTransaction_view.
......@@ -5802,7 +5782,23 @@ class TestInternalInvoiceTransaction(AccountingTestCase):
internal_invoice, 'stop_action')
self.assertEqual('stopped', internal_invoice.getSimulationState())
class TestAccountingCodingStyle(CodingStyleTestCase, AccountingTestCase):
"""Runs CodingStyleTestCase checks on erp5_accounting
"""
def getBusinessTemplateList(self):
# include administration for test_PythonSourceCode
return AccountingTestCase.getBusinessTemplateList(self) + (
'erp5_administration', )
def getTestedBusinessTemplateList(self):
return ('erp5_accounting', )
def beforeTearDown(self):
# we don't want to run AccountingTestCase.tearDown
pass
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAccountingWithSequences))
......@@ -5813,4 +5809,5 @@ def test_suite():
suite.addTest(unittest.makeSuite(TestAccountingExport))
suite.addTest(unittest.makeSuite(TestAccountingTransactionTemplate))
suite.addTest(unittest.makeSuite(TestInternalInvoiceTransaction))
suite.addTest(unittest.makeSuite(TestAccountingCodingStyle))
return suite
......@@ -3620,7 +3620,7 @@ class TestImmobilisation(TestImmobilisationMixin):
self.assertEqual('group/group B',
preference_tool.getPreferredAccountingTransactionSectionCategory())
# Make sure to not use the cache
self.portal.REQUEST['ERP5Accounting_getParams'] = None
self.portal.REQUEST['ERP5Site_getAccountingSelectionParameterDict'] = None
self.assertEqual(5000.0,account.AccountModule_getTotalSourceDebit(brain=account))
self.assertEqual(0.0,account.AccountModule_getTotalSourceCredit(brain=account))
......
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