2018-08-05 20:33:56 +02:00
|
|
|
# Copyright 2009-2017 Noviat
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2020-01-29 18:34:31 +01:00
|
|
|
from odoo import _, api, fields, models
|
2018-08-05 20:33:56 +02:00
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
|
|
|
|
|
|
class AccountAccount(models.Model):
|
2020-01-29 18:34:31 +01:00
|
|
|
_inherit = "account.account"
|
2018-08-05 20:33:56 +02:00
|
|
|
|
|
|
|
asset_profile_id = fields.Many2one(
|
2020-01-29 18:34:31 +01:00
|
|
|
comodel_name="account.asset.profile",
|
|
|
|
string="Asset Profile",
|
|
|
|
help="Default Asset Profile when creating invoice lines " "with this account.",
|
|
|
|
)
|
2018-08-05 20:33:56 +02:00
|
|
|
|
2020-01-29 18:34:31 +01:00
|
|
|
@api.constrains("asset_profile_id")
|
2018-08-05 20:33:56 +02:00
|
|
|
def _check_asset_profile(self):
|
|
|
|
for account in self:
|
2020-01-29 18:34:31 +01:00
|
|
|
if (
|
|
|
|
account.asset_profile_id
|
|
|
|
and account.asset_profile_id.account_asset_id != account
|
|
|
|
):
|
|
|
|
raise ValidationError(
|
|
|
|
_(
|
|
|
|
"The Asset Account defined in the Asset Profile "
|
|
|
|
"must be equal to the account."
|
|
|
|
)
|
|
|
|
)
|