Commit afe46492 authored by Jérome Perrin's avatar Jérome Perrin

accounting: rework Organisation_getMappingRelatedOrganisation ( WIP )

This script was returning organisations in random order !

When organisation does not have accounting periods, but another organisation at the same level of the same group has, the result was undefined.

This fixes by considering all organisation from the same group.
parent bc65bd81
"""Returns the main organisation for that group.
"""
if len(context.contentValues(filter=
dict(portal_type='Accounting Period'))) or context.getMapping():
return context
"""Returns the "main organisation" for that group, from accounting point of view.
def getOrganisationForSectionCategory(section):
mapping = section.getMappingRelatedValue(portal_type='Organisation',
checked_permission='Access contents information')
if mapping is not None:
return mapping
Other organisation from this group are considered subsidiaries and have same
accounting periods as the main organisation. This is also used for invoice reconciliation.
organisation_list = section.getGroupRelatedValueList(portal_type='Organisation',
strict_membership=1,
checked_permission='Access contents information')
XXX: the name of this script should include something "Accounting"
TODO: unify with Base_getAccountingPeriodStartDateForSectionCategory
"""
portal = context.getPortalObject()
for organisation in organisation_list:
if organisation.getProperty('validation_state', 'unset') not in ('deleted', 'invalidated'):
return organisation
def isMainOrganisation(organisation):
return bool(organisation.contentValues(
portal_type='Accounting Period',
checked_permission='Access contents information'))
if isMainOrganisation(context):
return context
group = context.getGroupValue()
if group is None:
return context
group_chain = []
while group.getPortalType() != 'Base Category':
group_chain.append(group)
section_uid_list = portal.Base_getSectionUidListForSectionCategory(
section_category=group.getRelativeUrl(),
strict_membership=True)
if -1 in section_uid_list:
section_uid_list.remove(-1) # XXX explain this
if section_uid_list:
for brain in portal.portal_catalog(uid=section_uid_list):
section = brain.getObject()
if isMainOrganisation(section):
return section
group = group.getParentValue()
for group in group_chain:
organisation = getOrganisationForSectionCategory(group)
if organisation is not None and (
len(organisation.contentValues(
filter=dict(portal_type='Accounting Period'))) or
organisation.getMapping()):
return organisation
return context
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