[IMP] account_usability_akretion : Replace error by warning in case a user try to reverse an already reversed account move

The goal is to allow multiple refund for a single invoice. It may happen to refund invoice partially and they refund again partially later.
This commit is contained in:
Florian da Costa
2024-08-28 15:26:33 +02:00
parent 3b5b64349b
commit c09e3a1108
4 changed files with 58 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, _
from odoo import api, fields, models, _
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError
@@ -10,6 +10,23 @@ from odoo.exceptions import UserError
class AccountMoveReversal(models.TransientModel):
_inherit = 'account.move.reversal'
already_reversed_warning = fields.Text(compute="_compute_already_reversed_warning")
@api.depends("move_ids")
def _compute_already_reversed_warning(self):
for wizard in self:
moves = wizard.move_ids or self.env["account.move"].browse(self._context['active_ids'])
reversed_moves = self.env["account.move"].search([('reversed_entry_id', 'in', moves.ids)])
warning = ""
for already_reversed_move in reversed_moves.reversed_entry_id:
if warning:
warning += "\n"
reversed_by = " ; ".join(already_reversed_move.reversal_move_id.mapped("display_name"))
move_detail = _("%s reversed by %s") % (already_reversed_move.display_name, reversed_by)
warning += move_detail
wizard.already_reversed_warning = warning or False
# Set default reversal date to original move + 1 day
# and raise error if original move has already been reversed
@api.model
@@ -20,10 +37,4 @@ class AccountMoveReversal(models.TransientModel):
moves = amo.browse(self._context['active_ids'])
if len(moves) == 1:
res['date'] = moves.date + relativedelta(days=1)
reversed_move = amo.search([('reversed_entry_id', 'in', moves.ids)], limit=1)
if reversed_move:
raise UserError(_(
"Journal entry '%s' has already been reversed by journal entry '%s'.") % (
reversed_move.reversed_entry_id.display_name,
reversed_move.display_name))
return res