Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14] account_usability : Warn user when trying to reverse an already … #223

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions account_usability/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'wizard/account_invoice_mark_sent_view.xml',
'wizard/account_group_generate_view.xml',
'wizard/account_payment_register_views.xml',
'wizard/account_move_reversal.xml',
'security/ir.model.access.csv',
'report/invoice_report.xml',
],
Expand Down
14 changes: 14 additions & 0 deletions account_usability/i18n/account_usability.pot
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ msgid ""
" generate account groups from scratch."
msgstr ""

#. module: account_usability
#. odoo-python
#: code:addons/account_usability/wizard/account_move_reversal.py:0
#, python-format
msgid "%s reversed by %s"
msgstr ""

#. module: account_usability
#: model:ir.model,name:account_usability.model_account_account
msgid "Account"
Expand Down Expand Up @@ -679,6 +686,13 @@ msgstr ""
msgid "View Journal Entry Form"
msgstr ""

#. module: account_usability
#: model_terms:ir.ui.view,arch_db:account_usability.view_account_move_reversal
msgid ""
"You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.\n"
" Already reversed entries are the following :"
msgstr ""

#. module: account_usability
#: model:ir.model.fields,help:account_usability.field_account_bank_statement__hide_bank_statement_balance
#: model:ir.model.fields,help:account_usability.field_account_journal__hide_bank_statement_balance
Expand Down
16 changes: 16 additions & 0 deletions account_usability/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ msgstr ""
"%d des groupes de comptes existent déjà dans la société '%s'. Cet "
"assistant est conçu pour créer des groupes de comptes à partir de zéro."

#. module: account_usability
#. odoo-python
#: code:addons/account_usability/wizard/account_move_reversal.py:0
#, python-format
msgid "%s reversed by %s"
msgstr "%s extourné par %s"


#. module: account_usability
#: model:ir.model,name:account_usability.model_account_account
msgid "Account"
Expand Down Expand Up @@ -727,6 +735,14 @@ msgstr "Voir la pièce comptable"
msgid "View Journal Entry Form"
msgstr "Voir la pièce comptable en vue formulaire"

#. module: account_usability
#: model_terms:ir.ui.view,arch_db:account_usability.view_account_move_reversal
msgid ""
"You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.\n"
" Already reversed entries are the following :"
msgstr "Vous êtes sur le point d'extourner une pièce comptable déjà extournée, ou partiellement extournée (avoir). Vérifiez que c'est bien ce que vous souhaitez faire.\n"
" Les pièces comptables déjà extournées sont les suivantes :"

#. module: account_usability
#: model:ir.model.fields,help:account_usability.field_account_bank_statement__hide_bank_statement_balance
#: model:ir.model.fields,help:account_usability.field_account_journal__hide_bank_statement_balance
Expand Down
29 changes: 19 additions & 10 deletions account_usability/wizard/account_move_reversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
24 changes: 24 additions & 0 deletions account_usability/wizard/account_move_reversal.xml
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>