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 datetime import datetime
23 from osv import fields,osv,orm
24 from tools.translate import _
33 ('done', 'Converted'),
37 class crm_opportunity(osv.osv):
38 """ Opportunity Cases """
41 _description = "Opportunity Cases"
42 _order = "priority,date_action,id desc"
47 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
48 domain="[('partner_id','=',partner_id)]"),
51 'probability': fields.float('Probability (%)'),
52 'planned_revenue': fields.float('Expected Revenue'),
53 'ref': fields.reference('Reference', selection=crm._links_get, size=128),
54 'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
55 'phone': fields.char("Phone", size=64),
56 'date_deadline': fields.date('Expected Closing'),
57 'date_action': fields.date('Next Action'),
60 def case_close(self, cr, uid, ids, *args):
61 """Overrides close for crm_case for setting probability and close date
62 @param self: The object pointer
63 @param cr: the current row, from the database cursor,
64 @param uid: the current user’s ID for security checks,
65 @param ids: List of case Ids
66 @param *args: Tuple Value for additional Params
68 res = super(crm_opportunity, self).case_close(cr, uid, ids, args)
69 self.write(cr, uid, ids, {'probability' : 100.0, 'date_close': time.strftime('%Y-%m-%d %H:%M:%S')})
72 def case_cancel(self, cr, uid, ids, *args):
73 """Overrides cancel for crm_case for setting probability
74 @param self: The object pointer
75 @param cr: the current row, from the database cursor,
76 @param uid: the current user’s ID for security checks,
77 @param ids: List of case Ids
78 @param *args: Tuple Value for additional Params
80 res = super(crm_opportunity, self).case_cancel(cr, uid, ids, args)
81 self.write(cr, uid, ids, {'probability' : 0.0})
84 def case_open(self, cr, uid, ids, *args):
85 """Overrides cancel for crm_case for setting Open Date
86 @param self: The object pointer
87 @param cr: the current row, from the database cursor,
88 @param uid: the current user’s ID for security checks,
89 @param ids: List of case's Ids
90 @param *args: Give Tuple Value
92 res = super(crm_opportunity, self).case_open(cr, uid, ids, *args)
93 self.write(cr, uid, ids, {'date_open': time.strftime('%Y-%m-%d %H:%M:%S')})
96 def onchange_stage_id(self, cr, uid, ids, stage_id, context={}):
98 """ @param self: The object pointer
99 @param cr: the current row, from the database cursor,
100 @param uid: the current user’s ID for security checks,
101 @param ids: List of stage’s IDs
102 @stage_id: change state id on run time """
107 stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
108 if not stage.on_change:
110 return {'value':{'probability': stage.probability}}
113 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c),
114 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
117 def action_makeMeeting(self, cr, uid, ids, context=None):
119 This opens Meeting's calendar view to schedule meeting on current Opportunity
120 @param self: The object pointer
121 @param cr: the current row, from the database cursor,
122 @param uid: the current user’s ID for security checks,
123 @param ids: List of Opportunity to Meeting IDs
124 @param context: A standard dictionary for contextual values
126 @return : Dictionary value for created Meeting view
129 for opp in self.browse(cr, uid, ids):
130 data_obj = self.pool.get('ir.model.data')
133 result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
134 res = data_obj.read(cr, uid, result, ['res_id'])
135 id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
136 id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
137 id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
139 id1 = data_obj.browse(cr, uid, id1, context=context).res_id
141 id2 = data_obj.browse(cr, uid, id2, context=context).res_id
143 id3 = data_obj.browse(cr, uid, id3, context=context).res_id
146 'default_opportunity_id': opp.id,
147 'default_partner_id': opp.partner_id and opp.partner_id.id or False,
148 'default_section_id': opp.section_id and opp.section_id.id or False,
149 'default_email_from': opp.email_from,
150 'default_state': 'open',
151 'default_name': opp.name
154 'name': _('Meetings'),
155 'domain': "[('user_id','=',%s),('opportunity_id','=',%s)]" % (uid,opp.id),
158 'view_mode': 'calendar,form,tree',
159 'res_model': 'crm.meeting',
161 'views': [(id1, 'calendar'), (id2, 'form'), (id3, 'tree')],
162 'type': 'ir.actions.act_window',
163 'search_view_id': res['res_id'],
170 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: