diff --git a/account_type_inactive/models/account_type.py b/account_type_inactive/models/account_type.py index 9f37e5180..a479b2601 100644 --- a/account_type_inactive/models/account_type.py +++ b/account_type_inactive/models/account_type.py @@ -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)))