diff --git a/modules/account/move.py b/modules/account/move.py index 5d440deb20ed64dfaf4ea7962baa80a4e5dd6cf9_bW9kdWxlcy9hY2NvdW50L21vdmUucHk=..7caa97a96b9522f6ee0f32b8d15da6845db46d22_bW9kdWxlcy9hY2NvdW50L21vdmUucHk= 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -785,6 +785,39 @@ 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 @@ 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 @@ 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 @@ | ~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 5d440deb20ed64dfaf4ea7962baa80a4e5dd6cf9_bW9kdWxlcy9hY2NvdW50L21vdmUueG1s..7caa97a96b9522f6ee0f32b8d15da6845db46d22_bW9kdWxlcy9hY2NvdW50L21vdmUueG1s 100644 --- a/modules/account/move.xml +++ b/modules/account/move.xml @@ -256,7 +256,7 @@ 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"> diff --git a/modules/account/view/move_line_list_payable_receivable.xml b/modules/account/view/move_line_list_payable_receivable.xml index 5d440deb20ed64dfaf4ea7962baa80a4e5dd6cf9_bW9kdWxlcy9hY2NvdW50L3ZpZXcvbW92ZV9saW5lX2xpc3RfcGF5YWJsZV9yZWNlaXZhYmxlLnhtbA==..7caa97a96b9522f6ee0f32b8d15da6845db46d22_bW9kdWxlcy9hY2NvdW50L3ZpZXcvbW92ZV9saW5lX2xpc3RfcGF5YWJsZV9yZWNlaXZhYmxlLnhtbA== 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. --> <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"/>