[FIX] account: wrong counterpart in invoice / out refund register payment

Revision 20935462a0
introduces the below regression:

When registering a payment on a customer invoice refund
or a vendor bill, with a payment difference

e.g. payment of 101 for an invoice of 100

and marking the invoice as fully paid,
the counter part in the payment account move
were wrongly computed:

In those cases,
its the payment total minus the invoice residual total
that must be performed, and not the other way around.

This revision solves this, inspired on how
the payment difference is computed for display
in the wizard on how it was before the above revision,
in the method `_compute_payment_difference`

Fixes #15000
This commit is contained in:
Denis Ledoux
2017-01-10 16:49:21 +01:00
parent 23deeb187d
commit fc813847d8
+5 -2
View File
@@ -388,9 +388,12 @@ class account_payment(models.Model):
# the writeoff debit and credit must be computed from the invoice residual in company currency
# minus the payment amount in company currency, and not from the payment difference in the payment currency
# to avoid loss of precision during the currency rate computations. See revision 20935462a0cabeb45480ce70114ff2f4e91eaf79 for a detailed example.
total_residual_company_signed = sum(invoice.residual_company_signed for invoice in self.invoice_ids)
total_residual_company_signed = self._compute_total_invoices_amount()
total_payment_company_signed = self.currency_id.with_context(date=self.payment_date).compute(self.amount, self.company_id.currency_id)
amount_wo = total_residual_company_signed - total_payment_company_signed
if self.invoice_ids[0].type in ['in_invoice', 'out_refund']:
amount_wo = total_payment_company_signed - total_residual_company_signed
else:
amount_wo = total_residual_company_signed - total_payment_company_signed
debit_wo = amount_wo > 0 and amount_wo or 0.0
credit_wo = amount_wo < 0 and -amount_wo or 0.0
writeoff_line['name'] = _('Counterpart')