2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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 ##############################################################################
29 from tools.translate import _
32 from osv import fields,osv,orm
33 from osv.orm import except_orm
35 AVAILABLE_PRIORITIES = [
43 def _links_get(self, cr, uid, context={}):
44 obj = self.pool.get('res.request.link')
45 ids = obj.search(cr, uid, [])
46 res = obj.read(cr, uid, ids, ['object', 'name'], context)
47 return [(r['object'], r['name']) for r in res]
49 class crm_opportunity_categ(osv.osv):
50 _name = "crm.opportunity.categ"
51 _description = "Opportunity Categories"
53 'name': fields.char('Category Name', size=64, required=True),
54 'probability': fields.float('Probability (%)', required=True),
55 'section_id': fields.many2one('crm.case.section', 'Case Section'),
58 'probability': lambda *args: 0.0
60 crm_opportunity_categ()
62 class crm_opportunity(osv.osv):
63 _name = "crm.opportunity"
64 _description = "Opportunity Cases"
68 'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id)]"),
69 'categ_id': fields.many2one('crm.opportunity.categ', 'Category', domain="[('section_id','=',section_id)]"),
70 'category2_id': fields.many2one('crm.case.category2', 'Category Name', domain="[('section_id','=',section_id)]"),
71 'priority': fields.selection(AVAILABLE_PRIORITIES, 'Priority'),
72 'probability': fields.float('Probability (%)'),
73 'planned_revenue': fields.float('Planned Revenue'),
74 'planned_cost': fields.float('Planned Costs'),
75 'canal_id': fields.many2one('res.partner.canal', 'Channel',help="The channels represent the different communication modes available with the customer." \
76 " With each commercial opportunity, you can indicate the canall which is this opportunity source."),
77 'som': fields.many2one('res.partner.som', 'State of Mind', help="The minds states allow to define a value scale which represents" \
78 "the partner mentality in relation to our services.The scale has" \
79 "to be created with a factor for each level from 0 (Very dissatisfied) to 10 (Extremely satisfied)."),
80 'ref' : fields.reference('Reference', selection=_links_get, size=128),
81 'ref2' : fields.reference('Reference 2', selection=_links_get, size=128),
82 'date_closed': fields.datetime('Closed', readonly=True),
83 'lead_id':fields.many2one ('crm.lead', 'Lead'),
84 'phonecall_id':fields.many2one ('crm.phonecall', 'Phonecall'),
87 def msg_new(self, cr, uid, msg):
88 mailgate_obj = self.pool.get('mail.gateway')
89 msg_body = mailgate_obj.msg_body_get(msg)
91 'name': msg['Subject'],
92 'email_from': msg['From'],
93 'email_cc': msg['Cc'],
95 'description': msg_body['body'],
96 'history_line': [(0, 0, {'description': msg_body['body'], 'email': msg['From'] })],
98 res = mailgate_obj.partner_get(cr, uid, msg['From'])
101 res = self.create(cr, uid, data)