[MERGE] Merge with lp:openobject-adddons
[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 from crm import wizard
25
26 wizard.mail_compose_message.SUPPORTED_MODELS.append('crm.fundraising')
27
28 class crm_fundraising(crm.crm_case, osv.osv):
29     """ Fund Raising Cases """
30
31     _name = "crm.fundraising"
32     _description = "Fund Raising"
33     _order = "id desc"
34     _inherit = ['mail.thread']
35     _columns = {
36             'id': fields.integer('ID', readonly=True),
37             'name': fields.char('Name', size=128, required=True),
38             'active': fields.boolean('Active', required=False),
39             'date_action_last': fields.datetime('Last Action', readonly=1),
40             'date_action_next': fields.datetime('Next Action', readonly=1),
41             'description': fields.text('Description'),
42             'create_date': fields.datetime('Creation Date' , readonly=True),
43             'write_date': fields.datetime('Update Date' , readonly=True),
44             'date_deadline': fields.date('Deadline'),
45             'user_id': fields.many2one('res.users', 'Responsible'),
46             'section_id': fields.many2one('crm.case.section', 'Sales Team', \
47                             select=True, help='Sales team to which Case belongs to. Define Responsible user and Email account for mail gateway.'),
48             'company_id': fields.many2one('res.company', 'Company'),
49             'partner_id': fields.many2one('res.partner', 'Partner'),
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="[('section_ids', '=', section_id)]"), 
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             'state': fields.selection(crm.AVAILABLE_STATES, 'Status', size=16, readonly=True,
72                                   help='The state is set to \'Draft\', when a case is created.\
73                                   \nIf the case is in progress the state is set to \'Open\'.\
74                                   \nWhen the case is over, the state is set to \'Done\'.\
75                                   \nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
76         }
77
78
79     def message_new(self, cr, uid, msg, custom_values=None, context=None):
80         """Automatically called when new email message arrives"""
81         res_id = super(crm_fundraising,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
82         vals = {
83             'name': msg.get('subject'),
84             'email_from': msg.get('from'),
85             'email_cc': msg.get('cc'),
86             'description': msg.get('body_text'),
87         }
88         priority = msg.get('priority')
89         if priority:
90             vals['priority'] = priority
91         vals.update(self.message_partner_by_email(cr, uid, msg.get('from')))
92         self.write(cr, uid, [res_id], vals, context=context)
93         return res_id
94
95
96     _defaults = {
97             'active': 1,
98             'user_id': crm.crm_case._get_default_user,
99             'partner_id': crm.crm_case._get_default_partner,
100             'email_from': crm.crm_case. _get_default_email,
101             'state': 'draft',
102             'section_id': crm.crm_case. _get_section,
103             'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
104             'priority': crm.AVAILABLE_PRIORITIES[2][0],
105             'probability': 0.0,
106             'planned_cost': 0.0,
107             'planned_revenue': 0.0,
108     }
109
110     def case_get_note_msg_prefix(self, cr, uid, id, context=None):
111         return 'Fund'
112
113     def create(self, cr, uid, vals, context=None):
114         obj_id = super(crm_fundraising, self).create(cr, uid, vals, context)
115         self.create_send_note(cr, uid, [obj_id], context=context)
116         return obj_id
117
118     def create_send_note(self, cr, uid, ids, context=None):
119         msg = '%s has been <b>created</b>.' % (self.case_get_note_msg_prefix(cr, uid, ids, context=context))
120         self.message_append_note(cr, uid, ids, body=msg, context=context)
121         return True
122
123
124 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: