[IMP] account_usability_akretion : Replace error by warning in case a user try to reverse an already reversed account move

The goal is to allow multiple refund for a single invoice. It may happen to refund invoice partially and they refund again partially later.
This commit is contained in:
Florian da Costa
2024-08-28 15:26:33 +02:00
parent 3b5b64349b
commit c09e3a1108
4 changed files with 58 additions and 14 deletions

View File

@@ -30,6 +30,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', # TODO
"views/res_partner.xml",

View File

@@ -37,6 +37,21 @@ msgstr ""
"Une extourne <a href=# data-oe-model=account.move data-oe-"
"id=%d>%s</a> a été générée."
#. module: account_usability_akretion
#. odoo-python
#: code:addons/account_usability_akretion/wizard/account_move_reversal.py:0
#, python-format
msgid "%s reversed by %s"
msgstr "%s extourné par %s"
#. module: account_usability_akretion
#: model_terms:ir.ui.view,arch_db:account_usability_akretion.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_akretion
#: model:ir.model,name:account_usability_akretion.model_account_account
msgid "Account"
@@ -366,13 +381,6 @@ msgstr "Divers"
msgid "Missing Attachment"
msgstr "Pièce jointe manquante"
#. module: account_usability_akretion
#. odoo-python
#: code:addons/account_usability_akretion/wizard/account_move_reversal.py:0
#, python-format
msgid "Journal entry '%s' has already been reversed by journal entry '%s'."
msgstr "La pièce comptable '%s' a déjà été extournée par la pièce comptable '%s'."
#. module: account_usability_akretion
#: model:ir.model,name:account_usability_akretion.model_account_partial_reconcile
msgid "Partial Reconcile"

View File

@@ -2,7 +2,7 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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
@@ -10,6 +10,23 @@ 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
@api.model
@@ -20,10 +37,4 @@ class AccountMoveReversal(models.TransientModel):
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(_(
"Journal entry '%s' has already been reversed by journal entry '%s'.") % (
reversed_move.reversed_entry_id.display_name,
reversed_move.display_name))
return res

View File

@@ -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>