Fix search_amount for payment with diferent kind than the account's one
issue3766 review4431002
This commit is contained in:
+6
-17
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user