Skip to content

Commit

Permalink
account_usability: reversal wizard: check the move hasn't already bee…
Browse files Browse the repository at this point in the history
…n reversed
  • Loading branch information
alexis-via committed Sep 27, 2022
1 parent 23222e9 commit 44a92bd
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions account_usability/wizard/account_move_reversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import api, models, _
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError


class AccountMoveReversal(models.TransientModel):
_inherit = 'account.move.reversal'

# Set default reversal date to original move + 1 day
# and raise error if original move has already been reversed
@api.model
def _default_date(self):
date_dt = None
if (
self._context.get('active_model') == 'account.move' and
self._context.get('active_id')):
move = self.env['account.move'].browse(self._context['active_id'])
date_dt = move.date + relativedelta(days=1)
return date_dt

date = fields.Date(default=_default_date)
def default_get(self, fields_list):
res = super().default_get(fields_list)
assert self._context.get('active_model') == 'account.move'
amo = self.env['account.move']
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(_(
"Move '%s' has already been reversed by move '%s'.") % (
reversed_move.reversed_entry_id.display_name,
reversed_move.display_name))
return res

0 comments on commit 44a92bd

Please sign in to comment.