# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import _, api, fields, models from odoo.exceptions import UserError class UtmMedium(models.Model): _name = 'utm.medium' _description = 'UTM Medium' _order = 'name' name = fields.Char(string='Medium Name', required=True, translate=True) active = fields.Boolean(default=True) @api.ondelete(at_uninstall=False) def _unlink_except_utm_medium_email(self): utm_medium_email = self.env.ref('utm.utm_medium_email', raise_if_not_found=False) if utm_medium_email and utm_medium_email in self: raise UserError(_( "The UTM medium '%s' cannot be deleted as it is used in some main " "functional flows, such as the recruitment and the mass mailing.", utm_medium_email.name ))