[IMP] mail: cleanup/rename API + adapt dependencies (wip)
bzr revid: odo@openerp.com-20110825122757-0mqr0gbol25t0n41
This commit is contained in:
+6
-6
@@ -350,7 +350,7 @@ class crm_case(crm_base):
|
||||
def case_open(self, cr, uid, ids, *args):
|
||||
"""Opens Case"""
|
||||
cases = self.browse(cr, uid, ids)
|
||||
self.history(cr, uid, cases, _('Open'))
|
||||
self.message_append(cr, uid, cases, _('Open'))
|
||||
for case in cases:
|
||||
data = {'state': 'open', 'active': True}
|
||||
if not case.user_id:
|
||||
@@ -363,7 +363,7 @@ class crm_case(crm_base):
|
||||
"""Closes Case"""
|
||||
cases = self.browse(cr, uid, ids)
|
||||
cases[0].state # to fill the browse record cache
|
||||
self.history(cr, uid, cases, _('Close'))
|
||||
self.message_append(cr, uid, cases, _('Close'))
|
||||
self.write(cr, uid, ids, {'state': 'done',
|
||||
'date_closed': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
})
|
||||
@@ -387,7 +387,7 @@ class crm_case(crm_base):
|
||||
raise osv.except_osv(_('Error !'), _('You can not escalate, You are already at the top level regarding your sales-team category.'))
|
||||
self.write(cr, uid, [case.id], data)
|
||||
cases = self.browse(cr, uid, ids)
|
||||
self.history(cr, uid, cases, _('Escalate'))
|
||||
self.message_append(cr, uid, cases, _('Escalate'))
|
||||
self._action(cr, uid, cases, 'escalate')
|
||||
return True
|
||||
|
||||
@@ -395,7 +395,7 @@ class crm_case(crm_base):
|
||||
"""Cancels Case"""
|
||||
cases = self.browse(cr, uid, ids)
|
||||
cases[0].state # to fill the browse record cache
|
||||
self.history(cr, uid, cases, _('Cancel'))
|
||||
self.message_append(cr, uid, cases, _('Cancel'))
|
||||
self.write(cr, uid, ids, {'state': 'cancel',
|
||||
'active': True})
|
||||
self._action(cr, uid, cases, 'cancel')
|
||||
@@ -408,7 +408,7 @@ class crm_case(crm_base):
|
||||
"""Marks case as pending"""
|
||||
cases = self.browse(cr, uid, ids)
|
||||
cases[0].state # to fill the browse record cache
|
||||
self.history(cr, uid, cases, _('Pending'))
|
||||
self.message_append(cr, uid, cases, _('Pending'))
|
||||
self.write(cr, uid, ids, {'state': 'pending', 'active': True})
|
||||
self._action(cr, uid, cases, 'pending')
|
||||
return True
|
||||
@@ -420,7 +420,7 @@ class crm_case(crm_base):
|
||||
state = 'open'
|
||||
cases = self.browse(cr, uid, ids)
|
||||
cases[0].state # to fill the browse record cache
|
||||
self.history(cr, uid, cases, _('Draft'))
|
||||
self.message_append(cr, uid, cases, _('Draft'))
|
||||
self.write(cr, uid, ids, {'state': state, 'active': True})
|
||||
self._action(cr, uid, cases, state)
|
||||
return True
|
||||
|
||||
@@ -106,8 +106,8 @@ class base_action_rule(osv.osv):
|
||||
write['email_cc'] = obj.act_email_cc
|
||||
|
||||
# Put state change by rule in communication history
|
||||
if hasattr(obj, 'state') and action.act_state:
|
||||
model_obj.history(cr, uid, [obj], _(action.act_state))
|
||||
if hasattr(obj, 'state') and hasattr(obj, 'message_append') and action.act_state:
|
||||
model_obj.message_append(cr, uid, [obj], _(action.act_state))
|
||||
|
||||
model_obj.write(cr, uid, [obj.id], write, context)
|
||||
emails = []
|
||||
|
||||
@@ -300,7 +300,7 @@ class crm_lead(crm_case, osv.osv):
|
||||
if 'stage_id' in vals and vals['stage_id']:
|
||||
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
|
||||
text = _("Changed Stage to: %s") % stage_obj.name
|
||||
self.history(cr, uid, ids, text, body_text=text)
|
||||
self.message_append(cr, uid, ids, text, body_text=text, context=context)
|
||||
message=''
|
||||
for case in self.browse(cr, uid, ids, context=context):
|
||||
if case.type == 'lead' or context.get('stage_type',False)=='lead':
|
||||
@@ -337,10 +337,7 @@ class crm_lead(crm_case, osv.osv):
|
||||
|
||||
def message_new(self, cr, uid, msg, custom_values=None, context=None):
|
||||
"""Automatically calls when new email message arrives"""
|
||||
res_id = super(crm_lead, self).message_new(cr, uid, msg,
|
||||
custom_values=custom_values,
|
||||
context=context)
|
||||
mail_thread = self.pool.get('mail.thread')
|
||||
res_id = super(crm_lead, self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
|
||||
subject = msg.get('subject') or _("No Subject")
|
||||
body = msg.get('body_text')
|
||||
msg_from = msg.get('from')
|
||||
@@ -354,9 +351,7 @@ class crm_lead(crm_case, osv.osv):
|
||||
}
|
||||
if priority:
|
||||
vals['priority'] = priority
|
||||
res = mail_thread.get_partner(cr, uid, msg.get('from', False))
|
||||
if res:
|
||||
vals.update(res)
|
||||
vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False)))
|
||||
res_id = self.write(cr, uid, [res_id], vals, context)
|
||||
return res_id
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class crm_add_note(osv.osv_memory):
|
||||
attach = dict(
|
||||
(x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
|
||||
)
|
||||
case_pool.history(cr, uid, [case], truncate_text(obj.body),
|
||||
case_pool.message_append(cr, uid, [case], truncate_text(obj.body),
|
||||
body_text=obj.body, attachments=attach)
|
||||
|
||||
if obj.state == 'unchanged':
|
||||
|
||||
@@ -133,7 +133,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
||||
|
||||
lead.write(vals, context=context)
|
||||
text = _('Converted to opportunity')
|
||||
leads.history(cr, uid, [lead], text, body_text=text, context=context)
|
||||
leads.message_append(cr, uid, [lead], text, body_text=text, context=context)
|
||||
if lead.partner_id:
|
||||
msg_ids = [ x.id for x in lead.message_ids]
|
||||
self.pool.get('mail.message').write(cr, uid, msg_ids, {
|
||||
|
||||
@@ -169,7 +169,7 @@ class crm_merge_opportunity(osv.osv_memory):
|
||||
subject = subject[0] + ", ".join(subject[1:])
|
||||
details = "\n\n".join(details)
|
||||
|
||||
opp_obj.history(cr, uid, [first_opportunity], subject, body_text=details)
|
||||
opp_obj.message_append(cr, uid, [first_opportunity], subject, body_text=details)
|
||||
#data.update({'message_ids' : [(6, 0 ,self._concat_o2m('message_ids', op_ids))]})
|
||||
opp_obj.write(cr, uid, [first_opportunity.id], data)
|
||||
unlink_ids = map(lambda x: x.id, tail_opportunities)
|
||||
|
||||
@@ -89,14 +89,14 @@ class crm_claim(crm.crm_case, osv.osv):
|
||||
stage = super(crm_claim, self).stage_next(cr, uid, ids, context=context)
|
||||
if stage:
|
||||
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context)
|
||||
self.history(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name)
|
||||
self.message_append(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name)
|
||||
return stage
|
||||
|
||||
def stage_previous(self, cr, uid, ids, context=None):
|
||||
stage = super(crm_claim, self).stage_previous(cr, uid, ids, context=context)
|
||||
if stage:
|
||||
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context)
|
||||
self.history(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name)
|
||||
self.message_append(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name)
|
||||
return stage
|
||||
|
||||
def _get_stage_id(self, cr, uid, context=None):
|
||||
@@ -162,10 +162,7 @@ class crm_claim(crm.crm_case, osv.osv):
|
||||
|
||||
def message_new(self, cr, uid, msg, custom_values=None, context=None):
|
||||
"""Automatically called when new email message arrives"""
|
||||
res_id = super(crm_claim,self).message_new(cr, uid, msg,
|
||||
custom_values=custom_values,
|
||||
context=context)
|
||||
mail_thread = self.pool.get('mail.thread')
|
||||
res_id = super(crm_claim,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
|
||||
subject = msg.get('subject')
|
||||
body = msg.get('body_text')
|
||||
msg_from = msg.get('from')
|
||||
@@ -179,9 +176,7 @@ class crm_claim(crm.crm_case, osv.osv):
|
||||
}
|
||||
if priority:
|
||||
vals['priority'] = priority
|
||||
res = mail_thread.get_partner(cr, uid, msg.get('from', False))
|
||||
if res:
|
||||
vals.update(res)
|
||||
vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False)))
|
||||
self.write(cr, uid, [res_id], vals, context=context)
|
||||
return res_id
|
||||
|
||||
|
||||
@@ -98,26 +98,17 @@ class crm_helpdesk(crm.crm_case, osv.osv):
|
||||
def message_new(self, cr, uid, msg_dict, custom_values=None, context=None):
|
||||
"""Automatically called when new email message arrives"""
|
||||
res_id = super(crm_helpdesk,self).message_new(cr, uid, msg_dict, custom_values=custom_values, context=context)
|
||||
thread_pool = self.pool.get('mail.thread')
|
||||
subject = msg.get('subject') or _("No Subject")
|
||||
body = msg.get('body_text')
|
||||
msg_from = msg.get('from')
|
||||
priority = msg.get('priority')
|
||||
|
||||
subject = msg_dict.get('subject') or _("No Subject")
|
||||
body = msg_dict.get('body_text')
|
||||
msg_from = msg_dict.get('from')
|
||||
vals = {
|
||||
'name': subject,
|
||||
'email_from': msg_from,
|
||||
'email_cc': msg.get('cc'),
|
||||
'email_cc': msg_dict.get('cc'),
|
||||
'description': body,
|
||||
'user_id': False,
|
||||
}
|
||||
if priority:
|
||||
vals['priority'] = priority
|
||||
|
||||
res = thread_pool.get_partner(cr, uid, msg.get('from', False))
|
||||
if res:
|
||||
vals.update(res)
|
||||
|
||||
vals.update(self.message_partner_by_email(cr, uid, msg_dict.get('from', False)))
|
||||
self.write(cr, uid, [res_id], vals, context)
|
||||
return res_id
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ class event_registration(osv.osv):
|
||||
})
|
||||
inv_id = inv_pool.create(cr, uid, val_invoice['value'], context=context)
|
||||
inv_pool.button_compute(cr, uid, [inv_id])
|
||||
self.history(cr, uid, [reg], _('Invoiced'))
|
||||
self.message_append(cr, uid, [reg], _('Invoiced'))
|
||||
return inv_id
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
@@ -430,7 +430,7 @@ class event_registration(osv.osv):
|
||||
"""
|
||||
res = self.write(cr, uid, ids, {'state': 'open'}, context=context)
|
||||
self.mail_user(cr, uid, ids)
|
||||
self.history(cr, uid, ids, _('Open'))
|
||||
self.message_append(cr, uid, ids, _('Open'))
|
||||
return res
|
||||
|
||||
def do_close(self, cr, uid, ids, context=None):
|
||||
@@ -444,7 +444,7 @@ class event_registration(osv.osv):
|
||||
if invoice_id:
|
||||
values['invoice_id'] = invoice_id
|
||||
res = self.write(cr, uid, ids, values)
|
||||
self.history(cr, uid, ids, msg)
|
||||
self.message_append(cr, uid, ids, msg)
|
||||
return res
|
||||
|
||||
def check_confirm(self, cr, uid, ids, context=None):
|
||||
@@ -515,7 +515,7 @@ class event_registration(osv.osv):
|
||||
"""This Function Cancel Event Registration.
|
||||
"""
|
||||
registrations = self.browse(cr, uid, ids)
|
||||
self.history(cr, uid, registrations, _('Cancel'))
|
||||
self.message_append(cr, uid, registrations, _('Cancel'))
|
||||
return self.write(cr, uid, ids, {'state': 'cancel'})
|
||||
|
||||
def mail_user(self, cr, uid, ids, confirm=False, context=None):
|
||||
|
||||
@@ -322,12 +322,11 @@ class hr_applicant(crm.crm_case, osv.osv):
|
||||
|
||||
def message_new(self, cr, uid, msg, custom_values=None, context=None):
|
||||
"""Automatically called when new email message arrives"""
|
||||
thread_pool = self.pool.get('mail.thread')
|
||||
res_id = super(hr_applicant,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
|
||||
subject = msg.get('subject') or _("No Subject")
|
||||
body = msg.get('body_text')
|
||||
msg_from = msg.get('from')
|
||||
priority = msg.get('priority')
|
||||
|
||||
vals = {
|
||||
'name': subject,
|
||||
'email_from': msg_from,
|
||||
@@ -337,12 +336,8 @@ class hr_applicant(crm.crm_case, osv.osv):
|
||||
}
|
||||
if priority:
|
||||
vals['priority'] = priority
|
||||
|
||||
res = thread_pool.get_partner(cr, uid, msg.get('from'))
|
||||
if res:
|
||||
vals.update(res)
|
||||
res_id = self.create(cr, uid, vals, context)
|
||||
self.append_mail(cr, uid, ids, msg, context=context)
|
||||
vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False)))
|
||||
self.write(cr, uid, [res_id], vals, context)
|
||||
return res_id
|
||||
|
||||
def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None):
|
||||
@@ -371,7 +366,7 @@ class hr_applicant(crm.crm_case, osv.osv):
|
||||
|
||||
vals.update(vls)
|
||||
res = self.write(cr, uid, ids, vals, context=context)
|
||||
self.append_mail(cr, uid, ids, msg, context=context)
|
||||
self.message_append_dict(cr, uid, ids, msg, context=context)
|
||||
return res
|
||||
|
||||
def case_open(self, cr, uid, ids, *args):
|
||||
|
||||
+76
-57
@@ -36,12 +36,20 @@ _logger = logging.getLogger('mail')
|
||||
class mail_thread(osv.osv):
|
||||
'''Mixin model, meant to be inherited by any model that needs to
|
||||
act as a discussion topic on which messages can be attached.
|
||||
Public methods are prefixed in order to avoid name collisions
|
||||
with existing methods of the models that will use this mixin.
|
||||
Public methods are prefixed with ``message_`` in order to avoid
|
||||
name collisions with methods of the models that will inherit
|
||||
from this mixin.
|
||||
|
||||
``mail.thread`` adds a one2many of mail.messages, acting as the
|
||||
thread's history, and a few methods that may be overridden to
|
||||
implement model-specific behavior upon arrival of new messages.
|
||||
|
||||
Inheriting classes are not required to implement any method, as the
|
||||
default implementation will work for any model. However it is common
|
||||
to override at least the ``message_new`` and ``message_update``
|
||||
methods (calling ``super``) to add model-specific behavior at
|
||||
creation and update of a thread.
|
||||
|
||||
mail.thread adds a one2many of mail.messages, acting as thread
|
||||
history, and a few methods that may be overridden to implement
|
||||
specific behavior.
|
||||
'''
|
||||
_name = 'mail.thread'
|
||||
_description = 'Email Thread'
|
||||
@@ -81,15 +89,17 @@ class mail_thread(osv.osv):
|
||||
|
||||
def message_new(self, cr, uid, msg_dict, custom_values=None, context=None):
|
||||
"""Called by ``message_process`` when a new message is received
|
||||
without referencing an existing thread. The default
|
||||
behavior is to create a new record of the corresponding
|
||||
model, then call ``append_mail()`` to attach a new
|
||||
mail.message to the newly created record.
|
||||
for a given thread model, if the message did not belong to
|
||||
an existing thread.
|
||||
The default behavior is to create a new record of the corresponding
|
||||
model (based on some very basic info extracted from the message),
|
||||
then attach the message to the newly created record
|
||||
(by calling ``message_append_dict``).
|
||||
Additional behavior may be implemented by overriding this method.
|
||||
|
||||
:param dict msg_dict: a map containing the email details and
|
||||
attachments. See ``message_process`` and
|
||||
``mail.message.parse()`` for details.
|
||||
``mail.message.parse`` for details.
|
||||
:param dict custom_values: optional dictionary of additional
|
||||
field values to pass to create()
|
||||
when creating the new thread record.
|
||||
@@ -113,14 +123,14 @@ class mail_thread(osv.osv):
|
||||
if custom_values and isinstance(custom_values, dict):
|
||||
data.update(custom_values)
|
||||
res_id = model_pool.create(cr, uid, data, context=context)
|
||||
self.append_mail(cr, uid, [res_id], msg_dict, context=context)
|
||||
self.message_append_dict(cr, uid, [res_id], msg_dict, context=context)
|
||||
return res_id
|
||||
|
||||
def message_update(self, cr, uid, ids, msg_dict, vals={}, default_act=None, context=None):
|
||||
"""Called by ``message_process`` when a new message is received
|
||||
for an existing thread. The default behavior is to create a
|
||||
new mail.message in the given thread by calling
|
||||
``append_mail()``.
|
||||
new mail.message in the given thread (by calling
|
||||
``message_append_dict``)
|
||||
Additional behavior may be implemented by overriding this
|
||||
method.
|
||||
|
||||
@@ -132,43 +142,9 @@ class mail_thread(osv.osv):
|
||||
to determine the model of the thread to
|
||||
update (instead of the current model).
|
||||
"""
|
||||
return self.append_mail(cr, uid, ids, msg_dict, context=context)
|
||||
return self.message_append_dict(cr, uid, ids, msg_dict, context=context)
|
||||
|
||||
def append_mail(self, cr, uid, ids, msg_dict, context=None):
|
||||
"""Creates a new mail.message attached to the given threads,
|
||||
with the contents of msg_dict, by calling ``history`` with
|
||||
the mail details. All attachments in msg_dict will be
|
||||
attached to the thread record as well as to the actual
|
||||
message.
|
||||
|
||||
:param dict msg_dict: a map containing the email details and
|
||||
attachments. See ``message_process`` and
|
||||
``mail.message.parse()`` for details.
|
||||
:param dict context: if a ``thread_model`` value is present
|
||||
in the context, its value will be used
|
||||
to determine the model of the thread to
|
||||
update (instead of the current model).
|
||||
"""
|
||||
return self.history(cr, uid, ids,
|
||||
subject = msg_dict.get('subject'),
|
||||
body_text = msg_dict.get('body_text'),
|
||||
email_to = msg_dict.get('to'),
|
||||
email_from = msg_dict.get('from'),
|
||||
email_cc = msg_dict.get('cc'),
|
||||
email_bcc = msg_dict.get('bcc'),
|
||||
reply_to = msg_dict.get('reply'),
|
||||
email_date = msg_dict.get('date'),
|
||||
message_id = msg_dict.get('message-id'),
|
||||
references = msg_dict.get('references')\
|
||||
or msg_dict.get('in-reply-to'),
|
||||
attachments = msg_dict.get('attachments'),
|
||||
body_html= msg_dict.get('body_html'),
|
||||
subtype = msg_dict.get('subtype'),
|
||||
headers = msg_dict.get('headers'),
|
||||
original = msg_dict.get('original'),
|
||||
context = context)
|
||||
|
||||
def history(self, cr, uid, threads, subject, body_text=None, email_to=False,
|
||||
def message_append(self, cr, uid, threads, subject, body_text=None, email_to=False,
|
||||
email_from=False, email_cc=None, email_bcc=None, reply_to=None,
|
||||
email_date=None, message_id=False, references=None,
|
||||
attachments=None, body_html=None, subtype=None, headers=None,
|
||||
@@ -279,13 +255,49 @@ class mail_thread(osv.osv):
|
||||
mail_message.create(cr, uid, data, context=context)
|
||||
return True
|
||||
|
||||
def message_append_dict(self, cr, uid, ids, msg_dict, context=None):
|
||||
"""Creates a new mail.message attached to the given threads (``ids``),
|
||||
with the contents of ``msg_dict``, by calling ``message_append``
|
||||
with the mail details. All attachments in msg_dict will be
|
||||
attached to the object record as well as to the actual
|
||||
mail message.
|
||||
|
||||
:param dict msg_dict: a map containing the email details and
|
||||
attachments. See ``message_process()`` and
|
||||
``mail.message.parse()`` for details on
|
||||
the dict structure.
|
||||
:param dict context: if a ``thread_model`` value is present
|
||||
in the context, its value will be used
|
||||
to determine the model of the thread to
|
||||
update (instead of the current model).
|
||||
"""
|
||||
return self.message_append(cr, uid, ids,
|
||||
subject = msg_dict.get('subject'),
|
||||
body_text = msg_dict.get('body_text'),
|
||||
email_to = msg_dict.get('to'),
|
||||
email_from = msg_dict.get('from'),
|
||||
email_cc = msg_dict.get('cc'),
|
||||
email_bcc = msg_dict.get('bcc'),
|
||||
reply_to = msg_dict.get('reply'),
|
||||
email_date = msg_dict.get('date'),
|
||||
message_id = msg_dict.get('message-id'),
|
||||
references = msg_dict.get('references')\
|
||||
or msg_dict.get('in-reply-to'),
|
||||
attachments = msg_dict.get('attachments'),
|
||||
body_html= msg_dict.get('body_html'),
|
||||
subtype = msg_dict.get('subtype'),
|
||||
headers = msg_dict.get('headers'),
|
||||
original = msg_dict.get('original'),
|
||||
context = context)
|
||||
|
||||
|
||||
def message_process(self, cr, uid, model, message, custom_values=None, context=None):
|
||||
"""Process an incoming RFC2822 email message related to the
|
||||
given thread model, relying on ``mail.message.parse()``
|
||||
for the parsing operation, and then calling ``message_new``
|
||||
(if the thread record did not exist) or ``message_update``
|
||||
(if it did), then calling ``message_forward()`` to automatically
|
||||
notify other people that should receive this email.
|
||||
(if it did), then calling ``message_forward`` to automatically
|
||||
notify other people that should receive this message.
|
||||
|
||||
:param string model: the thread model for which a new message
|
||||
must be processed
|
||||
@@ -305,7 +317,7 @@ class mail_thread(osv.osv):
|
||||
model_pool = self.pool.get(model)
|
||||
if self._name != model:
|
||||
if context is None: context = {}
|
||||
context.update({'thread_model':model})
|
||||
context.update({'thread_model': model})
|
||||
|
||||
mail_message = self.pool.get('mail.message')
|
||||
res_id = False
|
||||
@@ -379,8 +391,8 @@ class mail_thread(osv.osv):
|
||||
[decode(msg['from']),
|
||||
decode(msg['to']),
|
||||
decode(msg['cc'])])))
|
||||
message_forward = [i for i in message_followers_emails if (i and (i not in message_recipients))]
|
||||
if message_forward:
|
||||
forward_to = [i for i in message_followers_emails if (i and (i not in message_recipients))]
|
||||
if forward_to:
|
||||
# TODO: we need an interface for this for all types of objects, not just leads
|
||||
if hasattr(res, 'section_id'):
|
||||
del msg['reply-to']
|
||||
@@ -388,7 +400,7 @@ class mail_thread(osv.osv):
|
||||
|
||||
smtp_from = mail_message.to_email(msg['from'])
|
||||
msg['from'] = smtp_from
|
||||
msg['to'] = message_forward
|
||||
msg['to'] = forward_to
|
||||
msg['message-id'] = tools.generate_tracking_message_id(res.id)
|
||||
if not smtp_server_obj.send_email(cr, uid, msg) and email_error:
|
||||
subj = msg['subject']
|
||||
@@ -398,9 +410,16 @@ class mail_thread(osv.osv):
|
||||
smtp_server_obj.send_email(cr, uid, msg)
|
||||
return True
|
||||
|
||||
def get_partner(self, cr, uid, email, context=None):
|
||||
def message_partner_by_email(self, cr, uid, email, context=None):
|
||||
"""Attempts to return the id of a partner address matching
|
||||
the given ``email``, and the corresponding partner.
|
||||
the given ``email``, and the corresponding partner id.
|
||||
Can be used by classes using the ``mail.thread`` mixin
|
||||
to lookup the partner and use it in their implementation
|
||||
of ``message_new`` to link the new record with a
|
||||
corresponding partner.
|
||||
The keys used in the returned dict are meant to map
|
||||
to usual names for relationships towards a partner
|
||||
and one of its addresses.
|
||||
|
||||
:param email: email address for which a partner
|
||||
should be searched for.
|
||||
|
||||
@@ -209,7 +209,7 @@ class XMLRpcConn(object):
|
||||
if attachments:
|
||||
result = self.MakeAttachment([rec], mail)
|
||||
execute(conn, 'execute', self. _dbname, int(self._uid), self._pwd,
|
||||
'mail.thread','history',[res_id],
|
||||
'mail.thread','message_append',[res_id],
|
||||
msg.get('subject', False),
|
||||
msg.get('body', False),
|
||||
msg.get('to', False),
|
||||
|
||||
@@ -388,20 +388,17 @@ class project_issue(crm.crm_case, osv.osv):
|
||||
else:
|
||||
raise osv.except_osv(_('Warning !'), _('You cannot escalate this issue.\nThe relevant Project has not configured the Escalation Project!'))
|
||||
self.write(cr, uid, [case.id], data)
|
||||
self.history(cr, uid, cases, _('Escalate'))
|
||||
self.message_append(cr, uid, cases, _('Escalate'))
|
||||
return True
|
||||
|
||||
def message_new(self, cr, uid, msg, custom_values=None, context=None):
|
||||
"""Automatically called when new email message arrives"""
|
||||
if context is None:
|
||||
context = {}
|
||||
thread_pool = self.pool.get('mail.thread')
|
||||
|
||||
subject = msg.get('subject') or _('No Title')
|
||||
body = msg.get('body_text')
|
||||
msg_from = msg.get('from')
|
||||
priority = msg.get('priority')
|
||||
|
||||
vals = {
|
||||
'name': subject,
|
||||
'email_from': msg_from,
|
||||
@@ -411,17 +408,14 @@ class project_issue(crm.crm_case, osv.osv):
|
||||
}
|
||||
if priority:
|
||||
vals['priority'] = priority
|
||||
|
||||
res = thread_pool.get_partner(cr, uid, msg.get('from'))
|
||||
if res:
|
||||
vals.update(res)
|
||||
vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False)))
|
||||
context.update({'state_to' : 'draft'})
|
||||
|
||||
if custom_values and isinstance(custom_values, dict):
|
||||
vals.update(custom_values)
|
||||
|
||||
res_id = self.create(cr, uid, vals, context)
|
||||
self.append_mail(cr, uid, [res_id], msg, context=context)
|
||||
self.message_append_dict(cr, uid, [res_id], msg, context=context)
|
||||
self.convert_to_bug(cr, uid, [res_id], context=context)
|
||||
return res_id
|
||||
|
||||
@@ -460,7 +454,7 @@ class project_issue(crm.crm_case, osv.osv):
|
||||
|
||||
vals.update(vls)
|
||||
res = self.write(cr, uid, ids, vals)
|
||||
self.append_mail(cr, uid, [res_id], msg, context=context)
|
||||
self.message_append_dict(cr, uid, [res_id], msg, context=context)
|
||||
return res
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
|
||||
@@ -34,24 +34,17 @@ class project_tasks(osv.osv):
|
||||
}
|
||||
|
||||
def message_new(self, cr, uid, msg, custom_values=None, context=None):
|
||||
thread_obj = self.pool.get('mail.thread')
|
||||
res_id = super(project_tasks,self).message_new(cr, uid, msg, custom_values=custom_values, context=context)
|
||||
subject = msg.get('subject')
|
||||
body = msg.get('body_text')
|
||||
msg_from = msg.get('from')
|
||||
|
||||
data = {
|
||||
'name': subject,
|
||||
'description': body,
|
||||
'planned_hours': 0.0,
|
||||
}
|
||||
res = thread_obj.get_partner(cr, uid, msg_from)
|
||||
if res:
|
||||
data.update(res)
|
||||
|
||||
if custom_values and isinstance(custom_values, dict):
|
||||
data.update(custom_values)
|
||||
res_id = self.create(cr, uid, data, context)
|
||||
self.append_mail(cr, uid, [res_id], msg, context=context)
|
||||
data.update(self.message_partner_by_email(cr, uid, msg_from))
|
||||
self.write(cr, uid, [res_id], data, context)
|
||||
return res_id
|
||||
|
||||
def message_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
|
||||
@@ -80,7 +73,7 @@ class project_tasks(osv.osv):
|
||||
|
||||
self.write(cr, uid, ids, data, context=context)
|
||||
getattr(self,act)(cr, uid, ids, context=context)
|
||||
self.append_mail(cr, uid, [res_id], msg, context=context)
|
||||
self.message_append_dict(cr, uid, [res_id], msg, context=context)
|
||||
return True
|
||||
|
||||
def message_thread_followers(self, cr, uid, ids, context=None):
|
||||
@@ -102,19 +95,19 @@ class project_tasks(osv.osv):
|
||||
def do_draft(self, cr, uid, ids, context=None):
|
||||
res = super(project_tasks, self).do_draft(cr, uid, ids, context)
|
||||
tasks = self.browse(cr, uid, ids, context=context)
|
||||
self.history(cr, uid, tasks, _('Draft'), context=context)
|
||||
self.message_append(cr, uid, tasks, _('Draft'), context=context)
|
||||
return res
|
||||
|
||||
def do_open(self, cr, uid, ids, context=None):
|
||||
res = super(project_tasks, self).do_open(cr, uid, ids, context)
|
||||
tasks = self.browse(cr, uid, ids, context=context)
|
||||
self.history(cr, uid, tasks, _('Open'), context=context)
|
||||
self.message_append(cr, uid, tasks, _('Open'), context=context)
|
||||
return res
|
||||
|
||||
def do_pending(self, cr, uid, ids, context=None):
|
||||
res = super(project_tasks, self).do_pending(cr, uid, ids, context)
|
||||
tasks = self.browse(cr, uid, ids, context=context)
|
||||
self.history(cr, uid, tasks, _('Pending'), context=context)
|
||||
self.message_append(cr, uid, tasks, _('Pending'), context=context)
|
||||
return res
|
||||
|
||||
def do_close(self, cr, uid, ids, context=None):
|
||||
@@ -122,13 +115,13 @@ class project_tasks(osv.osv):
|
||||
tasks = self.browse(cr, uid, ids, context=context)
|
||||
for task in tasks:
|
||||
if task.state == 'done':
|
||||
self.history(cr, uid, tasks, _('Done'), context=context)
|
||||
self.message_append(cr, uid, tasks, _('Done'), context=context)
|
||||
return res
|
||||
|
||||
def do_cancel(self, cr, uid, ids, context=None):
|
||||
res = super(project_tasks, self).do_cancel(cr, uid, ids, context=context)
|
||||
tasks = self.browse(cr, uid, ids, context=context)
|
||||
self.history(cr, uid, tasks, _('Cancel'), context=context)
|
||||
self.message_append(cr, uid, tasks, _('Cancel'), context=context)
|
||||
return res
|
||||
|
||||
project_tasks()
|
||||
|
||||
@@ -108,7 +108,7 @@ class crm_make_sale(osv.osv_memory):
|
||||
new_ids.append(new_id)
|
||||
message = _("Opportunity '%s' is converted to Quotation.") % (case.name)
|
||||
self.log(cr, uid, case.id, message)
|
||||
case_obj.history(cr, uid, [case], _("Converted to Sales Quotation(id: %s).") % (new_id))
|
||||
case_obj.message_append(cr, uid, [case], _("Converted to Sales Quotation(id: %s).") % (new_id), context=context)
|
||||
|
||||
if make.close:
|
||||
case_obj.case_close(cr, uid, data)
|
||||
|
||||
@@ -89,7 +89,7 @@ class thunderbird_partner(osv.osv_memory):
|
||||
obj_attch.create(cr, uid, res)
|
||||
threads = self.pool.get(model).browse(cr, uid, res_id)
|
||||
|
||||
thread_pool.history(cr, uid,
|
||||
thread_pool.message_append(cr, uid,
|
||||
[threads],
|
||||
subject = msg.get('subject'),
|
||||
details = msg.get('body_text'),
|
||||
|
||||
Reference in New Issue
Block a user