From 262a8b894bb060f21189fd4f4bf57947d4e32b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 14 Feb 2025 10:43:15 +0100 Subject: [PATCH] Add payable/receivable date The date is the maturity date and if it is empty, fallback to the effective date. This gives a better chronology of the lines. --- modules/account/move.py | 45 ++++++++++++++++--- modules/account/move.xml | 2 +- .../move_line_list_payable_receivable.xml | 2 +- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/modules/account/move.py b/modules/account/move.py index d33d9131ab..be7af0af7e 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -785,6 +785,39 @@ class MoveLineMixin: currency = self.account.currency return currency.id + @fields.depends('maturity_date', 'date') + def on_change_with_payable_receivable_date(self, name=None): + return self.maturity_date or self.date + + @classmethod + def domain_payable_receivable_date(cls, domain, tables): + pool = Pool() + Move = pool.get('account.move') + table, _ = tables[None] + move = tables.get('move') + if move is None: + move = Move.__table__() + tables['move'] = { + None: (move, move.id == table.move), + } + _, operator, operand = domain + Operator = fields.SQL_OPERATORS[operator] + date = Coalesce(table.maturity_date, move.date) + return Operator(date, operand) + + @classmethod + def order_payable_receivable_date(cls, tables): + pool = Pool() + Move = pool.get('account.move') + table, _ = tables[None] + move = tables.get('move') + if move is None: + move = Move.__table__() + tables['move'] = { + None: (move, move.id == table.move), + } + return [Coalesce(table.maturity_date, move.date)] + @classmethod def get_payable_receivable_balance(cls, lines, name): pool = Pool() @@ -804,6 +837,8 @@ class MoveLineMixin: balances = dict.fromkeys(map(int, lines)) + date = Coalesce(line.maturity_date, move.date) + for company, lines in groupby(lines, lambda l: l.company): for sub_lines in grouped_slice(lines): sub_lines = list(sub_lines) @@ -835,11 +870,7 @@ class MoveLineMixin: balance = Sum(balance, window=Window( [line.party, currency], - order_by=[ - Coalesce(line.maturity_date, move.date).asc, - move.date.desc, - line.id.desc, - ])) + order_by=[date.asc.nulls_first, line.id.desc])) party_where = Literal(False) parties = {l.party for l in sub_lines} @@ -1045,6 +1076,10 @@ class Line(DescriptionOriginMixin, MoveLineMixin, ModelSQL, ModelView): | ~Eval('delegated_amount', 0)), }), 'get_delegated_amount') + + payable_receivable_date = fields.Function( + fields.Date("Payable/Receivable Date"), + 'on_change_with_payable_receivable_date') payable_receivable_balance = fields.Function( Monetary( "Payable/Receivable Balance", diff --git a/modules/account/move.xml b/modules/account/move.xml index 464506e55c..b9945f8bdf 100644 --- a/modules/account/move.xml +++ b/modules/account/move.xml @@ -256,7 +256,7 @@ this repository contains the full copyright notices and license terms. --> eval="[('company', '=', Eval('company', -1)), ['OR', If(Eval('receivable', True), ('account.type.receivable', '=', True), ('id', '<', 0)), If(Eval('payable', True), ('account.type.payable', '=', True), ('id', '<', 0))], If(Eval('reconciled', False), (), ('reconciliation', '=', None))]" pyson="1"/> - + diff --git a/modules/account/view/move_line_list_payable_receivable.xml b/modules/account/view/move_line_list_payable_receivable.xml index 5f808ce6bb..d8fd0a4e77 100644 --- a/modules/account/view/move_line_list_payable_receivable.xml +++ b/modules/account/view/move_line_list_payable_receivable.xml @@ -3,7 +3,7 @@ this repository contains the full copyright notices and license terms. --> - +