Add constraint if account type is used on account.account

This commit is contained in:
Akim Juillerat
2017-07-04 13:56:42 +02:00
parent 206e602ae6
commit d36177ae7e

View File

@@ -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)))