mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Add constraint if account type is used on account.account
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
# Copyright 2017 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models, fields
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountAccountType(models.Model):
|
||||
@@ -10,3 +11,13 @@ class AccountAccountType(models.Model):
|
||||
_inherit = 'account.account.type'
|
||||
|
||||
active = fields.Boolean('Active', default=True)
|
||||
|
||||
@api.constrains('active')
|
||||
def _check_account_moves(self):
|
||||
if not self.active:
|
||||
accounts = self.env['account.account'].search([
|
||||
('user_type_id', '=', self.id)])
|
||||
if accounts:
|
||||
raise ValidationError(_('You cannot inactive this account type'
|
||||
' as this type is is used on %d '
|
||||
'accounts.' % len(accounts)))
|
||||
|
||||
Reference in New Issue
Block a user