-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#66818 [16.0][MIG] account_move_unique_reversal (#193)
* TA#66818 [16.0][MIG] account_move_unique_reversal --------- Co-authored-by: Majda EL MARIOULI <[email protected]>
- Loading branch information
1 parent
c542f9f
commit 3957315
Showing
13 changed files
with
231 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
============================ | ||
Account Move Unique Reversal | ||
============================ | ||
|
||
This module blocks the users from reversing the Journal Entries if they have already | ||
been reversed or they are the reversal of another Entry except in cases where the journal is related to sales or purchases. | ||
|
||
- Reversed Entry: | ||
|
||
.. image:: static/description/reverse_reversed_move.png | ||
|
||
- Reversal Entry: | ||
|
||
.. image:: static/description/reverse_reversal_move.png | ||
|
||
Configuration | ||
------------- | ||
No configuration required apart from module installation. | ||
|
||
Contributors | ||
------------ | ||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
* Komit (https://komit-consulting.com) | ||
|
||
More information | ||
---------------- | ||
* Meet us at https://bit.ly/numigi-com |
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,4 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
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,15 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Account Move Unique Reversal", | ||
"summary": "Blocks the users from reversing the Journal Entries if they have " | ||
"already been reversed or they are the reversal of the other Entries", | ||
"version": "16.0.1.0.0", | ||
"website": "https://bit.ly/numigi-com", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"license": "AGPL-3", | ||
"depends": ["account"], | ||
"installable": True, | ||
} |
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,33 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_move_unique_reversal | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-06-14 10:18+0000\n" | ||
"PO-Revision-Date: 2024-06-14 10:18+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: account_move_unique_reversal | ||
#: model:ir.model,name:account_move_unique_reversal.model_account_move_reversal | ||
msgid "Account Move Reversal" | ||
msgstr "Renversement de la pièce comptable" | ||
|
||
#. module: account_move_unique_reversal | ||
#: code:addons/account_move_unique_reversal/models/account_move_reversal.py:18 | ||
#, python-format | ||
msgid "The accounting entry {} is already reversed (by entry {}). You can only reverse an accounting entry once." | ||
msgstr "La pièce comptable {} est déjà renversée (pièce {}). Vous ne pouvez renverser une pièce qu’une seule fois." | ||
|
||
#. module: account_move_unique_reversal | ||
#: code:addons/account_move_unique_reversal/models/account_move_reversal.py:28 | ||
#, python-format | ||
msgid "The accounting entry {} is the reversal of another entry ({}). You can not reverse a reversal accounting entry." | ||
msgstr "La pièce comptable {} est le renversement d’une autre pièce comptable ({}). Vous ne pouvez pas renverser une pièce comptable qui est le renversement d’une autre pièce." |
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,4 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import account_move |
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,33 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def _reverse_moves(self, default_values_list=None, cancel=False): | ||
for move in self: | ||
if move.reversal_move_id and move.journal_id.type not in ( | ||
"sale", | ||
"purchase", | ||
): | ||
raise UserError( | ||
_( | ||
"The accounting entry {} is already reversed (by entry {}). " | ||
"You can only reverse an accounting entry once." | ||
).format(move.display_name, move.reversal_move_id.display_name) | ||
) | ||
if move.reversed_entry_id and move.journal_id.type not in ( | ||
"sale", | ||
"purchase", | ||
): | ||
raise UserError( | ||
_( | ||
"The accounting entry {} is the reversal of another entry " | ||
"({}). You can not reverse a reversal accounting entry." | ||
).format(move.display_name, move.reversed_entry_id.display_name) | ||
) | ||
return super()._reverse_moves(default_values_list, cancel) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.4 KB
account_move_unique_reversal/static/description/reverse_reversal_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.9 KB
account_move_unique_reversal/static/description/reverse_reversed_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_account_move_unique_reversal |
109 changes: 109 additions & 0 deletions
109
account_move_unique_reversal/tests/test_account_move_unique_reversal.py
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,109 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields | ||
from odoo.exceptions import UserError | ||
from odoo.tests import common | ||
|
||
|
||
class TestAccountMoveUniqueReversal(common.SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.journal = cls.env["account.journal"].create( | ||
{"name": "Test", "code": "TEST", "type": "general"} | ||
) | ||
cls.journal_sale = cls.env["account.journal"].create( | ||
{ | ||
"name": "Test Sales Journal", | ||
"code": "tSAL", | ||
"type": "sale", | ||
} | ||
) | ||
cls.journal_purchase = cls.env["account.journal"].create( | ||
{ | ||
"name": "Test Purchase Journal", | ||
"code": "tPO", | ||
"type": "purchase", | ||
} | ||
) | ||
cls.today = fields.date.today() | ||
cls.account_1 = cls.env["account.account"].create( | ||
{ | ||
"name": "Account 1", | ||
"code": "501001", | ||
"account_type": "expense", | ||
} | ||
) | ||
cls.account_2 = cls.env["account.account"].create( | ||
{ | ||
"name": "Account 2", | ||
"code": "101001", | ||
"account_type": "asset_fixed", | ||
} | ||
) | ||
cls.move = cls._create_invoice(cls.journal) | ||
cls.move.action_post() | ||
|
||
cls.move_sale = cls._create_invoice(cls.journal_sale) | ||
cls.move_sale.action_post() | ||
|
||
cls.move_purchase = cls._create_invoice(cls.journal_purchase) | ||
cls.move_purchase.action_post() | ||
|
||
@classmethod | ||
def _create_invoice(cls, journal): | ||
move = cls.env["account.move"].create( | ||
{ | ||
"journal_id": journal.id, | ||
"date": cls.today, | ||
"line_ids": [ | ||
(0, 0, {"account_id": cls.account_1.id, "name": "/", "debit": 75}), | ||
(0, 0, {"account_id": cls.account_1.id, "name": "/", "debit": 25}), | ||
( | ||
0, | ||
0, | ||
{"account_id": cls.account_2.id, "name": "/", "credit": 100}, | ||
), | ||
], | ||
} | ||
) | ||
return move | ||
|
||
def test_reverse_reversed_entry_fail(self): | ||
self._reverse_move(self.move) | ||
with self.assertRaises(UserError): | ||
self._reverse_move(self.move) | ||
|
||
def test_reverse_reversed_entry_sale_pass(self): | ||
self._reverse_move(self.move_sale) | ||
assert self._reverse_move(self.move_sale) | ||
|
||
def test_reverse_reversed_entry_purchase_pass(self): | ||
self._reverse_move(self.move_purchase) | ||
assert self._reverse_move(self.move_purchase) | ||
|
||
def test_reverse_reversal_entry_fail(self): | ||
self._reverse_move(self.move) | ||
reversal_move = self.move.reversal_move_id | ||
with self.assertRaises(UserError): | ||
self._reverse_move(reversal_move) | ||
|
||
def test_reverse_reversal_entry_sale_pass(self): | ||
self._reverse_move(self.move_sale) | ||
reversal_move = self.move_sale.reversal_move_id | ||
assert self._reverse_move(reversal_move) | ||
|
||
def test_reverse_reversal_entry_purchase_pass(self): | ||
self._reverse_move(self.move_purchase) | ||
reversal_move = self.move_purchase.reversal_move_id | ||
assert self._reverse_move(reversal_move) | ||
|
||
def _reverse_move(self, move): | ||
wizard_env = self.env["account.move.reversal"] | ||
wizard_env = wizard_env.with_context( | ||
active_ids=[move.id], active_model="account.move" | ||
) | ||
return wizard_env.create( | ||
{"date": self.today, "journal_id": move.journal_id.id} | ||
).reverse_moves() |