~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to project/wizard/close_task.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# WARNING: This program as such is intended to be used by professional
 
6
# programmers who take the whole responsability of assessing all potential
 
7
# consequences resulting from its eventual inadequacies and bugs
 
8
# End users who are looking for a ready-to-use solution with commercial
 
9
# garantees and support are strongly adviced to contract a Free Software
 
10
# Service Company
 
11
#
 
12
# This program is Free Software; you can redistribute it and/or
 
13
# modify it under the terms of the GNU General Public License
 
14
# as published by the Free Software Foundation; either version 2
 
15
# of the License, or (at your option) any later version.
 
16
#
 
17
# This program is distributed in the hope that it will be useful,
 
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
# GNU General Public License for more details.
 
21
#
 
22
# You should have received a copy of the GNU General Public License
 
23
# along with this program; if not, write to the Free Software
 
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
25
#
 
26
##############################################################################
 
27
 
 
28
import wizard
 
29
from tools import email_send as email
 
30
import pooler
 
31
 
 
32
mail_form = """<?xml version="1.0" ?>
 
33
<form string="Send mail to customer">
 
34
        <field name="email" colspan="4"/>
 
35
        <field name="description" colspan="4"/>
 
36
</form>"""
 
37
 
 
38
mail_fields = {
 
39
        'email': {'string': 'E-Mails', 'type': 'char', 'required': 'True', 'size':64},
 
40
        'description': {'string':'Description', 'type':'text', 'required':'True'},
 
41
}
 
42
 
 
43
def email_send(cr, uid, ids, to_adr, description, context={}):
 
44
        for task in pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, ids, context):
 
45
                project = task.project_id
 
46
                subject = "Task '%s' closed" % task.name
 
47
                if task.user_id and task.user_id.address_id and task.user_id.address_id.email:
 
48
                        from_adr = task.user_id.address_id.email
 
49
                        signature = task.user_id.signature
 
50
                else:
 
51
                        raise osv.except_osv('Error', "Couldn't send mail because your email address is not configured!")
 
52
 
 
53
                if to_adr:
 
54
                        val = {
 
55
                                'name': task.name,
 
56
                                'user_id': task.user_id.name,
 
57
                                'task_id': "%d/%d" % (project.id, task.id),
 
58
                                'date_start': task.date_start,
 
59
                                'date_close': task.date_close,
 
60
                                'state': task.state
 
61
                        }
 
62
                        header = (project.warn_header or '') % val
 
63
                        footer = (project.warn_footer or '') % val
 
64
                        body = u'%s\n%s\n%s\n\n-- \n%s' % (header, description, footer, signature)
 
65
                        email(from_adr, [to_adr], subject, body.encode('utf-8'), email_bcc=[from_adr])
 
66
                else:
 
67
                        raise osv.except_osv('Error', "Couldn't send mail because the contact for this task (%s) has no email address!"% contact.name)
 
68
 
 
69
class wizard_close(wizard.interface):
 
70
        def _check_complete(self, cr, uid, data, context):
 
71
                task = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids'])[0]
 
72
                if not task.project_id.warn_customer:
 
73
                        return 'close'
 
74
                return 'mail_ask'
 
75
 
 
76
        def _get_data(self, cr, uid, data, context):
 
77
                email = ''
 
78
                task = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, data['ids'][0])
 
79
                partner_id = task.partner_id or task.project_id.partner_id
 
80
                if partner_id and partner_id.address[0].email:
 
81
                        email = partner_id.address[0].email
 
82
                return {'description': task.cust_desc or task.description, 'email':email}
 
83
                
 
84
        def _data_send(self, cr, uid, data, context):
 
85
                task_obj = pooler.get_pool(cr.dbname).get('project.task')
 
86
                if data['form']['email']:
 
87
                        description = data['form'].get('description', False)
 
88
                        if description:
 
89
                                val = {'cust_desc': description}
 
90
                                task_obj.write(cr, uid, [data['ids'][0]], val)
 
91
                        email_send(cr, uid, data['ids'], data['form']['email'], data['form']['description'])
 
92
                return {}
 
93
 
 
94
        def _do_close(self, cr, uid, data, context):
 
95
                task_obj = pooler.get_pool(cr.dbname).get('project.task')
 
96
                task_obj.do_close(cr, uid, data['ids'], context)
 
97
                return {}
 
98
 
 
99
        states = {
 
100
                'init': {
 
101
                        'actions': [],
 
102
                        'result': {'type':'choice', 'next_state':_check_complete}
 
103
                },
 
104
                'mail_ask': {
 
105
                        'actions': [_get_data],
 
106
                        'result': {'type':'form', 'arch':mail_form, 'fields':mail_fields, 'state':[('end', 'Cancel'), ('close', 'Quiet close'), ('mail_send', 'Send Message')]},
 
107
                },
 
108
                'mail_send': {
 
109
                        'actions': [_data_send],
 
110
                        'result': {'type':'state', 'state':'close'},
 
111
                },
 
112
                'close': {
 
113
                        'actions': [_do_close],
 
114
                        'result': {'type':'state', 'state':'end'},
 
115
                },
 
116
        }
 
117
wizard_close('project.task.close')
 
118