changeset 3215000a8e7a in modules/account_payment:default
details:
https://hg.tryton.org/modules/account_payment?cmd=changeset&node=3215000a8e7a
description:
Order payment by closest amount to the statement line
issue11171
review360781002
diffstat:
payment.py | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diffs (28 lines):
diff -r e1837a324796 -r 3215000a8e7a payment.py
--- a/payment.py Thu Feb 03 23:13:26 2022 +0100
+++ b/payment.py Sun Feb 13 23:52:20 2022 +0100
@@ -5,6 +5,7 @@
from itertools import groupby
from sql.aggregate import Count, Sum
+from sql.operators import Abs
from trytond.i18n import gettext
from trytond.model import (
@@ -449,6 +450,16 @@
def search_currency(cls, name, clause):
return [('journal.' + clause[0],) + tuple(clause[1:])]
+ @classmethod
+ def order_amount(cls, tables):
+ table, _ = tables[None]
+ context = Transaction().context
+ column = cls.amount.sql_column(table)
+ if isinstance(context.get('amount_order'), Decimal):
+ return [Abs(column - abs(context['amount_order']))]
+ else:
+ return [column]
+
@fields.depends('kind')
def on_change_kind(self):
self.line = None