[IMP] account_move_protect_deleting : use the move_id to check if it’s CASH deposit or CHQ deposit
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from odoo import models, api, _
|
from odoo import models, api, _
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
import re
|
|
||||||
|
|
||||||
class AccountMove(models.Model):
|
class AccountMove(models.Model):
|
||||||
_inherit = 'account.move'
|
_inherit = 'account.move'
|
||||||
@@ -13,14 +12,22 @@ class AccountMove(models.Model):
|
|||||||
This work the same with Cash deposit
|
This work the same with Cash deposit
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pattern_CHQ_DEPOSIT = r"DEP\d{3}"
|
# search in account.cash.deposit if account move is this one
|
||||||
pattern_CASH_DEPOSIT = r"CASH-DEP-\d{3}"
|
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 (
|
if (
|
||||||
self.posted_before and
|
self.posted_before and
|
||||||
(
|
(
|
||||||
not re.search(pattern_CHQ_DEPOSIT, self.ref)
|
not is_cash_deposit
|
||||||
and not re.search(pattern_CASH_DEPOSIT, self.ref)
|
and not is_check_deposit
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
raise UserError(_(""
|
raise UserError(_(""
|
||||||
|
Reference in New Issue
Block a user