[IMP]: add the onchange_categ_id to all crm cases
[odoo/odoo.git] / addons / crm / 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 import time
23 import re
24 import os
25
26 import mx.DateTime
27 import base64
28
29 from tools.translate import _
30
31 import tools
32 from osv import fields,osv,orm
33 from osv.orm import except_orm
34
35 AVAILABLE_PRIORITIES = [
36     ('5','Lowest'),
37     ('4','Low'),
38     ('3','Normal'),
39     ('2','High'),
40     ('1','Highest')
41 ]
42
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]
48
49 class crm_fundraising_categ(osv.osv):
50     _name = "crm.fundraising.categ"
51     _description = "Fundraising Categories"
52     _columns = {
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'),
56     }
57     _defaults = {
58         'probability': lambda *args: 0.0
59     }
60 crm_fundraising_categ()
61
62 class crm_fundraising_type(osv.osv):
63     _name = "crm.fundraising.type"
64     _description = "Fundraising Type"
65     _rec_name = "name"
66     _columns = {
67         'name': fields.char('Fundraising Type Name', size=64, required=True, translate=True),
68         'section_id': fields.many2one('crm.case.section', 'Case Section'),
69     }
70
71 crm_fundraising_type()
72
73 class crm_fundraising_stage(osv.osv):
74     _name = "crm.fundraising.stage"
75     _description = "Stage of fundraising case"
76     _rec_name = 'name'
77     _order = "sequence"
78     _columns = {
79         'name': fields.char('Stage Name', size=64, required=True, translate=True),
80         'section_id': fields.many2one('crm.case.section', 'Case Section'),
81         'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of case stages."),
82     }
83     _defaults = {
84         'sequence': lambda *args: 1
85     }
86 crm_fundraising_stage()
87
88
89 class crm_fundraising(osv.osv):
90     _name = "crm.fundraising"
91     _description = "Fund Raising Cases"
92     _order = "id desc"
93     _inherit ='crm.case'
94     _columns = {        
95             'date_closed': fields.datetime('Closed', readonly=True),
96             'priority': fields.selection(AVAILABLE_PRIORITIES, 'Priority'),            
97             'categ_id': fields.many2one('crm.fundraising.categ','Category', domain="[('section_id','=',section_id)]"),
98             'planned_revenue': fields.float('Planned Revenue'),
99             'planned_cost': fields.float('Planned Costs'),
100             'probability': fields.float('Probability (%)'),     
101             'partner_name': fields.char("Employee's Name", size=64),
102             'partner_name2': fields.char('Employee Email', size=64),
103             'partner_phone': fields.char('Phone', size=32),
104             'partner_mobile': fields.char('Mobile', size=32), 
105             'stage_id': fields.many2one ('crm.fundraising.stage', 'Stage', domain="[('section_id','=',section_id)]"),
106             'type_id': fields.many2one('crm.fundraising.type', 'Fundraising Type', domain="[('section_id','=',section_id)]"),
107             'duration': fields.float('Duration'),
108             'ref' : fields.reference('Reference', selection=_links_get, size=128),
109             'ref2' : fields.reference('Reference 2', selection=_links_get, size=128),
110             'canal_id': fields.many2one('res.partner.canal', 'Channel',help="The channels represent the different communication modes available with the customer." \
111                                                                         " With each commercial opportunity, you can indicate the canall which is this opportunity source."),
112             'som': fields.many2one('res.partner.som', 'State of Mind', help="The minds states allow to define a value scale which represents" \
113                                                                        "the partner mentality in relation to our services.The scale has" \
114                                                                        "to be created with a factor for each level from 0 (Very dissatisfied) to 10 (Extremely satisfied)."),
115         }
116    
117     _defaults = {
118                  'priority': lambda *a: AVAILABLE_PRIORITIES[2][0],
119     }
120     def onchange_categ_id(self, cr, uid, ids, categ, context={}):
121         if not categ:
122             return {'value':{}}
123         cat = self.pool.get('crm.fundraising.categ').browse(cr, uid, categ, context).probability
124         return {'value':{'probability':cat}}    
125     
126
127 crm_fundraising()