utm_medium.py 857 B

123456789101112131415161718192021222324
  1. # -*- coding:utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import _, api, models
  4. from odoo.exceptions import UserError
  5. class UtmMedium(models.Model):
  6. _inherit = 'utm.medium'
  7. @api.ondelete(at_uninstall=False)
  8. def _unlink_except_linked_mailings(self):
  9. """ Already handled by ondelete='restrict', but let's show a nice error message """
  10. linked_mailings = self.env['mailing.mailing'].sudo().search([
  11. ('medium_id', 'in', self.ids)
  12. ])
  13. if linked_mailings:
  14. raise UserError(_(
  15. "You cannot delete these UTM Mediums as they are linked to the following mailings in "
  16. "Mass Mailing:\n%(mailing_names)s",
  17. mailing_names=', '.join(['"%s"' % subject for subject in linked_mailings.mapped('subject')])))