Commit c91cf5b9 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: builder: group movement by specialise

Previously, we has 1 invoice per simulation tree.
But we want to reduce the number of invoice, without using the "aggregate" builder trick
parent 22e07b5a
......@@ -4,13 +4,21 @@ if context.getDelivery() is not None:
if context.getLedger() != 'automated':
return
root_applied_rule = context.getRootAppliedRule()
root_applied_rule_path = root_applied_rule.getPath()
# group by specialise: the trade condition is the common link betweek every line/cell on a delivery
business_link = context.getCausalityValue(portal_type='Business Link')
if business_link is None:
raise ValueError('Movement without business link: %s' % context.getRelativeUrl())
lock_tag = 'build_in_progress_%s_%s' % (business_link.getUid(), root_applied_rule.getUid())
trade_condition = context.getSpecialiseValue()
if trade_condition is None:
raise ValueError('Movement without specialise: %s' % context.getRelativeUrl())
lock_tag = 'build_in_progress_%s_%s' % (business_link.getUid(), trade_condition.getUid())
if context.getPortalObject().portal_activities.countMessageWithTag(lock_tag) == 0:
business_link.build(path='%s/%%' % root_applied_rule_path, activate_kw={'tag': tag})
root_applied_rule.activate(activity='SQLQueue', after_tag=tag, tag=lock_tag).getId()
business_link.build(
ledger__uid=context.getPortalObject().portal_categories.ledger.automated.getUid(),
specialise__uid=trade_condition.getUid(),
activate_kw={'tag': tag}
)
business_link.activate(activity='SQLQueue', after_tag=tag, tag=lock_tag).getId()
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