Launchpad automatic translations update.
[odoo/odoo.git] / addons / portal_sale / sale.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 fields, osv
23
24 class sale_order(osv.osv):
25     _inherit = 'sale.order'
26
27     def action_button_confirm(self, cr, uid, ids, context=None):
28         # fetch the partner's id and subscribe the partner to the sale order
29         partner = self.browse(cr, uid, ids[0], context=context)['partner_id']
30         if partner.id not in self.browse(cr, uid, ids[0], context=context)['message_follower_ids']:
31             self.message_subscribe(cr, uid, ids, [partner.id], context=context)
32             document = self.browse(cr, uid, ids[0], context=context)
33             mail_values = {
34                 'email_from': self.pool.get('res.users').browse(cr, uid, uid, context=context)['partner_id']['email'],
35                 'email_to': partner.email,
36                 'subject': 'Invitation to follow %s' % document.name_get()[0][1],
37                 'body_html': 'You have been invited to follow %s' % document.name_get()[0][1],
38                 'auto_delete': True,
39             }
40             mail_obj = self.pool.get('mail.mail')
41             mail_id = mail_obj.create(cr, uid, mail_values, context=context)
42             mail_obj.send(cr, uid, [mail_id], recipient_ids=[partner.id], context=context)
43         return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
44
45 sale_order()
46
47 class mail_mail(osv.osv):
48     _inherit = 'mail.mail'
49
50     def _postprocess_sent_message(self, cr, uid, mail, context=None):
51         if mail.model == 'sale.order':
52             so_obj = self.pool.get('sale.order')
53             partner = so_obj.browse(cr, uid, mail.res_id, context=context)['partner_id']
54             if partner.id not in so_obj.browse(cr, uid, mail.res_id, context=context)['message_follower_ids']:
55                 so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
56         return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context)
57
58 mail_mail()