changeset 8fbaa1d07c62 in modules/account_payment_clearing:default
details:
https://hg.tryton.org/modules/account_payment_clearing?cmd=changeset&node=8fbaa1d07c62
description:
Ensure to create only once clearing move
issue11388
review354911002
diffstat:
payment.py | 31 ++++++++++++++++++-------------
1 files changed, 18 insertions(+), 13 deletions(-)
diffs (59 lines):
diff -r 9cf7589e779b -r 8fbaa1d07c62 payment.py
--- a/payment.py Mon Apr 11 22:23:58 2022 +0200
+++ b/payment.py Sat Apr 16 11:31:51 2022 +0200
@@ -174,22 +174,11 @@
@Workflow.transition('succeeded')
def succeed(cls, payments):
pool = Pool()
- Move = pool.get('account.move')
Line = pool.get('account.move.line')
super(Payment, cls).succeed(payments)
- moves = []
- for payment in payments:
- move = payment.create_clearing_move(
- date=Transaction().context.get('clearing_date'))
- if move:
- moves.append(move)
- if moves:
- Move.save(moves)
- cls.write(*sum((([m.origin], {'clearing_move': m.id})
- for m in moves), ()))
-
+ cls.set_clearing_move(payments)
to_reconcile = []
for payment in payments:
if (payment.line
@@ -217,7 +206,21 @@
else:
return self.party
- def create_clearing_move(self, date=None):
+ @classmethod
+ def set_clearing_move(cls, payments):
+ pool = Pool()
+ Move = pool.get('account.move')
+ moves = []
+ for payment in payments:
+ move = payment._get_clearing_move()
+ if move and not payment.clearing_move:
+ payment.clearing_move = move
+ moves.append(move)
+ if moves:
+ Move.save(moves)
+ cls.save(payments)
+
+ def _get_clearing_move(self, date=None):
pool = Pool()
Move = pool.get('account.move')
Line = pool.get('account.move.line')
@@ -234,6 +237,8 @@
return self.clearing_move
if date is None:
+ date = Transaction().context.get('clearing_date')
+ if date is None:
with Transaction().set_context(company=self.company.id):
date = Date.today()
period = Period.find(self.company.id, date=date)