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.

49 lines
1.7 KiB

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