From e7da27d544983f9b5f08e0d89ecf2bba2b4fc4e7 Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Mon, 12 Feb 2018 15:49:42 +0100 Subject: [PATCH] Add issue7129 - account_payment Slow to list Lines to Pay --- issue7129.diff | 33 +++++++++++++++++++++++++++++++++ series | 1 + 2 files changed, 34 insertions(+) create mode 100644 issue7129.diff diff --git a/issue7129.diff b/issue7129.diff new file mode 100644 index 0000000..98f9e18 --- /dev/null +++ b/issue7129.diff @@ -0,0 +1,33 @@ +diff -r 98695a5ca9e7 trytond/trytond/modules/account_payment/account.py +--- a/trytond/trytond/modules/account_payment/account.py Mon Feb 12 15:11:55 2018 +0100 ++++ b/trytond/trytond/modules/account_payment/account.py Mon Feb 12 15:36:36 2018 +0100 +@@ -1,6 +1,6 @@ + # 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 sql import Null ++from sql import Union, Null, Literal + from sql.aggregate import Sum + from sql.conditionals import Case, Coalesce + from sql.functions import Abs +@@ -87,14 +87,19 @@ + else_=second_amount) + value = cls.payment_amount.sql_format(value) + +- query = table.join(payment, type_='LEFT', ++ query1 = table.join(payment, type_='LEFT', + condition=(table.id == payment.line) & (payment.state != 'failed') + ).join(account, condition=table.account == account.id + ).select(table.id, +- where=account.kind.in_(['payable', 'receivable']), ++ where=account.kind.in_(['payable', 'receivable']) & ++ (table.reconciliation == Null), + group_by=(table.id, account.kind, table.second_currency), + having=Operator(amount, value) + ) ++ query2 = table.select(Literal(0).as_('amount'), ++ where=(table.reconciliation == Null) & ++ Operator(Literal(0), value)) ++ query = Union(query1, query2, all_=True) + return [('id', 'in', query)] + + def get_payment_kind(self, name): diff --git a/series b/series index ae0ee95..a940893 100644 --- a/series +++ b/series @@ -74,3 +74,4 @@ locale.diff improve_stock_by_locations_performance.diff issue6322_6501.diff issue33209.diff # [account_invoice] Forbid to create credit notes from nonposted invoices. +issue7129.diff # [account_payment] Slow to list Lines to Pay