[FIX] auction: auction_transfer_unsold_object issues has been fixed
[odoo/odoo.git] / addons / auction / wizard / auction_lots_sms_send.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 from tools.translate import _
24 import netsvc
25 import pooler
26 import time
27 import tools
28 import wizard
29
30 class auction_lots_sms_send(osv.osv_memory):
31
32     _name = "auction.lots.sms.send"
33     _description = "Sms send "
34     _columns= {
35                'app_id':fields.char('API ID', size=64, required=True), 
36                'user':fields.char('Login', size=64, required=True),
37                'password':fields.char('Password', size=64, required=True),
38                'text':fields.text('SMS Message', required=True)
39                }
40     
41     def sms_send(self, cr, uid, ids, context):
42         """
43             to send sms
44             
45             @param cr: the current row, from the database cursor.
46             @param uid: the current user’s ID for security checks.
47             @param ids: the ID or list of IDs
48             @param context: A standard dictionary 
49             @return: number indicating the acknowledgement
50         """
51                 
52         lot_obj = self.pool.get('auction.lots')
53         partner_obj = self.pool.get('res.partner')
54         partner_address_obj = self.pool.get('res.partner.address')
55         for datas in self.read(cr, uid, ids):
56             lots = lot_obj.read(cr, uid, context['active_ids'], ['obj_num','obj_price','ach_uid'])
57             res = partner_obj.read(cr, uid, [l['ach_uid'][0] for l in lots if l['ach_uid']], ['gsm'], context)
58             
59             nbr = 0
60             for r in res:
61                 add = partner_obj.address_get(cr, uid, [r['id']])['default']
62                 addr = partner_address_obj.browse(cr, uid, add)
63                 to = addr.mobile
64                 if to:
65                     tools.smssend(data['user'], data['password'], data['app_id'], unicode(data['text'], 'utf-8').encode('latin1'), to)
66                     nbr += 1
67             return {'sms_sent': nbr}
68         
69             if to:
70                 tools.smssend(data['user'], data['password'], data['app_id'], unicode(data['text'], 'utf-8').encode('latin1'), to)
71                 nbr += 1
72             return {'sms_sent': nbr}
73 #      
74 auction_lots_sms_send()
75
76
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
78