Check account before reconciliation

When we calculate the amount of the payments and of the invoice, we do not check the account, just the credit or debit amount.

I just check if the account of the invoice, match the account of the account.move.line before suming the amount.
This fix a bug to reconcile invoices containing discount/refund lines.
Example : I have an sale order with 2 lines : 
1) Computer => amount = 500
2) Refund/discount => amount = -100

The problem of this second line is that the invoice will generates an account move line with a debit = 100.

So when we sum the debit of the account move line of the invoice, we will have 400 +100 = 500
The payment linked to the sale order has an amount of 400.
It won't try to reconcile even if it should.

Maybe instead of checking if the invoice account match the account move line Account, I should just check if the account move line account is payable/receivable.

I think the bug is also present in v7.0, if confirmed I can propose a patch for the version 7