diff --git a/account.py b/account.py index 5f647f6770..2f0d05a48f 100644 --- a/account.py +++ b/account.py @@ -2,7 +2,7 @@ #this repository contains the full copyright notices and license terms. from sql.aggregate import Sum from sql.conditionals import Case, Coalesce -from sql.functions import Abs, Sign +from sql.functions import Abs from trytond.pool import Pool, PoolMeta from trytond.model import ModelView, fields @@ -79,22 +79,11 @@ class MoveLine: payment = Payment.__table__() account = Account.__table__() - main_payable = ((table.credit - table.debit) - - Sum(Coalesce(payment.amount, 0))) - main_receivable = ((table.debit - table.credit) - - Sum(Coalesce(payment.amount, 0))) - - second_payable = ((Abs(table.amount_second_currency) - * Sign(table.credit - table.debit)) - - Sum(Coalesce(payment.amount, 0))) - second_receivable = ((Abs(table.amount_second_currency) - * Sign(table.debit - table.credit)) - - Sum(Coalesce(payment.amount, 0))) - amount = Case((table.second_currency == None, - Case((account.kind == 'payable', main_payable), - else_=main_receivable)), - else_=Case((account.kind == 'payable', second_payable), - else_=second_receivable)) + payment_amount = Sum(Coalesce(payment.amount, 0)) + main_amount = Abs(table.credit - table.debit) - payment_amount + second_amount = Abs(table.amount_second_currency) - payment_amount + amount = Case((table.second_currency == None, main_amount), + else_=second_amount) value = cls.payment_amount.sql_format(value) query = table.join(payment, type_='LEFT',