-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[14] account_usability : Warn user when trying to reverse an already …
…reversed account move
- Loading branch information
Showing
5 changed files
with
74 additions
and
10 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
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
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
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,17 +2,32 @@ | |
# @author: Alexis de Lattre <[email protected]> | ||
# 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 | ||
|
||
|
||
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 | ||
# WARNING: this wizard is also used to generate refunds | ||
@api.model | ||
def default_get(self, fields_list): | ||
res = super().default_get(fields_list) | ||
|
@@ -21,10 +36,4 @@ def default_get(self, fields_list): | |
moves = amo.browse(self._context['active_ids']) | ||
if len(moves) == 1 and moves.move_type not in ('out_invoice', 'in_invoice'): | ||
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 | ||
return res |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="view_account_move_reversal" model="ir.ui.view"> | ||
<field name="model">account.move.reversal</field> | ||
<field name="inherit_id" ref="account.view_account_move_reversal"/> | ||
<field name="arch" type="xml"> | ||
<field name="residual" position="before"> | ||
<div | ||
class="alert alert-warning" | ||
role="alert" | ||
attrs="{'invisible': [('already_reversed_warning', '=', False)]}" | ||
> | ||
You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented. | ||
Already reversed entries are the following : | ||
<field | ||
name="already_reversed_warning" | ||
/> | ||
</div> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |