From 851e71e5a60ce0947c8659ee091de9c9bc179228 Mon Sep 17 00:00:00 2001 From: Boris Gallet Date: Wed, 15 May 2024 09:07:29 +0200 Subject: [PATCH] =?UTF-8?q?[IMP]=20account=5Fmove=5Fprotect=5Fdeleting=20:?= =?UTF-8?q?=20use=20the=20move=5Fid=20to=20check=20if=20it=E2=80=99s=20CAS?= =?UTF-8?q?H=20deposit=20or=20CHQ=20deposit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/account_move.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/account_move_protect_deleting/models/account_move.py b/account_move_protect_deleting/models/account_move.py index e2e4545..33019a0 100644 --- a/account_move_protect_deleting/models/account_move.py +++ b/account_move_protect_deleting/models/account_move.py @@ -1,6 +1,5 @@ from odoo import models, api, _ from odoo.exceptions import UserError -import re class AccountMove(models.Model): _inherit = 'account.move' @@ -9,18 +8,26 @@ class AccountMove(models.Model): def _check_posted(self): """ Prevent deletion of a account move if it has been posted exeptions : Check deposit or Cash deposit. In V16 in odoo the account move is deleted - when the check deposit is reset to draft. + when the check deposit is reset to draft. This work the same with Cash deposit """ - pattern_CHQ_DEPOSIT = r"DEP\d{3}" - pattern_CASH_DEPOSIT = r"CASH-DEP-\d{3}" + # search in account.cash.deposit if account move is this one + for cash_deposit in self.env['account.cash.deposit'].search([]): + if cash_deposit.move_id == self: + print (cash_deposit.move_id, self) + is_cash_deposit = True + + # search in account.check.deposit if account move is this one + for check_deposit in self.env['account.check.deposit'].search([]): + if check_deposit.move_id == self: + is_check_deposit = True if ( - self.posted_before and - ( - not re.search(pattern_CHQ_DEPOSIT, self.ref) - and not re.search(pattern_CASH_DEPOSIT, self.ref) + self.posted_before and + ( + not is_cash_deposit + and not is_check_deposit ) ): raise UserError(_(""