[IMP]: add the onchange_categ_id to all crm cases
[odoo/odoo.git] / addons / crm_job / crm_job.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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_job_categ(osv.osv):
50     _name = "crm.job.categ"
51     _description = "Job 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_job_categ()
61
62 class crm_job(osv.osv):
63     _name = "crm.job"
64     _description = "Job Cases"
65     _order = "id desc"
66     _inherit ='crm.case'    
67     _columns = {        
68             'date_closed': fields.datetime('Closed', readonly=True),
69             'priority': fields.selection(AVAILABLE_PRIORITIES, 'Priority'),            
70             'categ_id': fields.many2one('crm.job.categ', 'Category', domain="[('section_id','=',section_id)]"),
71             'planned_revenue': fields.float('Planned Revenue'),
72             'planned_cost': fields.float('Planned Costs'),
73             'probability': fields.float('Probability (%)'),     
74             'partner_name': fields.char("Employee's Name", size=64),
75             'partner_name2': fields.char('Employee Email', size=64),
76             'partner_phone': fields.char('Phone', size=32),
77             'partner_mobile': fields.char('Mobile', size=32), 
78             'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('section_id','=',section_id)]"),
79             'category2_id': fields.many2one('crm.case.category2', 'Category Name', domain="[('section_id','=',section_id)]"),
80             'duration': fields.float('Duration'),
81             'case_id': fields.many2one('crm.case', 'Related Case'),
82             'ref' : fields.reference('Reference', selection=_links_get, size=128),
83             'ref2' : fields.reference('Reference 2', selection=_links_get, size=128),
84             'canal_id': fields.many2one('res.partner.canal', 'Channel',help="The channels represent the different communication modes available with the customer." \
85                                                                         " With each commercial opportunity, you can indicate the canall which is this opportunity source."),
86             'som': fields.many2one('res.partner.som', 'State of Mind', help="The minds states allow to define a value scale which represents" \
87                                                                        "the partner mentality in relation to our services.The scale has" \
88                                                                        "to be created with a factor for each level from 0 (Very dissatisfied) to 10 (Extremely satisfied)."),
89
90             
91     }
92     def onchange_categ_id(self, cr, uid, ids, categ, context={}):
93         if not categ:
94             return {'value':{}}
95         cat = self.pool.get('crm.categ.categ').browse(cr, uid, categ, context).probability
96         return {'value':{'probability':cat}}
97    
98 crm_job()