From 8d1138577f721f0eaaeb29334dcb2ba9a26bc0c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 30 Nov 2016 06:56:29 +0000
Subject: [PATCH] accounting: AccountingTransaction_setDefaultMirrorAccountList
 is not needed here

We only want to do it when starting an internal invoice, but it will
probably make the invoice inconsitent, because not balance. This should
not be a problem for the source accountant who is starting the invoice,
but is something destination accountant have to fix before stopping.
---
 .../accounting_workflow/scripts/validateTransaction.py    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.py b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.py
index a1de0cd6b3..bd53b3cf90 100644
--- a/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.py
+++ b/bt5/erp5_accounting/WorkflowTemplateItem/portal_workflow/accounting_workflow/scripts/validateTransaction.py
@@ -12,7 +12,13 @@ if not transaction.getStartDate() and transaction.getStopDate():
   transaction.setStartDate(transaction.getStopDate())
 
 # XXX auto-fill mirror accounts, if necessary.
-transaction.AccountingTransaction_setDefaultMirrorAccountList()
+# We do not do it for internal invoice transaction, because we do it in
+# only after starting the invoice, because this can make invoice not balanced
+# for destination section, which is not a problem for source section accountant
+# when starting.
+# Using this in non-internal transaction is probably a bad idea.
+if transaction.getPortalType() != 'Internal Invoice Transaction':
+  transaction.AccountingTransaction_setDefaultMirrorAccountList()
 
 # Check constraints
 transaction.Base_checkConsistency()
-- 
2.30.9