Launchpad automatic translations update.
[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         'categ_ids': fields.many2many('crm.case.categ', 'sale_order_category_rel', 'order_id', 'category_id', 'Categories', \
29             domain="['|',('section_id','=',section_id),('section_id','=',False), ('object_id.model', '=', 'crm.lead')]")
30     }
31
32     def create(self, cr, uid, vals, context=None):
33         order =  super(sale_order, self).create(cr, uid, vals, context=context)
34         section_id = self.browse(cr, uid, order, context=context).section_id
35         if section_id:
36             followers = [follow.id for follow in section_id.message_follower_ids]
37             self.message_subscribe(cr, uid, [order], followers, context=context)
38         return order
39
40     def write(self, cr, uid, ids, vals, context=None):
41         if vals.get('section_id'):
42             section_id = self.pool.get('crm.case.section').browse(cr, uid, vals.get('section_id'), context=context)
43             if section_id:
44                 vals['message_follower_ids'] = [(4, follower.id) for follower in section_id.message_follower_ids]
45         return super(sale_order, self).write(cr, uid, ids, vals, context=context)
46
47 sale_order()
48
49 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: