Skip to content

Commit 72fc445

Browse files
committed
[14] account_usability : Warn user when trying to reverse an already reversed account move
1 parent 2a0b134 commit 72fc445

File tree

6 files changed

+76
-12
lines changed

6 files changed

+76
-12
lines changed

account_usability/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'wizard/account_invoice_mark_sent_view.xml',
3737
'wizard/account_group_generate_view.xml',
3838
'wizard/account_payment_register_views.xml',
39+
'wizard/account_move_reversal.xml',
3940
'security/ir.model.access.csv',
4041
'report/invoice_report.xml',
4142
],

account_usability/i18n/account_usability.pot

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ msgid ""
2121
" generate account groups from scratch."
2222
msgstr ""
2323

24+
#. module: account_usability
25+
#. odoo-python
26+
#: code:addons/account_usability/wizard/account_move_reversal.py:0
27+
#, python-format
28+
msgid "%s reversed by %s"
29+
msgstr ""
30+
2431
#. module: account_usability
2532
#: model:ir.model,name:account_usability.model_account_account
2633
msgid "Account"
@@ -679,6 +686,13 @@ msgstr ""
679686
msgid "View Journal Entry Form"
680687
msgstr ""
681688

689+
#. module: account_usability
690+
#: model_terms:ir.ui.view,arch_db:account_usability.view_account_move_reversal
691+
msgid ""
692+
"You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.\n"
693+
" Already reversed entries are the following :"
694+
msgstr ""
695+
682696
#. module: account_usability
683697
#: model:ir.model.fields,help:account_usability.field_account_bank_statement__hide_bank_statement_balance
684698
#: model:ir.model.fields,help:account_usability.field_account_journal__hide_bank_statement_balance

account_usability/i18n/fr.po

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ msgstr ""
2626
"%d des groupes de comptes existent déjà dans la société '%s'. Cet "
2727
"assistant est conçu pour créer des groupes de comptes à partir de zéro."
2828

29+
#. module: account_usability
30+
#. odoo-python
31+
#: code:addons/account_usability/wizard/account_move_reversal.py:0
32+
#, python-format
33+
msgid "%s reversed by %s"
34+
msgstr "%s extourné par %s"
35+
36+
2937
#. module: account_usability
3038
#: model:ir.model,name:account_usability.model_account_account
3139
msgid "Account"
@@ -727,6 +735,14 @@ msgstr "Voir la pièce comptable"
727735
msgid "View Journal Entry Form"
728736
msgstr "Voir la pièce comptable en vue formulaire"
729737

738+
#. module: account_usability
739+
#: model_terms:ir.ui.view,arch_db:account_usability.view_account_move_reversal
740+
msgid ""
741+
"You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.\n"
742+
" Already reversed entries are the following :"
743+
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"
744+
" Les pièces comptables déjà extournées sont les suivantes :"
745+
730746
#. module: account_usability
731747
#: model:ir.model.fields,help:account_usability.field_account_bank_statement__hide_bank_statement_balance
732748
#: model:ir.model.fields,help:account_usability.field_account_journal__hide_bank_statement_balance

account_usability/wizard/account_move_reversal.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@
22
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5-
from odoo import api, models, _
5+
from odoo import api, fields, models, _
66
from dateutil.relativedelta import relativedelta
7-
from odoo.exceptions import UserError
87

98

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

12+
already_reversed_warning = fields.Text(compute="_compute_already_reversed_warning")
13+
14+
@api.depends("move_ids")
15+
def _compute_already_reversed_warning(self):
16+
for wizard in self:
17+
moves = wizard.move_ids or self.env["account.move"].browse(self._context['active_ids'])
18+
reversed_moves = self.env["account.move"].search([('reversed_entry_id', 'in', moves.ids)])
19+
warning = ""
20+
for already_reversed_move in reversed_moves.reversed_entry_id:
21+
if warning:
22+
warning += "\n"
23+
reversed_by = " ; ".join(already_reversed_move.reversal_move_id.mapped("display_name"))
24+
move_detail = _("%s reversed by %s") % (already_reversed_move.display_name, reversed_by)
25+
warning += move_detail
26+
wizard.already_reversed_warning = warning or False
27+
28+
1329
# Set default reversal date to original move + 1 day
1430
# and raise error if original move has already been reversed
15-
# WARNING: this wizard is also used to generate refunds
1631
@api.model
1732
def default_get(self, fields_list):
1833
res = super().default_get(fields_list)
@@ -21,10 +36,4 @@ def default_get(self, fields_list):
2136
moves = amo.browse(self._context['active_ids'])
2237
if len(moves) == 1 and moves.move_type not in ('out_invoice', 'in_invoice'):
2338
res['date'] = moves.date + relativedelta(days=1)
24-
reversed_move = amo.search([('reversed_entry_id', 'in', moves.ids)], limit=1)
25-
if reversed_move:
26-
raise UserError(_(
27-
"Move '%s' has already been reversed by move '%s'.") % (
28-
reversed_move.reversed_entry_id.display_name,
29-
reversed_move.display_name))
30-
return res
39+
return res
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record id="view_account_move_reversal" model="ir.ui.view">
5+
<field name="model">account.move.reversal</field>
6+
<field name="inherit_id" ref="account.view_account_move_reversal"/>
7+
<field name="arch" type="xml">
8+
<field name="residual" position="before">
9+
<div
10+
class="alert alert-warning"
11+
role="alert"
12+
attrs="{'invisible': [('already_reversed_warning', '=', False)]}"
13+
>
14+
You are about to reverse entries that have already been reversed or partially reversed (refund). Make sure it is intented.
15+
Already reversed entries are the following :
16+
<field
17+
name="already_reversed_warning"
18+
/>
19+
</div>
20+
</field>
21+
</field>
22+
</record>
23+
24+
</odoo>

sale_usability/models/account_move.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class AccountMove(models.Model):
1111

1212
# sale_ids is kind of the symetric field of invoice_ids on sale.order
1313
sale_ids = fields.Many2many(
14-
'sale.order', string='Sale Orders', compute="_compute_sale_ids")
14+
'sale.order', string='Sale Orders', compute="_compute_sale_ids", store=True)
1515
sale_count = fields.Integer(
16-
string='Sale Order Count', compute='_compute_sale_ids')
16+
string='Sale Order Count', compute='_compute_sale_ids', store=True)
1717

1818
@api.depends('invoice_line_ids.sale_line_ids')
1919
def _compute_sale_ids(self):

0 commit comments

Comments
 (0)