[FIX] account: fix payment_difference computation

Bug introduced by https://github.com/odoo/odoo/commit/cdca5d4751a979f6b694f02d88160843f81a77f5

There is two problems:
- The payment difference is the difference between what you need to pay and what you pay.
=> The compute does the opposite.
- When the payment type is outbound, the payment amount is never negative.
=> Need to inverse the payment amount in the compute in this case.

E.G.

Suppose A a customer invoice of 25 and B a vendor bill of 50:

Payment on A will compute:
payment_type = 'inbound'
amount = 25

If you pay 20, the payment_difference computed was 20 - 25 = -5
It should be 25 - 20 = 5 instead.

Payment on B will compute:
payment_type = 'outbound'
amount = 50 (not -50!)

If you pay 40, the payment difference computed was 40 - (-50) = 10
It should be -50 - (-40) = -10 instead.
This commit is contained in:
Laurent Smet
2018-03-22 11:01:20 +01:00
parent 168b3490cd
commit 7859dee4fc
+2 -1
View File
@@ -129,7 +129,8 @@ class account_abstract_payment(models.AbstractModel):
@api.depends('invoice_ids', 'amount', 'payment_date', 'currency_id')
def _compute_payment_difference(self):
for pay in self.filtered(lambda p: p.invoice_ids):
pay.payment_difference = pay.amount - abs(pay._compute_payment_amount())
payment_amount = -pay.amount if pay.payment_type == 'outbound' else pay.amount
pay.payment_difference = pay._compute_payment_amount() - payment_amount
@api.onchange('journal_id')
def _onchange_journal(self):