Commit 8fbd61f5 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 45b2a6fd
"""Returns the main organisation for that group.
"""Returns the "main organisation" for that group, from accounting point of view.
Other organisation from this group are considered subsidiaries and have same
accounting periods as the main organisation. This is also used for invoice reconciliation.
XXX: the name of this script should include something "Accounting"
TODO: unify with Base_getAccountingPeriodStartDateForSectionCategory
"""
portal = context.getPortalObject()
def isMainOrganisation(organisation):
return bool(organisation.contentValues(
portal_type='Accounting Period',
checked_permission='Access contents information'))
if len(context.contentValues(filter=
dict(portal_type='Accounting Period'))) or context.getMapping():
if isMainOrganisation(context):
return context
def getOrganisationForSectionCategory(section):
......@@ -24,9 +35,17 @@ 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:
......
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