wiz_meeting.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  6. # Copyright (C) 2011-Today Serpent Consulting Services PVT. LTD.
  7. # (<http://www.serpentcs.com>)
  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 import models, fields, api, _
  23. from openerp.exceptions import except_orm
  24. class StudentMeeting(models.TransientModel):
  25. _name = "student.meeting"
  26. name = fields.Char('Meeting Subject', size=128, required=True)
  27. meeting_date = fields.Datetime('Meeting Date', required=True)
  28. deadline = fields.Datetime('Deadline', required=True)
  29. description = fields.Text('Description')
  30. @api.multi
  31. def set_meeting(self):
  32. cur_rec = self.browse(self.id)
  33. student_obj = self.env['student.student']
  34. cal_event_obj = self.env['calendar.event']
  35. attendee_ids = []
  36. flag = False
  37. error_student = ''
  38. for student in student_obj.browse(self._context['active_ids']):
  39. if not student.email:
  40. flag = True
  41. error_student += (student.pid + " : " + student.name + " " +
  42. student.middle + " " + student.last + "\n")
  43. else:
  44. attendee_ids.append((0, 0, {'user_id': student.user_id.id,
  45. 'email': student.email}))
  46. if flag:
  47. raise except_orm(_('Error !'), _("Following Student don't have \
  48. Email ID.\n\n" + error_student + "\nMeeting \
  49. cannot be scheduled."))
  50. cal_event_obj.create({
  51. 'name': cur_rec.name,
  52. 'start': cur_rec.meeting_date,
  53. 'stop': cur_rec.deadline,
  54. 'description': cur_rec.description,
  55. 'attendee_ids': attendee_ids
  56. })
  57. return {'type': 'ir.actions.act_window_close'}