Commit 8fc469ee authored by Jérome Perrin's avatar Jérome Perrin

accounting: rework Organisation_getMappingRelatedOrganisation ( WIP )

TODO:

 * [ ] file as bug
 * [ ] unify implementation with Base_getAccountingPeriodStartDateForSectionCategory
 * [ ] MR for nexedi/erp5
 * [ ] capago: stop creating accounting period for durban in `ERP5Site_openCapagoAccountingPeriod`, this was just hiding the bug

/reviewed-on https://lab.nexedi.com/nexedi/erp5-capago/merge_requests/20
parents bc65bd81 afe46492
"""Returns the main organisation for that group. """Returns the "main organisation" for that group, from accounting point of view.
"""
if len(context.contentValues(filter= Other organisation from this group are considered subsidiaries and have same
dict(portal_type='Accounting Period'))) or context.getMapping(): accounting periods as the main organisation. This is also used for invoice reconciliation.
return context
def getOrganisationForSectionCategory(section): XXX: the name of this script should include something "Accounting"
mapping = section.getMappingRelatedValue(portal_type='Organisation', TODO: unify with Base_getAccountingPeriodStartDateForSectionCategory
checked_permission='Access contents information') """
if mapping is not None: portal = context.getPortalObject()
return mapping
organisation_list = section.getGroupRelatedValueList(portal_type='Organisation',
strict_membership=1,
checked_permission='Access contents information')
for organisation in organisation_list: def isMainOrganisation(organisation):
if organisation.getProperty('validation_state', 'unset') not in ('deleted', 'invalidated'): return bool(organisation.contentValues(
return organisation portal_type='Accounting Period',
checked_permission='Access contents information'))
if isMainOrganisation(context):
return context
group = context.getGroupValue() group = context.getGroupValue()
if group is None: if group is None:
return context return context
group_chain = []
while group.getPortalType() != 'Base Category': 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() 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