diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 454cb4ad5f9..486c7eba0ab 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -385,6 +385,9 @@ class account_payment(models.Model): if self.payment_difference_handling == 'reconcile' and self.payment_difference: writeoff_line = self._get_shared_move_line_vals(0, 0, 0, move.id, False) amount_currency_wo, currency_id = aml_obj.with_context(date=self.payment_date).compute_amount_fields(self.payment_difference, self.currency_id, self.company_id.currency_id, invoice_currency)[2:] + # 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_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