-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
account_usability: reversal wizard: check the move hasn't already bee…
…n reversed
- Loading branch information
1 parent
23222e9
commit 44a92bd
Showing
1 changed file
with
18 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |