1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
29
from osv import fields,osv
34
from tools.misc import UpdateableStr, UpdateableDict
37
class Invoice(osv.osv):
38
_inherit = "account.invoice"
40
def send_mail(self, db_name, uid, ids):
41
db, pool = pooler.get_db_and_pool(db_name)
47
smtp = self.pool.get('email.smtpclient')
49
address = self.read(cr, uid, ids ,['address_invoice_id', 'number', 'name'],context=None)[0]
50
email = smtp.selectAddress(cr, uid, partner=None, contact=[address['address_invoice_id'][0]])
51
smtpserver_id = self.pool.get('email.smtpclient').select(cr, uid, 'account')
54
if smtpserver_id is False:
55
raise Exception, 'Please check the Server Configuration !!!'
57
smtpserver = self.pool.get('email.smtpclient').browse(cr, uid, smtpserver_id, context=False)
60
name = self.pool.get('res.partner.address').read(cr, uid, [address['address_invoice_id'][0]], ['name'])[0]['name'] or 'Customer'
61
user = self.pool.get('res.users').read(cr, uid, [uid], ['name'])[0]['name'] or 'Tiny ERP'
62
body = body.replace('__name__', name)
63
body = body.replace('__user__', user)
64
body = body.replace('__number__', str(address['number']))
66
state = smtpserver.send_email(
71
"Invoice : " + str(address['number']),
78
inv_data = self.read(cr, uid, ids ,['partner_id', 'amount_total'],context=None)
79
partner_ids = inv_data[0]['partner_id']
80
total = inv_data[0]['amount_total']
82
event_obj = self.pool.get('res.partner.event')
83
event_obj.create(cr, uid, {'name': 'Invoice: '+ str(address['number']),\
84
'partner_id': partner_ids[0],\
85
'date': time.strftime('%Y-%m-%d %H:%M:%S'),\
87
'partner_type': 'customer',
89
'planned_revenue': total,
91
'document' : 'account.invoice,'+str(ids[0])})
95
raise Exception, 'Verification Failed, Please check the Server Configuration!!!'
97
model_id=self.pool.get('ir.model').search(cr, uid, [('model','=','account.invoice')], context=False)[0]
99
history = self.pool.get('email.smtpclient.history')
104
'date_create':time.strftime('%Y-%m-%d %H:%M:%S'),
105
'server_id' : smtpserver_id,
106
'name':'The Email is not sent because the Partner have no Email',
114
def action_number(self, cr, uid, ids):
115
super(Invoice, self).action_number(cr, uid, ids)
117
thread1 = threading.Thread( target=self.send_mail , args=(cr.dbname, uid, ids))
b'\\ No newline at end of file'