-
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#66820 [16.0][MIG] account_payment_cancel_group (#186)
* TA#66820 [16.0][MIG] account_payment_cancel_group --------- Co-authored-by: Majda EL MARIOULI <[email protected]>
- Loading branch information
1 parent
f077760
commit 116bd8c
Showing
16 changed files
with
250 additions
and
1 deletion.
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,34 @@ | ||
==================== | ||
Payment Cancel Group | ||
==================== | ||
|
||
.. contents:: Table of Contents | ||
|
||
Context | ||
------- | ||
In vanilla Odoo, when the module account_cancel is installed, users with basic accounting access | ||
are able to cancel a payment (if authorized on the journal). | ||
|
||
.. image:: static/description/payment_cancel_button.png | ||
|
||
.. image:: static/description/payment_cancelled_message.png | ||
|
||
Summary | ||
------- | ||
This module adds a user group allowed to cancel payments. | ||
|
||
.. image:: static/description/user_form.png | ||
|
||
The `Cancel` button on payments is only displayed for members of this group. | ||
|
||
Known Issues | ||
~~~~~~~~~~~~ | ||
As of Odoo version 14.0, the cancellation of payments passes through the status ``Draft``. | ||
|
||
In other words, a posted payment can be reset to draft, then it can be cancelled. | ||
|
||
Because of this new behavior, the module now restricts both ``Reset To Draft`` and ``Cancel`` buttons. | ||
|
||
Contributors | ||
------------ | ||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens) |
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 LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
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,21 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Payment Cancel Group", | ||
"version": "16.0.1.0.0", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"website": "https://www.numigi.com", | ||
"license": "LGPL-3", | ||
"category": "Accounting", | ||
"summary": "Add a user group allowed to cancel payments", | ||
"depends": [ | ||
"account", | ||
], | ||
"data": [ | ||
"security/res_groups.xml", | ||
"views/account_payment.xml", | ||
], | ||
"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,52 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_payment_cancel_group | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-06-21 20:40+0000\n" | ||
"PO-Revision-Date: 2024-06-21 15:40-0500\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"Language: fr\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
"X-Generator: Poedit 2.3\n" | ||
|
||
#. module: account_payment_cancel_group | ||
#: model:res.groups,name:account_payment_cancel_group.group_cancel_payments | ||
msgid "Cancel Payments" | ||
msgstr "Annulation de paiements" | ||
|
||
#. module: account_payment_cancel_group | ||
#: model:ir.model.fields,field_description:account_payment_cancel_group.field_account_move__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: account_payment_cancel_group | ||
#: model:ir.model.fields,field_description:account_payment_cancel_group.field_account_move__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: account_payment_cancel_group | ||
#: model:ir.model,name:account_payment_cancel_group.model_account_move | ||
msgid "Journal Entry" | ||
msgstr "" | ||
|
||
#. module: account_payment_cancel_group | ||
#: model:ir.model.fields,field_description:account_payment_cancel_group.field_account_move____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: account_payment_cancel_group | ||
#: code:addons/account_payment_cancel_group/models/account_move.py:0 | ||
#, python-format | ||
msgid "You are not authorized to reset to draft or cancel payments." | ||
msgstr "Vous n'êtes pas autorisé à remettre à brouillon ou annuler des paiements." | ||
|
||
#~ msgid "Payment Cancelled" | ||
#~ msgstr "Paiement annulé" |
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 LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
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,34 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import models, _ | ||
from odoo.exceptions import AccessError | ||
|
||
|
||
class AccountMove(models.Model): | ||
|
||
_inherit = "account.move" | ||
|
||
def button_draft(self): | ||
self._check_payment_cancel_authorization() | ||
return super().button_draft() | ||
|
||
def button_cancel(self): | ||
self._check_payment_cancel_authorization() | ||
return super().button_cancel() | ||
|
||
def _check_payment_cancel_authorization(self): | ||
if self._contains_payments() and not self._user_can_cancel_payments(): | ||
raise AccessError( | ||
_("You are not authorized to reset to draft or cancel payments.") | ||
) | ||
|
||
def _user_can_cancel_payments(self): | ||
return self.env.user.has_group( | ||
"account_payment_cancel_group.group_cancel_payments" | ||
) | ||
|
||
def _contains_payments(self): | ||
return self and bool( | ||
self.env["account.payment"].search([("move_id", "in", self.ids)]) | ||
) |
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="group_cancel_payments" model="res.groups"> | ||
<field name="name">Cancel Payments</field> | ||
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/> | ||
</record> | ||
|
||
</odoo> |
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
+82.1 KB
account_payment_cancel_group/static/description/payment_cancel_button.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
+88.9 KB
account_payment_cancel_group/static/description/payment_cancelled_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import test_payment_cancel |
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,65 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import pytest | ||
from odoo.tests import common | ||
from odoo.exceptions import AccessError | ||
|
||
|
||
class TestPaymentCancel(common.SavepointCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.user = cls.env["res.users"].create( | ||
{ | ||
"name": "Test User", | ||
"email": "[email protected]", | ||
"login": "[email protected]", | ||
"groups_id": [ | ||
(4, cls.env.ref("account.group_account_manager").id), | ||
], | ||
} | ||
) | ||
|
||
cls.journal = cls.env["account.journal"].create( | ||
{ | ||
"name": "Test Bank Journal", | ||
"type": "bank", | ||
"code": "TEST", | ||
} | ||
) | ||
|
||
cls.supplier = cls.env["res.partner"].create({"name": "Supplier"}) | ||
cls.payment = cls.env["account.payment"].create( | ||
{ | ||
"journal_id": cls.journal.id, | ||
"partner_id": cls.supplier.id, | ||
"amount": 100, | ||
"payment_type": "outbound", | ||
"payment_method_id": cls.env.ref( | ||
"account.account_payment_method_manual_out" | ||
).id, | ||
"partner_type": "supplier", | ||
} | ||
) | ||
|
||
def test_if_not_member_of_group__action_draft_not_allowed(self): | ||
with pytest.raises(AccessError): | ||
self.payment.with_user(self.user).action_draft() | ||
|
||
def test_if_not_member_of_group__action_cancel_not_allowed(self): | ||
with pytest.raises(AccessError): | ||
self.payment.with_user(self.user).action_cancel() | ||
|
||
def test_if_member_of_group__user_allowed(self): | ||
self.user.groups_id |= self.env.ref( | ||
"account_payment_cancel_group.group_cancel_payments" | ||
) | ||
self.payment.with_user(self.user).action_draft() | ||
assert self.payment.state == "draft" | ||
self.payment.with_user(self.user).action_cancel() | ||
assert self.payment.state == "cancel" | ||
|
||
def test_call_method_with_empty_recordset(self): | ||
self.env["account.payment"].with_user(self.user).action_draft() |
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,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="payment_form" model="ir.ui.view"> | ||
<field name="name">Payment Form: restrict Cancel button</field> | ||
<field name="model">account.payment</field> | ||
<field name="inherit_id" ref="account.view_account_payment_form"/> | ||
<field name="arch" type="xml"> | ||
<button name="action_cancel" position="attributes"> | ||
<attribute name="groups">account_payment_cancel_group.group_cancel_payments</attribute> | ||
</button> | ||
<button name="action_draft" position="attributes"> | ||
<attribute name="groups">account_payment_cancel_group.group_cancel_payments</attribute> | ||
</button> | ||
</field> | ||
</record> | ||
|
||
</odoo> |