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