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.

86 lines
3.6 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. return tuple(sorted(algorithms, lambda a, b: cmp(a[0], b[0])))
  40. _columns = {
  41. 'sequence': fields.integer('Sequence'),
  42. 'path': fields.char(
  43. 'Path', size=256, help='The path to your mail '
  44. 'folder. Typically would be something like \'INBOX.myfolder\'',
  45. required=True),
  46. 'model_id': fields.many2one('ir.model', 'Model', required=True),
  47. 'model_field': fields.char('Field (model)', size=128),
  48. 'model_order': fields.char('Order (model)', size=128),
  49. 'match_algorithm': fields.selection(
  50. _get_match_algorithms_sel,
  51. 'Match algorithm', required=True, translate=True),
  52. 'mail_field': fields.char('Field (email)', size=128),
  53. 'server_id': fields.many2one('fetchmail.server', 'Server'),
  54. 'delete_matching': fields.boolean('Delete matches'),
  55. 'flag_nonmatching': fields.boolean('Flag nonmatching'),
  56. 'match_first': fields.boolean('Use 1st match'),
  57. 'domain': fields.char(
  58. 'Domain', size=128, help='Fill in a search '
  59. 'filter to narrow down objects to match')
  60. }
  61. _defaults = {
  62. 'flag_nonmatching': True,
  63. }
  64. def get_algorithm(self, cr, uid, ids, context=None):
  65. for this in self.browse(cr, uid, ids, context):
  66. return self._get_match_algorithms()[this.match_algorithm]()
  67. def button_attach_mail_manually(self, cr, uid, ids, context=None):
  68. for this in self.browse(cr, uid, ids, context):
  69. context.update({'default_folder_id': this.id})
  70. return {
  71. 'type': 'ir.actions.act_window',
  72. 'res_model': 'fetchmail.attach.mail.manually',
  73. 'target': 'new',
  74. 'context': context,
  75. 'view_type': 'form',
  76. 'view_mode': 'form',
  77. }