changeset a548f3e2d37b in modules/account_payment_clearing:default
details: 
https://hg.tryton.org/modules/account_payment_clearing?cmd=changeset;node=a548f3e2d37b
description:
        Prevent calling succeed or fail with duplicate payments

        issue9064
        review266821003
diffstat:

 statement.py |  16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diffs (40 lines):

diff -r 80139e794d09 -r a548f3e2d37b statement.py
--- a/statement.py      Sun Mar 01 16:12:38 2020 +0100
+++ b/statement.py      Thu Mar 05 23:02:21 2020 +0100
@@ -17,28 +17,28 @@
 
         moves = super(Statement, cls).create_move(statements)
 
-        to_success = []
-        to_fail = []
+        to_success = set()
+        to_fail = set()
         for move, statement, lines in moves:
             for line in lines:
                 if line.payment:
-                    payments = [line.payment]
+                    payments = {line.payment}
                     kind = line.payment.kind
                 elif line.payment_group:
-                    payments = line.payment_group.payments
+                    payments = set(line.payment_group.payments)
                     kind = line.payment_group.kind
                 else:
                     continue
                 if (kind == 'receivable') == (line.amount >= 0):
-                    to_success.extend(payments)
+                    to_success.update(payments)
                 else:
-                    to_fail.extend(payments)
+                    to_fail.update(payments)
         # The failing should be done last because success is usually not a
         # definitive state
         if to_success:
-            Payment.succeed(to_success)
+            Payment.succeed(Payment.browse(to_success))
         if to_fail:
-            Payment.fail(to_fail)
+            Payment.fail(Payment.browse(to_fail))
 
         for move, statement, lines in moves:
             assert len({l.payment for l in lines}) == 1

Reply via email to