Commit 76b96377 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Do not merge SPL (Aggregated) from different causality

When causality is set and it is a Subscription Request, do not aggregate services (it will generate individual inviduals invoices per Subscription).

When a user has multiple requests, it should not merge, and it should generate 1 invoice per subscription request.
parent bbebfa5b
......@@ -43,6 +43,7 @@
<string>source</string>
<string>source_section</string>
<string>specialise</string>
<string>causality</string>
</tuple>
</value>
</item>
......
......@@ -3,14 +3,8 @@
person_delivery_mapping = {}
portal = context.getPortalObject()
for movement in movement_list:
person = movement.getDestinationValue()
try:
delivery = person_delivery_mapping[person]
except KeyError:
delivery = person.Person_getAggregatedDelivery()
if delivery is None or delivery.getSimulationState() != 'confirmed':
delivery = portal.sale_packing_list_module.newContent(
def newPackingList(movement, causality):
return portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List',
source=movement.getDestination(),
destination=movement.getDestination(),
......@@ -19,9 +13,24 @@ for movement in movement_list:
destination_decision=movement.getDestination(),
specialise=movement.getSpecialise(),
price_currency=movement.getPriceCurrency(),
causality=movement.getCausality()
)
causality=causality)
for movement in movement_list:
person = movement.getDestinationValue()
causality = movement.getCausality(portal_type="Subscription Request")
try:
delivery = person_delivery_mapping["%s---%s" % (person.getUid(), causality)]
except KeyError:
delivery = person.Person_getAggregatedDelivery()
if causality is None and (delivery is None or delivery.getSimulationState() != 'confirmed'):
delivery = newPackingList(movement, causality)
delivery.confirm('New aggregated delivery.')
person.Person_setAggregatedDelivery(delivery)
person_delivery_mapping[person] = delivery
elif causality is not None:
# If causality is not None, this is a delivery from a subscription request, so
# we create a separated Sale Packing List for it.
delivery = newPackingList(movement, causality)
delivery.confirm('New aggregated delivery for subscription')
person_delivery_mapping["%s---%s" % (person.getUid(), causality)] = delivery
return person_delivery_mapping.values()
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