Commit 0789ec35 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: Extend the invoice causality with the parent simulation movement explanation

parent 202cbdd4
......@@ -3,6 +3,9 @@ the new Invoice.
"""
from Products.ERP5Type.Message import translateString
from DateTime import DateTime
portal = context.getPortalObject()
if related_simulation_movement_path_list is None:
raise RuntimeError, 'related_simulation_movement_path_list is missing. Update ERP5 Product.'
......@@ -11,17 +14,19 @@ price_currency = invoice.getPriceCurrency()
if invoice.getResource() != price_currency:
invoice.setResource(price_currency)
if invoice.getCausality(None) is None:
causality_list = []
for line in invoice.objectValues():
related_delivery = line.getDeliveryRelatedValue()
if related_delivery is not None:
root_applied_rule = related_delivery.getRootAppliedRule()
if root_applied_rule is not None:
causality = root_applied_rule.getCausality()
if causality is not None and causality not in causality_list:
causality_list.append(causality)
invoice.setCausalityList(causality_list)
# Extend the invoice causality with the parent simulation movement explanation
# usually, Sale Packing List
causality_list = invoice.getCausalityList()
for simulation_movement in related_simulation_movement_path_list:
simulation_movement = portal.restrictedTraverse(simulation_movement)
applied_rule = simulation_movement.getParentValue()
if applied_rule.getParentId() != 'portal_simulation':
causality = applied_rule.getParentValue().getExplanationValue()
if causality is not None:
causality = causality.getRelativeUrl()
if causality not in causality_list:
causality_list.append(causality)
invoice.setCausalityList(causality_list)
# Link the Invoice to the original Deposit payment
# this allow the invoice and payment to be automatilly grouped (lettering)
......
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