changeset 1b86b11c3c2c in modules/account_payment_clearing:default
details:
https://hg.tryton.org/modules/account_payment_clearing?cmd=changeset;node=1b86b11c3c2c
description:
Use the date of the statement as date for the clearing move
issue9030
review253031002
diffstat:
CHANGELOG | 2 ++
statement.py | 18 ++++++++++++------
tests/scenario_account_payment_clearing.rst | 4 +++-
3 files changed, 17 insertions(+), 7 deletions(-)
diffs (73 lines):
diff -r 3087133db0ef -r 1b86b11c3c2c CHANGELOG
--- a/CHANGELOG Thu Mar 19 19:00:29 2020 +0100
+++ b/CHANGELOG Fri Mar 20 19:10:30 2020 +0100
@@ -1,3 +1,5 @@
+* Use the date of the statement line as date for the clearing move
+
Version 5.4.0 - 2019-11-04
* Bug fixes (see mercurial logs for details)
* Relax Account domain on Payment
diff -r 3087133db0ef -r 1b86b11c3c2c statement.py
--- a/statement.py Thu Mar 19 19:00:29 2020 +0100
+++ b/statement.py Fri Mar 20 19:10:30 2020 +0100
@@ -1,5 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
+from collections import defaultdict
+
from trytond.pool import PoolMeta, Pool
from trytond.model import fields
from trytond.pyson import Eval, If, Bool
@@ -17,8 +19,8 @@
moves = super(Statement, cls).create_move(statements)
- to_success = set()
- to_fail = set()
+ to_success = defaultdict(set)
+ to_fail = defaultdict(set)
for move, statement, lines in moves:
for line in lines:
if line.payment:
@@ -30,15 +32,19 @@
else:
continue
if (kind == 'receivable') == (line.amount >= 0):
- to_success.update(payments)
+ to_success[line.date].update(payments)
else:
- to_fail.update(payments)
+ to_fail[line.date].update(payments)
# The failing should be done last because success is usually not a
# definitive state
if to_success:
- Payment.succeed(Payment.browse(to_success))
+ for date, payments in to_success.items():
+ with Transaction().set_context(clearing_date=date):
+ Payment.succeed(Payment.browse(payments))
if to_fail:
- Payment.fail(Payment.browse(to_fail))
+ for date, payments in to_fail.items():
+ with Transaction().set_context(clearing_date=date):
+ Payment.fail(Payment.browse(payments))
for move, statement, lines in moves:
assert len({l.payment for l in lines}) == 1
diff -r 3087133db0ef -r 1b86b11c3c2c tests/scenario_account_payment_clearing.rst
--- a/tests/scenario_account_payment_clearing.rst Thu Mar 19 19:00:29
2020 +0100
+++ b/tests/scenario_account_payment_clearing.rst Fri Mar 20 19:10:30
2020 +0100
@@ -445,7 +445,7 @@
... journal=statement_journal,
... start_balance=Decimal('0.00'),
... end_balance=Decimal('-50.00'))
- >>> line = statement.lines.new(date=today)
+ >>> line = statement.lines.new(date=yesterday)
>>> line.payment = payment
>>> line.party == supplier
True
@@ -471,3 +471,5 @@
>>> debit_line, = [l for l in payment.clearing_move.lines if l.debit > 0]
>>> debit_line.debit
Decimal('50.00')
+ >>> debit_line.date == yesterday
+ True