[IMP] account_voucher: search view ordering of extended option and group by
[odoo/odoo.git] / addons / sale_crm / sale_crm.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 from osv import osv,fields
23
24 class sale_order(osv.osv):
25     _inherit = 'sale.order'
26     _columns = {
27         'section_id': fields.many2one('crm.case.section', 'Sales Team'),
28     }
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'])
35         lost_stage_id = False
36         if res_data and res_data.get('res_id'):
37             lost_stage_id = res_data.get('res_id', False)
38         if not lost_stage_id:
39             return res
40         # After sale cancel, lead also lost
41         for sale_id in ids:
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})
44         return res
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'])
51         win_stage_id = False
52         if res_data and res_data.get('res_id'):
53             win_stage_id = res_data.get('res_id', False)
54         if not win_stage_id:
55             return res
56         # After sale confimed, lead also win
57         for sale_id in ids:
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})
60         return res
61     def _get_section(self, cr, uid, context=None):
62        return context.get('context_section_id', False)
63
64     _defaults = {
65           'section_id': _get_section
66     }
67
68 sale_order()
69
70 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: