[IMP] account: unique description for wizard model
[odoo/odoo.git] / addons / project_scrum / wizard / project_scrum_email.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import fields, osv
23 from tools.translate import _
24 from datetime import datetime
25 import tools
26
27 class project_scrum_email(osv.osv_memory):
28     _name = 'project.scrum.email'
29
30     def default_get(self, cr, uid, fields, context=None):
31         """
32         This function gets default values
33         @param self: The object pointer
34         @param cr: the current row, from the database cursor,
35         @param uid: the current user’s ID for security checks,
36         @param fields: List of fields for default value
37         @param context: A standard dictionary for contextual values
38
39         @return : default values of fields.
40         """
41         if context is None:
42             context = {}
43         meeting_pool = self.pool.get('project.scrum.meeting')
44         record_ids = context and context.get('active_ids', []) or []
45         res = super(project_scrum_email, self).default_get(cr, uid, fields, context=context)
46         for meeting in meeting_pool.browse(cr, uid, record_ids, context=context):
47             sprint = meeting.sprint_id
48             if 'scrum_master_email' in fields:
49                 res.update({'scrum_master_email': sprint.scrum_master_id and sprint.scrum_master_id.user_email or False})
50             if 'product_owner_email' in fields:
51                 res.update({'product_owner_email': sprint.product_owner_id and sprint.product_owner_id.user_email or False})
52             if 'subject' in fields:
53                 subject = _("Scrum Meeting : %s") %(meeting.date)
54                 res.update({'subject': subject})
55             if 'message' in fields:
56                 message = _("Hello  , \nI am sending you Scrum Meeting : %s for the Sprint  '%s' of Project '%s'") %(meeting.date, sprint.name, sprint.project_id.name)
57                 res.update({'message': message})
58         return res
59
60     _columns = {
61         'scrum_master_email': fields.char('Scrum Master Email', size=64, help="Email Id of Scrum Master"),
62         'product_owner_email': fields.char('Product Owner Email', size=64, help="Email Id of Product Owner"),
63         'subject':fields.char('Subject', size=64),
64         'message':fields.text('Message'),
65
66     }
67
68     def button_send_scrum_email(self, cr, uid, ids, context=None):
69         if context is None:
70             context = {}
71
72         mail_message = self.pool.get('mail.message')
73         active_id = context.get('active_id', False)
74         scrum_meeting_pool = self.pool.get('project.scrum.meeting')
75         user_pool = self.pool.get('res.users')
76         meeting = scrum_meeting_pool.browse(cr, uid, active_id, context=context)
77
78 #        wizard data
79         data_id = ids and ids[0] or False
80         if not data_id or not active_id:
81             return False
82         data = self.browse(cr, uid, data_id, context=context)
83
84         email_from = tools.config.get('email_from', False)
85         user = user_pool.browse(cr, uid, uid, context=context)
86         user_email = email_from or user.user_email
87
88         body = "%s\n" %(data.message)
89         body += "\n%s\n" %_('Tasks since yesterday')
90         body += "_______________________\n"
91         body += "\n%s\n" %(meeting.question_yesterday or _('None'))
92         body += "\n%s\n" %_("Task for Today")
93         body += "_______________________ \n"
94         body += "\n%s\n" %(meeting.question_today or _('None'))
95         body += "\n%s\n" % _('Blocking points encountered:')
96         body += "_______________________ \n"
97         body += "\n%s\n" %(meeting.question_blocks or _('None'))
98         body += "\n%s\n%s" %(_('Thank you,'), user.name)
99         if user.signature:
100             body += "\n%s" %(user.signature)
101         if data.scrum_master_email == data.product_owner_email:
102             data.product_owner_email = False
103         if data.scrum_master_email:
104             mail_message.schedule_with_attach(cr, uid, user_email, [data.scrum_master_email], data.subject, body, reply_to=user_email, context=context)
105         if data.product_owner_email:
106             mail_message.schedule_with_attach(cr, uid, user_email, [data.product_owner_email], data.subject, body, reply_to=user_email, context=context)
107         return {'type': 'ir.actions.act_window_close'}