1 # -*- coding: utf-8 -*-
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 osv import osv,fields
24 class sale_order(osv.osv):
25 _inherit = 'sale.order'
27 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
29 def action_cancel(self, cr, uid, ids, context=None):
30 res = super(sale_order, self).action_cancel(cr, uid, ids, context=context)
31 case_pool = self.pool.get('crm.lead')
32 data_pool = self.pool.get('ir.model.data')
33 data = data_pool._get_id(cr, uid, 'crm', 'stage_lead6')
34 res_data = data_pool.read(cr, uid, data, ['res_id'])
36 if res_data and res_data.get('res_id'):
37 lost_stage_id = res_data.get('res_id', False)
40 # After sale cancel, lead also lost
42 lead_ids = case_pool.search(cr, uid, [('ref','=','sale.order,%s'%(sale_id))])
43 case_pool.write(cr, uid, lead_ids, {'stage_id': lost_stage_id})
45 def action_ship_create(self, cr, uid, ids, *args):
46 res = super(sale_order, self).action_ship_create(cr, uid, ids, *args)
47 case_pool = self.pool.get('crm.lead')
48 data_pool = self.pool.get('ir.model.data')
49 data = data_pool._get_id(cr, uid, 'crm', 'stage_lead5')
50 res_data = data_pool.read(cr, uid, data, ['res_id'])
52 if res_data and res_data.get('res_id'):
53 win_stage_id = res_data.get('res_id', False)
56 # After sale confimed, lead also win
58 lead_ids = case_pool.search(cr, uid, [('ref','=','sale.order,%s'%(sale_id))])
59 case_pool.write(cr, uid, lead_ids, {'stage_id': win_stage_id})
61 def _get_section(self, cr, uid, context=None):
62 return context.get('context_section_id', False)
65 'section_id': _get_section
70 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: