[FIX] account: register payment with change gain with currency rate > 100
On an invoice, when registering a payment in a foreign currency for which the payment pays entirely the invoice, and even more thanks to the change gain(write off), but for which the foreign currency rate to the company currency is higher than 100, (higher than the currency decimal precision of 2 digts), e.g. Invoice in CDF, Payment in USD (1 USD = 948 CDF), and choosing the option "Mark invoice as fully paid" for the difference handling, the invoice could not be marked as paid, according to the result of the currency rate rounding. This is because the debit or credit of the writeoff was computed from the payment difference, in the foreign currency, to the company currency, which lead to two currency rate computation, one in each way, company currency to foreign currency, then foreign currency to company currency, and some precision was lost in the process. Instead of computing the debit or credit of the writeoff from the payment difference, we now compute it from the payment amount in the company currency minus the invoice residual amount in the company currency, to avoid the double currency computation rate, so the precision is not lost in the process, and the invoice move is finally fully reconciled e.g.: Invoice of 247590.40 FC Payment of 267 USD (1 USD = 948 FC) Payment difference: (247590,40 / 948) - 267 = -5.83 (Gain of 5.83 USD) Before the revision, the credit of the writeoff was computed as: `((247590,40 FC / 948) - 267 USD) * 948 = 5526,84` After the revision, the credit of the writeoff is computed: `247590.40 - (267 * 948) = 5525.6` Notice in the first formula that the rate computation is performed two times, once in each way (`/948` then `*948`), while only once in the second, and this avoid the loss of 1.24 FC in the process. Without this precise debit/credit of the writeoff, the invoice could not be marked as fully paid, as the move was not fully reconciled. opw-687201
This commit is contained in:
@@ -384,7 +384,12 @@ class account_payment(models.Model):
|
||||
#Reconcile with the invoices
|
||||
if self.payment_difference_handling == 'reconcile' and self.payment_difference:
|
||||
writeoff_line = self._get_shared_move_line_vals(0, 0, 0, move.id, False)
|
||||
debit_wo, credit_wo, 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)
|
||||
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:]
|
||||
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
|
||||
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')
|
||||
writeoff_line['account_id'] = self.writeoff_account_id.id
|
||||
writeoff_line['debit'] = debit_wo
|
||||
|
||||
Reference in New Issue
Block a user