[REF]: mail_gateway, crm: Refactoring of _history for detailed history maintenance
bzr revid: rpa@tinyerp.com-20100701104631-12v4ii33woqj50bq
This commit is contained in:
+9
-10
@@ -212,13 +212,10 @@ class crm_case(object):
|
||||
address = self.pool.get('res.partner.address').browse(cr, uid, add)
|
||||
return {'value': {'email_from': address.email, '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={}):
|
||||
def _history(self, cr, uid, cases, keyword, history=False, emails=None, message=None, context=None):
|
||||
mailgate_pool = self.pool.get('mailgate.thread')
|
||||
return mailgate_pool._history(cr, uid, cases, keyword, history=history,\
|
||||
subject=subject, email=email, \
|
||||
details=details, email_from=email_from,\
|
||||
message_id=message_id, attach=attach, \
|
||||
context=context)
|
||||
emails=emails, message=message, context=context)
|
||||
|
||||
def case_open(self, cr, uid, ids, *args):
|
||||
"""Opens Case
|
||||
@@ -360,14 +357,13 @@ class crm_case(object):
|
||||
src = case.email_from
|
||||
dest = case.section_id.reply_to
|
||||
body = ""
|
||||
body = case.email_last or case.description
|
||||
body = case.description
|
||||
if not destination:
|
||||
src, dest = dest, src
|
||||
if body and case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature)
|
||||
|
||||
body = self.format_body(body)
|
||||
dest = [dest]
|
||||
|
||||
attach_to_send = None
|
||||
|
||||
@@ -377,16 +373,19 @@ class crm_case(object):
|
||||
attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send)
|
||||
|
||||
# Send an email
|
||||
subject = "Reminder: [%s] %s" % (str(case.id), case.name, )
|
||||
flag = tools.email_send(
|
||||
src,
|
||||
dest,
|
||||
"Reminder: [%s] %s" % (str(case.id), case.name, ),
|
||||
[dest],
|
||||
subject,
|
||||
body,
|
||||
reply_to=case.section_id.reply_to,
|
||||
openobject_id=str(case.id),
|
||||
attach=attach_to_send
|
||||
)
|
||||
self._history(cr, uid, [case], _('Send'), history=True, email=dest, details=body, email_from=src)
|
||||
emails = {'email_from': src, 'email_to': dest}
|
||||
message = {'subject': subject, 'description': body, 'attach': attach_to_send}
|
||||
self._history(cr, uid, [case], _('Send'), history=True, emails=emails, message=message)
|
||||
return True
|
||||
|
||||
def _check(self, cr, uid, ids=False, context={}):
|
||||
|
||||
@@ -204,19 +204,22 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
||||
if this.history == 'latest':
|
||||
msgs = msgs[:1]
|
||||
attachments.extend(itertools.chain(*[m.attachment_ids for m in msgs]))
|
||||
|
||||
attach = [(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas]
|
||||
|
||||
result = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
this.subject,
|
||||
body,
|
||||
openobject_id=str(case.id),
|
||||
attach=[(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas],
|
||||
attach=attach,
|
||||
reply_to=case.section_id.reply_to,
|
||||
)
|
||||
|
||||
if result:
|
||||
case_pool._history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, subject=this.subject, details=body, email_from=email_from)
|
||||
emails = {'email_from': email_from, 'email_to': this.email_to}
|
||||
message = {'subject': this.subject, 'description': body , 'attach': attach}
|
||||
case_pool._history(cr, uid, [case], _('Forward'), history=True, emails=emails, message=message)
|
||||
else:
|
||||
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ class crm_send_new_email(osv.osv_memory):
|
||||
]
|
||||
|
||||
message_id = None
|
||||
ref_id = None
|
||||
|
||||
case = case_pool.browse(cr, uid, res_id)
|
||||
if context.get('mail', 'new') == 'new':
|
||||
@@ -101,6 +102,7 @@ class crm_send_new_email(osv.osv_memory):
|
||||
model = hist.model
|
||||
model_pool = self.pool.get(model)
|
||||
res_id = hist.res_id
|
||||
ref_id = hist.ref_id
|
||||
case = model_pool.browse(cr, uid, res_id)
|
||||
emails = [obj.email_to]
|
||||
email_cc = (obj.email_cc or '').split(',')
|
||||
@@ -128,13 +130,11 @@ class crm_send_new_email(osv.osv_memory):
|
||||
if not flag:
|
||||
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
|
||||
if flag:
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, \
|
||||
email=obj.email_to, details=body, \
|
||||
subject=obj.subject, email_from=email_from, \
|
||||
message_id=message_id, attach=attach)
|
||||
email_dict = {'email_from': email_from, 'email_to': obj.email_to, 'email_cc': email_cc}
|
||||
message = {'subject': obj.subject, 'description': body, 'message_id': message_id, 'ref_id': ref_id , 'attach': attach}
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, emails=email_dict, message=message)
|
||||
if obj.state == 'unchanged':
|
||||
pass
|
||||
elif obj.state == 'done':
|
||||
case_pool.case_close(cr, uid, [case.id])
|
||||
elif obj.state == 'draft':
|
||||
case_pool.case_reset(cr, uid, [case.id])
|
||||
|
||||
@@ -68,8 +68,7 @@ class mailgate_thread(osv.osv):
|
||||
def msg_send(self, cr, uid, id, *args, **argv):
|
||||
raise Exception, _('Method is not implemented')
|
||||
|
||||
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, \
|
||||
email_from=False, message_id=False, references=None, attach=None, context=None):
|
||||
def _history(self, cr, uid, cases, keyword, history=False, emails=None, message=None, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@@ -77,17 +76,18 @@ class mailgate_thread(osv.osv):
|
||||
@param cases: a browse record list
|
||||
@param keyword: Case action keyword e.g.: If case is closed "Close" keyword is used
|
||||
@param history: Value True/False, If True it makes entry in case History otherwise in Case Log
|
||||
@param email: Email address if any
|
||||
@param details: Details of case history if any
|
||||
@param atach: Attachment sent in email
|
||||
@param emails: Email details, e.g. emails = {'email_from': 'FROM', 'email_to': 'TO', 'email_cc': 'CC', 'email_bcc': 'BCC'}
|
||||
@param message: Details of email to send, e.g. message = {'subject': 'SUBJECT', 'description': 'DESCRIPTION', 'message_id':'MESSAGE_ID', 'ref_id': 'REFERENCES' , 'attach': 'ATTACH'}
|
||||
@param context: A standard dictionary for contextual values"""
|
||||
if context is None:
|
||||
context = {}
|
||||
if attach is None:
|
||||
attach = []
|
||||
|
||||
if message is None:
|
||||
message = {}
|
||||
if emails is None:
|
||||
emails = {}
|
||||
if message.get('attach') is None:
|
||||
message.update({'attach': []})
|
||||
# The mailgate sends the ids of the cases and not the object list
|
||||
|
||||
if all(isinstance(case_id, (int, long)) for case_id in cases):
|
||||
cases = self.browse(cr, uid, cases, context=context)
|
||||
|
||||
@@ -101,34 +101,40 @@ class mailgate_thread(osv.osv):
|
||||
'model' : case._name,
|
||||
'res_id': case.id,
|
||||
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'message_id': message_id,
|
||||
'message_id': message.get('message_id', False),
|
||||
}
|
||||
attachments = []
|
||||
if history:
|
||||
for att in attach:
|
||||
for att in message.get('attach'):
|
||||
attachments.append(att_obj.create(cr, uid, {'name': att[0], 'datas': base64.encodestring(att[1])}))
|
||||
|
||||
data = {
|
||||
'name': subject or 'History',
|
||||
'name': message.get('subject', 'History'),
|
||||
'history': True,
|
||||
'user_id': uid,
|
||||
'model' : case._name,
|
||||
'res_id': case.id,
|
||||
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'description': details or (hasattr(case, 'description') and case.description or False),
|
||||
'email_to': email or \
|
||||
'description': message.get('description') or (hasattr(case, 'description') and case.description or False),
|
||||
'email_to': emails.get('email_to') or \
|
||||
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
|
||||
case.user_id.address_id.email) or tools.config.get('email_from', False),
|
||||
'email_from': email_from or \
|
||||
'email_from': emails.get('email_from') or \
|
||||
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
|
||||
case.user_id.address_id.email) or tools.config.get('email_from', False),
|
||||
'email_cc': emails.get('email_cc', None),
|
||||
'email_bcc': emails.get('email_bcc', None),
|
||||
'partner_id': hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False,
|
||||
'references': references,
|
||||
'message_id': message_id,
|
||||
'ref_id': message.get('ref_id'),
|
||||
'message_id': message.get('message_id'),
|
||||
'attachment_ids': [(6, 0, attachments)]
|
||||
}
|
||||
obj.create(cr, uid, data, context)
|
||||
obj.create(cr, uid, data, context=context)
|
||||
return True
|
||||
|
||||
history = _history
|
||||
__history = _history
|
||||
|
||||
mailgate_thread()
|
||||
|
||||
class mailgate_message(osv.osv):
|
||||
@@ -415,15 +421,9 @@ class mailgate_tool(osv.osv_memory):
|
||||
# Store messages
|
||||
context.update({'model' : model})
|
||||
if hasattr(model_pool, '_history'):
|
||||
model_pool._history(cr, uid, res_ids, _('Receive'), history=True,
|
||||
subject = msg.get('subject'),
|
||||
email = msg.get('to'),
|
||||
details = msg.get('body'),
|
||||
email_from = msg.get('from'),
|
||||
message_id = msg.get('message-id'),
|
||||
references = msg.get('references', False),
|
||||
attach = attachments.items(),
|
||||
context = context)
|
||||
emails = {'email_from': msg.get('from'), 'email_to': msg.get('to'), 'email_cc': msg.get('cc')}
|
||||
message = {'subject': msg.get('subject'), 'description': msg.get('body'), 'message_id': msg.get('message-id'), 'ref_id': msg.get('references', False) , 'attach': attachments.items()}
|
||||
model_pool._history(cr, uid, res_ids, _('Receive'), history=True, emails=emails, message=message, context = context)
|
||||
else:
|
||||
self.history(cr, uid, model, res_ids, msg, attachment_ids, context=context)
|
||||
self.email_forward(cr, uid, model, res_ids, msg_txt)
|
||||
|
||||
@@ -94,7 +94,7 @@ class tinythunderbird_partner(osv.osv):
|
||||
dictcreate.update({'partner_id':partner[0]['partner_id'][0]})
|
||||
create_id = case_pool.create(cr, user, dictcreate)
|
||||
cases=case_pool.browse(cr,user,[create_id])
|
||||
case_pool._history(cr, user, cases, _('Archive'), history=True, email=False)
|
||||
case_pool._history(cr, user, cases, _('Archive'), history=True)
|
||||
return create_id
|
||||
|
||||
def thunderbird_createcontact(self,cr,user,vals):
|
||||
|
||||
Reference in New Issue
Block a user