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.

111 lines
4.4 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2013 Therp BV (<http://therp.nl>)
  6. # All Rights Reserved
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ########################################################################
  22. from openerp.osv import fields
  23. from openerp.osv.orm import Model
  24. from .. import match_algorithm
  25. class fetchmail_server_folder(Model):
  26. _name = 'fetchmail.server.folder'
  27. _rec_name = 'path'
  28. def _get_match_algorithms(self):
  29. def get_all_subclasses(cls):
  30. return cls.__subclasses__() + [subsub
  31. for sub in cls.__subclasses__()
  32. for subsub in get_all_subclasses(sub)]
  33. return dict([(cls.__name__, cls) for cls in get_all_subclasses(
  34. match_algorithm.base.base)])
  35. def _get_match_algorithms_sel(self, cr, uid, context=None):
  36. algorithms = []
  37. for cls in self._get_match_algorithms().itervalues():
  38. algorithms.append((cls.__name__, cls.name))
  39. algorithms.sort()
  40. return algorithms
  41. _columns = {
  42. 'sequence': fields.integer('Sequence'),
  43. 'path': fields.char(
  44. 'Path', size=256, help='The path to your mail '
  45. "folder. Typically would be something like 'INBOX.myfolder'",
  46. required=True),
  47. 'model_id': fields.many2one(
  48. 'ir.model', 'Model', required=True,
  49. help='The model to attach emails to'),
  50. 'model_field': fields.char(
  51. 'Field (model)', size=128,
  52. help='The field in your model that contains the field to match '
  53. 'against.\n'
  54. 'Examples:\n'
  55. "'email' if your model is res.partner, or "
  56. "'partner_id.email' if you're matching sale orders"),
  57. 'model_order': fields.char(
  58. 'Order (model)', size=128,
  59. help='Fields to order by, this mostly useful in conjunction '
  60. "with 'Use 1st match'"),
  61. 'match_algorithm': fields.selection(
  62. _get_match_algorithms_sel,
  63. 'Match algorithm', required=True, translate=True,
  64. help='The algorithm used to determine which object an email '
  65. 'matches.'),
  66. 'mail_field': fields.char(
  67. 'Field (email)', size=128,
  68. help='The field in the email used for matching. Typically '
  69. "this is 'to' or 'from'"),
  70. 'server_id': fields.many2one('fetchmail.server', 'Server'),
  71. 'delete_matching': fields.boolean(
  72. 'Delete matches',
  73. help='Delete matched emails from server'),
  74. 'flag_nonmatching': fields.boolean(
  75. 'Flag nonmatching',
  76. help="Flag emails in the server that don't match any object "
  77. 'in OpenERP'),
  78. 'match_first': fields.boolean(
  79. 'Use 1st match',
  80. help='If there are multiple matches, use the first one. If '
  81. 'not checked, multiple matches count as no match at all'),
  82. 'domain': fields.char(
  83. 'Domain', size=128, help='Fill in a search '
  84. 'filter to narrow down objects to match')
  85. }
  86. _defaults = {
  87. 'flag_nonmatching': True,
  88. }
  89. def get_algorithm(self, cr, uid, ids, context=None):
  90. for this in self.browse(cr, uid, ids, context):
  91. return self._get_match_algorithms()[this.match_algorithm]()
  92. def button_attach_mail_manually(self, cr, uid, ids, context=None):
  93. for this in self.browse(cr, uid, ids, context):
  94. context.update({'default_folder_id': this.id})
  95. return {
  96. 'type': 'ir.actions.act_window',
  97. 'res_model': 'fetchmail.attach.mail.manually',
  98. 'target': 'new',
  99. 'context': context,
  100. 'view_type': 'form',
  101. 'view_mode': 'form',
  102. }