2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from base_status.base_stage import base_stage
24 from crm import wizard
25 from osv import fields, osv
27 wizard.mail_compose_message.SUPPORTED_MODELS.append('crm.fundraising')
29 class crm_fundraising(base_stage, osv.osv):
30 """ Fund Raising Cases """
32 _name = "crm.fundraising"
33 _description = "Fund Raising"
35 _inherit = ['mail.thread']
37 'id': fields.integer('ID', readonly=True),
38 'name': fields.char('Name', size=128, required=True),
39 'active': fields.boolean('Active', required=False),
40 'date_action_last': fields.datetime('Last Action', readonly=1),
41 'date_action_next': fields.datetime('Next Action', readonly=1),
42 'description': fields.text('Description'),
43 'create_date': fields.datetime('Creation Date' , readonly=True),
44 'write_date': fields.datetime('Update Date' , readonly=True),
45 'date_deadline': fields.date('Deadline'),
46 'user_id': fields.many2one('res.users', 'Responsible'),
47 'section_id': fields.many2one('crm.case.section', 'Sales Team', \
48 select=True, help='Sales team to which Case belongs to. Define Responsible user and Email account for mail gateway.'),
49 'company_id': fields.many2one('res.company', 'Company'),
50 'partner_id': fields.many2one('res.partner', 'Partner'),
51 '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"),
52 'email_from': fields.char('Email', size=128, help="These people will receive email."),
53 'date_closed': fields.datetime('Closed', readonly=True),
54 'date': fields.datetime('Date'),
55 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
56 'categ_id': fields.many2one('crm.case.categ', 'Category', \
57 domain="[('section_id','=',section_id),\
58 ('object_id.model', '=', 'crm.fundraising')]"),
59 'planned_revenue': fields.float('Planned Revenue'),
60 'planned_cost': fields.float('Planned Costs'),
61 'probability': fields.float('Probability (%)'),
62 'partner_name': fields.char("Employee's Name", size=64),
63 'partner_name2': fields.char('Employee Email', size=64),
64 'partner_phone': fields.char('Phone', size=32),
65 'partner_mobile': fields.char('Mobile', size=32),
66 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_ids', '=', section_id)]"),
67 'type_id': fields.many2one('crm.case.resource.type', 'Campaign', \
68 domain="[('section_id','=',section_id)]"),
69 'duration': fields.float('Duration'),
70 'ref': fields.reference('Reference', selection=crm._links_get, size=128),
71 'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
72 'state': fields.related('stage_id', 'state', type="selection", store=True,
73 selection=crm.AVAILABLE_STATES, string="State", readonly=True,
74 help='The state is set to \'Draft\', when a case is created.\
75 If the case is in progress the state is set to \'Open\'.\
76 When the case is over, the state is set to \'Done\'.\
77 If the case needs to be reviewed then the state is \
78 set to \'Pending\'.'),
79 'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
84 'user_id': lambda s, cr, uid, c: s._get_default_user(cr, uid, c),
85 'partner_id': lambda s, cr, uid, c: s._get_default_partner(cr, uid, c),
86 'email_from': lambda s, cr, uid, c: s._get_default_email(cr, uid, c),
87 'section_id': lambda s, cr, uid, c: s._get_default_section_id(cr, uid, c),
88 'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
89 'priority': crm.AVAILABLE_PRIORITIES[2][0],
92 'planned_revenue': 0.0,
95 def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
96 """ Override of the base.stage method
97 Parameter of the stage search taken from the lead:
98 - section_id: if set, stages must belong to this section or
101 if isinstance(cases, (int, long)):
102 cases = self.browse(cr, uid, cases, context=context)
103 # collect all section_ids
106 section_ids.append(section_id)
109 section_ids.append(case.section_id.id)
110 # OR all section_ids and OR with case_default
113 search_domain += [('|')] * len(section_ids)
114 for section_id in section_ids:
115 search_domain.append(('section_ids', '=', section_id))
116 search_domain.append(('case_default', '=', True))
117 # AND with the domain in parameter
118 search_domain += list(domain)
119 # perform search, return the first found
120 stage_ids = self.pool.get('crm.case.stage').search(cr, uid, search_domain, order=order, context=context)
125 def message_new(self, cr, uid, msg, custom_values=None, context=None):
126 """Automatically called when new email message arrives"""
127 res_id = super(crm_fundraising,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
129 'name': msg.get('subject'),
130 'email_from': msg.get('from'),
131 'email_cc': msg.get('cc'),
132 'description': msg.get('body_text'),
134 priority = msg.get('priority')
136 vals['priority'] = priority
137 vals.update(self.message_partner_by_email(cr, uid, msg.get('from')))
138 self.write(cr, uid, [res_id], vals, context=context)
141 # ---------------------------------------------------
142 # OpenChatter methods and notifications
143 # ---------------------------------------------------
145 def case_get_note_msg_prefix(self, cr, uid, id, context=None):
146 """ Override of default prefix for notifications. """
149 def stage_set_send_note(self, cr, uid, ids, stage_id, context=None):
150 """ Override of the (void) default notification method. """
151 stage_name = self.pool.get('crm.case.stage').name_get(cr, uid, [stage_id], context=context)[0][1]
152 return self.message_append_note(cr, uid, ids, body= _("Stage changed to <b>%s</b>.") % (stage_name), context=context)
155 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: