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.
This commit is contained in:
Cédric Krier
2025-02-14 10:43:15 +01:00
parent 93b3d27117
commit 262a8b894b
3 changed files with 42 additions and 7 deletions
+40 -5
View File
@@ -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",
+1 -1
View File
@@ -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"/>
<field name="search_value"></field>
<field name="order" eval="[('maturity_date', 'ASC'), ('date', 'DESC'), ('id', 'DESC')]" pyson="1"/>
<field name="order" eval="[('payable_receivable_date', 'ASC NULLS FIRST'), ('id', 'DESC')]" pyson="1"/>
</record>
<record model="ir.action.act_window.view"
id="act_move_line_payable_receivable_view1">
@@ -3,7 +3,7 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="company" expand="1" optional="1"/>
<field name="maturity_date"/>
<field name="payable_receivable_date" string="Date"/>
<field name="party"/>
<field name="amount"/>
<field name="payable_receivable_balance" string="Balance"/>