[IMP] imporve action_send_mail method in related module. hr_recruitment :- call email...
[odoo/odoo.git] / addons / crm_fundraising / crm_fundraising.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 crm import crm
24 import tools
25
26 class crm_fundraising(crm.crm_case, osv.osv):
27     """ Fund Raising Cases """
28
29     _name = "crm.fundraising"
30     _description = "Fund Raising"
31     _order = "id desc"
32     _inherit = ['mailgate.thread']
33     _columns = {
34             'id': fields.integer('ID'),
35             'name': fields.char('Name', size=128, required=True),
36             'active': fields.boolean('Active', required=False),
37             'date_action_last': fields.datetime('Last Action', readonly=1),
38             'date_action_next': fields.datetime('Next Action', readonly=1),
39             'description': fields.text('Description'),
40             'create_date': fields.datetime('Creation Date' , readonly=True),
41             'write_date': fields.datetime('Update Date' , readonly=True),
42             'date_deadline': fields.date('Deadline'),
43             'user_id': fields.many2one('res.users', 'Responsible'),
44             'section_id': fields.many2one('crm.case.section', 'Sales Team', \
45                             select=True, help='Sales team to which Case belongs to. Define Responsible user and Email account for mail gateway.'),
46             'company_id': fields.many2one('res.company', 'Company'),
47             'partner_id': fields.many2one('res.partner', 'Partner'),
48             'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
49                                  domain="[('partner_id','=',partner_id)]"),
50             'email_cc': fields.text('Watchers Emails', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
51             'email_from': fields.char('Email', size=128, help="These people will receive email."),
52             'date_closed': fields.datetime('Closed', readonly=True),
53             'date': fields.datetime('Date'),
54             'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
55             'categ_id': fields.many2one('crm.case.categ', 'Category', \
56                                 domain="[('section_id','=',section_id),\
57                                 ('object_id.model', '=', 'crm.fundraising')]"),
58             'planned_revenue': fields.float('Planned Revenue'),
59             'planned_cost': fields.float('Planned Costs'),
60             'probability': fields.float('Probability (%)'),
61             'partner_name': fields.char("Employee's Name", size=64),
62             'partner_name2': fields.char('Employee Email', size=64),
63             'partner_phone': fields.char('Phone', size=32),
64             'partner_mobile': fields.char('Mobile', size=32),
65             'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('type', '=', 'fundraising')]"),
66             'type_id': fields.many2one('crm.case.resource.type', 'Campaign', \
67                              domain="[('section_id','=',section_id)]"),
68             'duration': fields.float('Duration'),
69             'ref': fields.reference('Reference', selection=crm._links_get, size=128),
70             'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
71             'canal_id': fields.many2one('res.partner.canal', 'Channel', \
72                         help="The channels represent the different communication \
73  modes available with the customer."),
74             'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
75                                   help='The state is set to \'Draft\', when a case is created.\
76                                   \nIf the case is in progress the state is set to \'Open\'.\
77                                   \nWhen the case is over, the state is set to \'Done\'.\
78                                   \nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
79             'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
80         }
81
82     _defaults = {
83             'active': lambda *a: 1,
84             'user_id': crm.crm_case._get_default_user,
85             'partner_id': crm.crm_case._get_default_partner,
86             'partner_address_id': crm.crm_case._get_default_partner_address,
87             'email_from': crm.crm_case. _get_default_email,
88             'state': lambda *a: 'draft',
89             'section_id': crm.crm_case. _get_section,
90             'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
91             'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
92             'probability': lambda *a:0.0,
93             'planned_cost': lambda *a:0.0,
94             'planned_revenue': lambda *a:0.0,
95             }
96
97     def action_send_email(self, cr, uid, ids, context=None):
98         """
99             Open Send email wizard.
100         """
101         if context is None:
102             context = {}
103         for data in self.browse(cr, uid ,ids, context):
104             context.update({
105                     'mail':'new',
106                     'default_name': data.name,
107                     'default_email_to': data.email_from,
108                     'default_email_from': data.user_id and data.user_id.address_id and data.user_id.address_id.email,
109                     'default_description': '\n' + (tools.ustr(data.user_id.signature or '')),
110                     'default_model': context.get('model',''),
111                     'default_email_cc': tools.ustr(data.email_cc or ''),
112                     'default_res_id': context.get('rec_id',0)
113                 })
114             if hasattr(data, 'section_id'):
115                 context.update({'default_reply_to': data.section_id and data.section_id.reply_to or False})
116
117         result = {
118                 'view_type': 'form',
119                 'view_mode': 'form',
120                 'res_model': 'email.message.wizard_send',
121                 'view_id': False,
122                 'context': context,
123                 'type': 'ir.actions.act_window',
124                 'target': 'new',
125                 'nodestroy': True
126                 }
127         return result
128
129 crm_fundraising()
130
131
132 class crm_stage_fundraising(osv.osv):
133
134     def _get_type_value(self, cr, user, context):
135         list = super(crm_stage_fundraising, self)._get_type_value(cr, user, context)
136         list.append(('fundraising','Fundraising'))
137         return list
138
139     _inherit = "crm.case.stage"
140     _columns = {
141             'type': fields.selection(_get_type_value, 'Type'),
142     }
143
144
145 crm_stage_fundraising()