[FIX] account, account_tax_cash_basis: rounding
When tax cash basis is used, the user might face the error "Wrong credit or debit value in accounting entry !". A detailed use case can be found in issue #14158. The reason is that a float representation of `1.0` of the field `matched_percentage` will become `1.000...2` when used in Python. Therefore, such an expression such as `line.credit_cash_basis - line.credit * matched_percentage` might lead to a slightly negative value for the credit/debit, which will not pass the condition `CHECK (credit+debit>=0)`. Fixes #14158 opw-692797
This commit is contained in:
@@ -55,7 +55,7 @@ class AccountMove(models.Model):
|
||||
total_amount += amount
|
||||
for partial_line in (line.matched_debit_ids + line.matched_credit_ids):
|
||||
total_reconciled += partial_line.amount
|
||||
if total_amount == 0.0:
|
||||
if float_is_zero(total_amount, precision_rounding=move.currency_id.rounding):
|
||||
move.matched_percentage = 1.0
|
||||
else:
|
||||
move.matched_percentage = total_reconciled / total_amount
|
||||
|
||||
@@ -53,7 +53,7 @@ class AccountPartialReconcileCashBasis(models.Model):
|
||||
#create reporting issues. Not sure of the behavior to implement in that case, though.
|
||||
# amount to write is the current cash_basis amount minus the one before the reconciliation
|
||||
matched_percentage = value_before_reconciliation[move.id]
|
||||
amount = (line.credit_cash_basis - line.debit_cash_basis) - (line.credit - line.debit) * matched_percentage
|
||||
amount = line.currency_id.round((line.credit_cash_basis - line.debit_cash_basis) - (line.credit - line.debit) * matched_percentage)
|
||||
if not self._check_tax_exigible(line):
|
||||
if line.tax_line_id and line.tax_line_id.use_cash_basis:
|
||||
# group by line account
|
||||
@@ -73,15 +73,15 @@ class AccountPartialReconcileCashBasis(models.Model):
|
||||
for tax in line.tax_ids:
|
||||
line_to_create.append((0, 0, {
|
||||
'name': '/',
|
||||
'debit': line.debit_cash_basis - line.debit * matched_percentage,
|
||||
'credit': line.credit_cash_basis - line.credit * matched_percentage,
|
||||
'debit': line.currency_id.round(line.debit_cash_basis - line.debit * matched_percentage),
|
||||
'credit': line.currency_id.round(line.credit_cash_basis - line.credit * matched_percentage),
|
||||
'account_id': line.account_id.id,
|
||||
'tax_ids': [(6, 0, [tax.id])],
|
||||
}))
|
||||
line_to_create.append((0, 0, {
|
||||
'name': '/',
|
||||
'credit': line.debit_cash_basis - line.debit * matched_percentage,
|
||||
'debit': line.credit_cash_basis - line.credit * matched_percentage,
|
||||
'credit': line.currency_id.round(line.debit_cash_basis - line.debit * matched_percentage),
|
||||
'debit': line.currency_id.round(line.credit_cash_basis - line.credit * matched_percentage),
|
||||
'account_id': line.account_id.id,
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user