You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

  1. # Copyright 2017 Tecnativa - Jairo Llopis <jairo.llopis@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class FetchmailServer(models.Model):
  5. _inherit = "fetchmail.server"
  6. default_thread_id = fields.Reference(
  7. selection="_get_thread_models",
  8. string="Default mail thread",
  9. help="Messages with no clear route will be posted as a new message "
  10. "to this thread.",
  11. )
  12. @api.model
  13. def _get_thread_models(self):
  14. """Get list of available ``mail.thread`` submodels.
  15. :return [(model, name), ...]:
  16. Tuple list of available models that can receive messages.
  17. """
  18. models = self.env["ir.model.fields"].search([
  19. ("name", "=", "message_partner_ids"),
  20. ]).mapped("model_id")
  21. # Exclude AbstractModel
  22. return [(m.model, m.name) for m in models
  23. if m.model in self.env and getattr(self.env[m.model], "_auto")]
  24. @api.onchange('type', 'is_ssl', 'object_id')
  25. def onchange_server_type(self):
  26. """Remove :attr:`default_thread_id` if there is :attr:`object_id`."""
  27. if self.object_id:
  28. self.default_thread_id = False
  29. return super(FetchmailServer, self).onchange_server_type()
  30. @api.multi
  31. @api.onchange("default_thread_id")
  32. def _onchange_remove_object_id(self):
  33. """Remove :attr:`object_id` if there is :attr:`default_thread_id`."""
  34. if self.default_thread_id:
  35. self.object_id = False