[IMP] account_advanced_protection_features : remove exceptions about cash and check deposits when trying to delete an posted account move

This commit is contained in:
2025-09-15 12:54:21 +02:00
committed by mondot
parent 04da189e5e
commit c7254a7b84
3 changed files with 8 additions and 33 deletions

View File

@@ -5,6 +5,7 @@ account_advanced_protection_features
This module adds several protection features about accounting : This module adds several protection features about accounting :
* Forbid to delete an invoice that has already been validated * Forbid to delete an invoice that has already been validated
* Forbid to reset to draft an invoice that has already been sent by email * Forbid to reset to draft an invoice that has already been sent by email
* Allow bank statements and bank statement lines deletion
Installation Installation
============ ============
@@ -31,6 +32,7 @@ Credits
Contributors Contributors
------------ ------------
* Laetitia Da Costa (https://github.com/LaetitiaElabore)
* Boris Gallet - `Email<mailto:boris.gallet@elabore.coop>` - `Github<https://github.com/b0g>` * Boris Gallet - `Email<mailto:boris.gallet@elabore.coop>` - `Github<https://github.com/b0g>`
* Clément Thomas * Clément Thomas
* Quentin Mondot - `Email<mailto:quentin.mondot@elabore.coop>` - `Github<https://github.com/mondot>` * Quentin Mondot - `Email<mailto:quentin.mondot@elabore.coop>` - `Github<https://github.com/mondot>`

View File

@@ -94,7 +94,7 @@ msgstr ""
#. odoo-python #. odoo-python
#: code:addons/account_advanced_protection_features/models/account_move.py:0 #: code:addons/account_advanced_protection_features/models/account_move.py:0
#, python-format #, python-format
msgid "You cannot delete this account move because it has been posted." msgid "You cannot delete this account move because it has already been posted."
msgstr "" msgstr ""
"Vous ne pouvez pas supprimer cette pièce comptable car elle à déjà été " "Vous ne pouvez pas supprimer cette pièce comptable car elle à déjà été "
"confirmée." "confirmée."

View File

@@ -13,38 +13,11 @@ class AccountMove(models.Model):
@api.ondelete(at_uninstall=False) @api.ondelete(at_uninstall=False)
def _check_posted(self): def _check_posted(self):
""" Prevent deletion of an account move if it has been posted """ Prevent deletion of an account move if it has already been posted and
exceptions : Check deposit or Cash deposit. In V16 in odoo the account move is deleted journal parameter prevent_deletion_of_posted_account_move is activated
when the check deposit is reset to draft.
This work the same with Cash deposit
""" """
for rec in self: for rec in self:
if not rec.journal_id.prevent_deletion_of_posted_account_move: if rec.posted_before and rec.journal_id.prevent_deletion_of_posted_account_move:
continue raise UserError(_(
"You cannot delete this account move because it has already been posted."
is_cash_deposit = False
is_check_deposit = False
# search in account.cash.deposit if account move is this one
if rec.env.get('account.cash.deposit'):
for cash_deposit in rec.env['account.cash.deposit'].search([]):
if cash_deposit.move_id == rec:
print(cash_deposit.move_id, rec)
is_cash_deposit = True
# # search in account.check.deposit if account move is this one
if rec.env.get('account.check.deposit'):
for check_deposit in rec.env['account.check.deposit'].search([]):
if check_deposit.move_id == rec:
is_check_deposit = True
if (
rec.posted_before and
(
not is_cash_deposit
and not is_check_deposit
)
):
raise UserError(_(""
"You cannot delete this account move because it has been posted."
)) ))