[REVIEW+MERGE] merged rha work

bzr revid: hmo@tinyerp.com-20110404060333-06w4xpwnrod1d3ni
This commit is contained in:
Harry (OpenERP)
2011-04-04 11:33:33 +05:30
5 changed files with 39 additions and 37 deletions
+2 -2
View File
@@ -308,8 +308,8 @@ class crm_case(object):
return {'value': {'phone': address.phone}}
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None):
mailgate_pool = self.pool.get('email.thread')
return mailgate_pool.history(cr, uid, cases, keyword, history=history,\
thread_pool = self.pool.get('email.thread')
return thread_pool.history(cr, uid, cases, keyword, history=history,\
subject=subject, email=email, \
details=details, email_from=email_from,\
message_id=message_id, attach=attach, \
+2 -2
View File
@@ -28,13 +28,13 @@
"access_res_partner_address_manager","res.partner.address.crm.user.manager","base.model_res_partner_address","base.group_sale_manager",1,0,0,0
"access_res_partner_category_manager","res.partner.category.crm.manager","base.model_res_partner_category","base.group_sale_manager",1,0,0,0
"email_email_message_manager","email.email.message.manager","email.model_email_message","base.group_sale_manager",1,0,0,0
"email_thread_manager","email.mailgate.thread.manager","email.model_email_thread","base.group_sale_manager",1,1,1,1
"email_thread_manager","email.thread.manager","email.model_email_thread","base.group_sale_manager",1,1,1,1
"access_calendar_attendee_crm_user","calendar.attendee.crm.user","model_calendar_attendee","base.group_sale_salesman",1,1,1,0
"access_calendar_attendee_crm_manager","calendar.attendee.crm.manager","model_calendar_attendee","base.group_sale_manager",1,1,1,1
"access_res_partner","res.partner.crm.user","base.model_res_partner","base.group_sale_salesman",1,1,1,0
"access_res_partner_address","res.partner.address.crm.user","base.model_res_partner_address","base.group_sale_salesman",1,1,1,0
"access_res_partner_category","res.partner.category.crm.user","base.model_res_partner_category","base.group_sale_salesman",1,1,1,0
"email_mailgate_thread","email.mailgate.thread","email.model_email_thread","base.group_sale_salesman",1,1,1,1
"email_mailgate_thread","email.thread","email.model_email_thread","base.group_sale_salesman",1,1,1,1
"email_gateway_email_message_user","email.email.message.user","email.model_email_message","base.group_sale_salesman",1,1,1,1
"access_crm_case_categ_manager","crm.case.categ manager","model_crm_case_categ","base.group_sale_manager",1,1,1,1
"access_base_action_rule_manager","base.action.rule manager","model_base_action_rule","base.group_sale_manager",1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
28 access_res_partner_address_manager res.partner.address.crm.user.manager base.model_res_partner_address base.group_sale_manager 1 0 0 0
29 access_res_partner_category_manager res.partner.category.crm.manager base.model_res_partner_category base.group_sale_manager 1 0 0 0
30 email_email_message_manager email.email.message.manager email.model_email_message base.group_sale_manager 1 0 0 0
31 email_thread_manager email.mailgate.thread.manager email.thread.manager email.model_email_thread base.group_sale_manager 1 1 1 1
32 access_calendar_attendee_crm_user calendar.attendee.crm.user model_calendar_attendee base.group_sale_salesman 1 1 1 0
33 access_calendar_attendee_crm_manager calendar.attendee.crm.manager model_calendar_attendee base.group_sale_manager 1 1 1 1
34 access_res_partner res.partner.crm.user base.model_res_partner base.group_sale_salesman 1 1 1 0
35 access_res_partner_address res.partner.address.crm.user base.model_res_partner_address base.group_sale_salesman 1 1 1 0
36 access_res_partner_category res.partner.category.crm.user base.model_res_partner_category base.group_sale_salesman 1 1 1 0
37 email_mailgate_thread email.mailgate.thread email.thread email.model_email_thread base.group_sale_salesman 1 1 1 1
38 email_gateway_email_message_user email.email.message.user email.model_email_message base.group_sale_salesman 1 1 1 1
39 access_crm_case_categ_manager crm.case.categ manager model_crm_case_categ base.group_sale_manager 1 1 1 1
40 access_base_action_rule_manager base.action.rule manager model_base_action_rule base.group_sale_manager 1 1 1 1
+32 -30
View File
@@ -85,7 +85,7 @@ class email_message_common(osv.osv_memory):
'body_html': fields.text('HTML', help="Contains HTML version of email"),
'smtp_server_id':fields.many2one('ir.mail_server', 'SMTP Server'),
}
_rec_name='subject'
_rec_name = 'subject'
_sql_constraints = []
email_message_common()
@@ -210,7 +210,7 @@ class email_message(osv.osv):
msg_vals = {
'subject': subject,
'model': model or '',
'date': time.strftime('%Y-%m-%d'),
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'user_id': uid,
'body': body,
'email_from': email_from,
@@ -243,6 +243,8 @@ class email_message(osv.osv):
'res_model':'email.message',
'res_id': email_msg_id,
}
if context.has_key('default_type'):
del context['default_type']
attachment_ids.append(attachment_obj.create(cr, uid, attachment_data, context))
self.write(cr, uid, email_msg_id,
{ 'attachment_ids': [[6, 0, attachment_ids]] }, context)
@@ -256,33 +258,29 @@ class email_message(osv.osv):
ids = []
if context is None:
context = {}
attachment_obj = self.pool.get('ir.attachment')
smtp_server_obj = self.pool.get('ir.mail_server')
if not ids:
filters = [('state', '=', 'outgoing')]
if 'filters' in context:
filters.extend(context['filters'])
ids = self.search(cr, uid, filters, context=context)
self.write(cr, uid, ids, {'state':'outgoing'}, context)
for message in self.browse(cr, uid, ids, context):
try:
res = self.send_email(cr, uid, ids, auto_commit=True, context=context)
if res:
self.write(cr, uid, [message.id], {'state':'sent', 'message_id': res}, context)
else:
self.write(cr, uid, [message.id], {'state':'exception'}, context)
except Exception, error:
logger = netsvc.Logger()
logger.notifyChannel("email-template", netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (message.id, error))
self.write(cr, uid, [message.id], {'state':'exception'}, context)
return ids
try:
res = self.send_email(cr, uid, ids, auto_commit=True, context=context)
except Exception, error:
logger = netsvc.Logger()
msg = _("Sending of Mail failed. Error: %s") % (error)
logger.notifyChannel("email", netsvc.LOG_ERROR, msg)
return False
return res
def send_email(self, cr, uid, ids, auto_commit=False, context=None):
"""
send email message
"""
if context is None:
context = {}
attachment = []
smtp_server_obj = self.pool.get('ir.mail_server')
attachment_pool = self.pool.get('ir.attachment')
self.write(cr, uid, ids, {'state':'outgoing'}, context)
for message in self.browse(cr, uid, ids, context):
try:
smtp_server = message.smtp_server_id
@@ -292,9 +290,10 @@ class email_message(osv.osv):
smtp_server = smtp_server_obj.browse(cr, uid, smtp_ids, context)[0]
attachments = []
for attach in message.attachment_ids:
attachments.append((attach.datas_fname ,base64.b64decode(attach.datas)))
attachments.append((attach.datas_fname, base64.b64decode(attach.datas)))
if message.state in ['outgoing', 'exception']:
msg = smtp_server_obj.pack_message(cr, uid, message.subject, message.body,
msg = smtp_server_obj.pack_message(cr, uid, message.email_from,
message.email_to and message.email_to.split(',') or [], message.subject, message.body,
email_cc=message.email_cc and message.email_cc.split(',') or [],
email_bcc=message.email_bcc and message.email_bcc.split(',') or [],
reply_to=message.reply_to,
@@ -303,26 +302,29 @@ class email_message(osv.osv):
subtype=message.sub_type,
x_headers=message.headers and eval(message.headers) or {},
priority=message.priority)
res = smtp_server_obj.send_email(cr, uid, message.email_from,
message.email_to and message.email_to.split(',') or [],
res = smtp_server_obj.send_email(cr, uid,
msg,
mail_server_id = message.smtp_server_id.id or None,
smtp_server=smtp_server and smtp_server.smtp_host or None,
smtp_port=smtp_server and smtp_server.smtp_port or None,
smtp_user=smtp_server and smtp_server.smtp_user or None,
smtp_password=smtp_server and smtp_server.smtp_pass or None,
smtp_password=smtp_server and smtp_server.smtp_pass or None,
ssl=smtp_server and smtp_server.smtp_ssl or False,
tsl=smtp_server and smtp_server.smtp_tsl,
tls=smtp_server and smtp_server.smtp_tls,
debug=message.debug)
if res:
self.write(cr, uid, [message.id], {'state':'sent', 'message_id': res}, context)
else:
self.write(cr, uid, [message.id], {'state':'exception'}, context)
else:
raise osv.except_osv(_('Error !'), _('No messages in outgoing or exception state!'))
sent_emails = self.search(cr, uid, [('state','=','sent'), ('auto_delete','=',True)], context=context)
if sent_emails:
for sent in self.browse(cr, uid, sent_emails, context):
if sent.attachment_ids:
attachment_pool.unlink(cr, uid, [attachment.id for attachment in sent.attachment_ids], context=context)
self.unlink(cr, uid, sent.id, context=context)
#if auto_delete=True then delete that sent messages as well as attachments
message_data = self.read(cr, uid, message.id, ['state', 'auto_delete', 'attachment_ids'])
if message_data['state'] == 'sent' and message_data['auto_delete'] == True:
self.unlink(cr, uid, [message.id], context=context)
if message_data['attachment_ids']:
attachment_pool.unlink(cr, uid, message_data['attachment_ids'], context=context)
if auto_commit == True:
cr.commit()
+1 -1
View File
@@ -1,3 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_email_message","email.message","model_email_message",,1,0,0,0
"access_mailgate_thread","mailgate.thread","model_email_thread",,1,0,0,0
"access_mailgate_thread","email.thread","model_email_thread",,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_email_message email.message model_email_message 1 0 0 0
3 access_mailgate_thread mailgate.thread email.thread model_email_thread 1 0 0 0
+2 -2
View File
@@ -107,8 +107,8 @@ class project_tasks(osv.osv):
return res
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None):
mailgate_pool = self.pool.get('email.thread')
return mailgate_pool.history(cr, uid, cases, keyword, history=history,\
thread_pool = self.pool.get('email.thread')
return thread_pool.history(cr, uid, cases, keyword, history=history,\
subject=subject, email=email, \
details=details, email_from=email_from,\
message_id=message_id, attach=attach, \