4
# (c) 2008 Sednacom <http://www.sednacom.fr>
7
# - Brice V. < brice@sednacom.fr >
9
from osv import osv, fields
14
def _default_from(*args):
19
return obj.pool.get('res.users').read(cr, user, [user, ], ['zarafa_email', ])[0]['zarafa_email']
21
def _default_name(*args):
23
name = context.get('case_name', '')
26
def _default_recipients(*args):
28
recipients = context.get('case_recipients', False)
33
_name = 'sednacom.email'
35
def _make_to(self, cr, uid, eids, name, arg, context={}):
37
for data in self.browse(cr, uid, eids, context):
38
res[data.id] = ', '.join([ contact.email for contact in data.recipients if contact.email])
42
'name' : fields.char('Title', size=64, required=True, readonly=True,
43
states={'draft' : [('readonly', False),]}) ,
44
'body' : fields.text('Message', readonly=True,
45
states={'draft' : [('readonly', False),]}) ,
46
'to' : fields.function(_make_to, method=True, string='To', type='char', size=256) ,
47
'recipients' : fields.many2many('res.partner.address', 'sednacom_email_recipients', 'email', 'contact', 'Contacts',
48
readonly=True, states={'draft' : [('readonly', False),]}) ,
49
'exp' : fields.char('From', size=128, required=True, readonly=True,
50
states={'draft' : [('readonly', False),]}) ,
51
'datetime' : fields.datetime('Date', readonly=True,
52
states={'draft' : [('readonly', False),]}) ,
53
'state' : fields.selection(
56
('received','Received'), ] ,
57
'State', readonly=True,) ,
58
'crm_case' : fields.many2one('crm.case', 'Case',
59
readonly=True, states={'draft' : [('readonly', False),]}) ,
63
'datetime' : lambda *args: time.strftime('%Y-%m-%d %H:%M:%S') ,
64
'exp' : _default_from ,
65
'state' : lambda *args: 'draft' ,
66
'name' : _default_name ,
67
'recipients' : _default_recipients ,
70
_order = "datetime desc"
72
def add_crm_log(self, cr, uid, eids, context={}):
73
o_cch = self.pool.get('crm.case.history')
75
data = self.read(cr, uid, eids, ['id', 'crm_case', 'body', 'exp', ])
77
canal = context.get('canal_id', False)
78
name = context.get('history_name', 'Email')
82
case_id = row['crm_case'][0]
87
'description' : row['body'] ,
88
'email' : row['exp'] ,
90
res = o_cch.create(cr, uid, vals)
96
def send(self, cr, uid, eids, context={}):
99
datas = self.browse(cr, uid , eids, context)
101
o_ia = self.pool.get('ir.attachment')
102
b64d = base64.decodestring
105
ia_ids = o_ia.search(cr, uid,
106
[('res_model','=','sednacom.email'),('res_id','=',data.id),] )
109
ia_raw_data = o_ia.read(cr, uid, ia_ids, ['datas_fname', 'datas',])
110
ia_data = [ ( d['datas_fname'], b64d(d['datas']) ) \
111
for d in ia_raw_data ]
113
htmlmail.email_html_send_attach(
115
[a.strip() for a in str(data.to).split(',')] ,
126
self.write(cr, uid, eids, {'state' : 'sent'})
127
self.add_crm_log(cr, uid, eids, context)
130
def zarafa_send(self, cr, uid, eids, context={}):
133
datas = self.browse(cr, uid , eids, context)
135
o_ia = self.pool.get('ir.attachment')
136
b64d = base64.decodestring
139
ia_ids = o_ia.search(cr, uid,
140
[('res_model','=','sednacom.email'),('res_id','=',data.id),] )
143
ia_raw_data = o_ia.read(cr, uid, ia_ids, ['datas_fname', 'datas',])
144
ia_data = [ ( d['datas_fname'], b64d(d['datas']) ) \
145
for d in ia_raw_data ]
146
htmlmail.zarafa_email_html_send_attach(
149
[a.strip() for a in str(data.to).split(',')] ,
160
self.write(cr, uid, eids, {'state' : 'sent'})
161
self.add_crm_log(cr, uid, eids, context)