[MERGE+REVIEW]
bzr revid: hmo@tinyerp.com-20110413130425-yaljvh5kexeqdf6f
This commit is contained in:
commit
51ce311aac
|
@ -40,7 +40,7 @@ class email_compose_message(osv.osv_memory):
|
|||
result.update({
|
||||
'subject' : data.name or False,
|
||||
'email_to' : data.email_from or False,
|
||||
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
|
||||
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or tools.config.get('email_from', False),
|
||||
'body' : '\n' + (tools.ustr(data.user_id.signature or '')),
|
||||
'email_cc' : tools.ustr(data.email_cc or ''),
|
||||
'model': model or False,
|
||||
|
|
|
@ -65,19 +65,17 @@ class email_template(osv.osv):
|
|||
mod_name = self.pool.get('ir.model').browse(cr, uid, model_id, context).model
|
||||
return {'value':{'model':mod_name}}
|
||||
|
||||
def _lang_get(self, cr, uid, context={}):
|
||||
obj = self.pool.get('res.lang')
|
||||
ids = obj.search(cr, uid, [], context=context)
|
||||
res = obj.read(cr, uid, ids, ['code', 'name'], context)
|
||||
return [(r['code'], r['name']) for r in res] + [('','')]
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=250),
|
||||
'model_id':fields.many2one('ir.model', 'Resource'),
|
||||
'model': fields.related('model_id', 'model', string='Model', type="char", size=128, store=True, readonly=True),
|
||||
'track_campaign_item':fields.boolean('Resource Tracking',
|
||||
help="Enable this is you wish to include a special \
|
||||
tracking marker in outgoing emails so you can identify replies and link \
|
||||
them back to the corresponding resource record. \
|
||||
This is useful for CRM leads for example"),
|
||||
'lang':fields.char(
|
||||
'Language',
|
||||
size=250,
|
||||
help="The default language for the email."
|
||||
'lang': fields.selection(_lang_get, 'Language', size=5, help="The default language for the email."
|
||||
" Placeholders can be used here. "
|
||||
"eg. ${object.partner_id.lang}"),
|
||||
'subject':fields.char(
|
||||
|
@ -157,7 +155,6 @@ This is useful for CRM leads for example"),
|
|||
'email_to': fields.char('To', size=256, help="Email Recipients. Placeholders can be used here."),
|
||||
'email_cc': fields.char('Cc', size=256, help="Carbon Copy Email Recipients. Placeholders can be used here."),
|
||||
'email_bcc': fields.char('Bcc', size=256, help="Blind Carbon Copy Email Recipients. Placeholders can be used here."),
|
||||
'message_id': fields.char('Message Id', size=1024, select=1, help="Message Id on Email. Placeholders can be used here."),
|
||||
'reply_to':fields.char('Reply-To', size=250, help="Placeholders can be used here."),
|
||||
'body': fields.text('Description', translate=True, help="Placeholders can be used here."),
|
||||
'body_html': fields.text('HTML', help="Contains HTML version of email. Placeholders can be used here."),
|
||||
|
@ -183,7 +180,7 @@ This is useful for CRM leads for example"),
|
|||
'res_model': 'email.compose.message',
|
||||
'src_model': src_obj,
|
||||
'view_type': 'form',
|
||||
'context': "{'template_id':'%d','src_rec_id':active_id,'src_rec_ids':active_ids}" % (src_obj, template.id),
|
||||
'context': "{'template_id':'%d','src_rec_id':active_id,'src_rec_ids':active_ids}" % (template.id),
|
||||
'view_mode':'form,tree',
|
||||
'view_id': res_id,
|
||||
'target': 'new',
|
||||
|
@ -388,14 +385,6 @@ This is useful for CRM leads for example"),
|
|||
#'body_html': self.get_template_value(cr, uid, template.body_html, model, record_id, context),
|
||||
}
|
||||
|
||||
if template.message_id:
|
||||
# use provided message_id with placeholders
|
||||
values.update({'message_id': self.get_template_value(cr, uid, template.message_id, model, record_id, context)})
|
||||
|
||||
elif template['track_campaign_item']:
|
||||
# get appropriate message-id
|
||||
values.update({'message_id': tools.generate_tracking_message_id(record_id)})
|
||||
|
||||
#Use signatures if allowed
|
||||
if template.user_signature:
|
||||
sign = self.pool.get('res.users').read(cr, uid, uid, ['signature'], context)['signature']
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<separator string="Options" colspan="2"/>
|
||||
<field name="lang" colspan="4" />
|
||||
<field name="user_signature" colspan="4" />
|
||||
<field name="track_campaign_item" colspan="4"/>
|
||||
<field name="auto_delete"/>
|
||||
</group>
|
||||
<group col="2" colspan="2">
|
||||
<separator colspan="2" string="Email Content"/>
|
||||
|
@ -72,11 +72,6 @@
|
|||
<field name="ref_ir_value"/>
|
||||
<button name="unlink_action" string="Delete Action" type="object" icon="gtk-delete" colspan="2" attrs="{'invisible':[('ref_ir_act_window','=',False), ('ref_ir_value','=',False)]}"/>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Advanced Options" colspan="2"/>
|
||||
<field name="message_id"/>
|
||||
<field name="auto_delete"/>
|
||||
</group>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Attachments" colspan="2"/>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
from osv import osv
|
||||
from osv import fields
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
class email_compose_message(osv.osv_memory):
|
||||
_name = 'email.compose.message'
|
||||
|
@ -127,6 +128,10 @@ class email_compose_message(osv.osv_memory):
|
|||
'template_id': fields.selection(_get_templates, 'Template'),
|
||||
}
|
||||
|
||||
def get_template_value(self, cr, uid, message, model, resource_id, context=None):
|
||||
template_pool = self.pool.get('email.template')
|
||||
return template_pool.get_template_value(cr, uid, message, model, resource_id, context)
|
||||
|
||||
def on_change_template(self, cr, uid, ids, model, template_id, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
@ -138,6 +143,15 @@ class email_compose_message(osv.osv_memory):
|
|||
vals.update(self.get_template_data(cr, uid, resource_id, template_id, context))
|
||||
else:
|
||||
vals.update({'attachment_ids' : []})
|
||||
|
||||
email_temp_pool = self.pool.get('email.template')
|
||||
template_data = email_temp_pool.browse(cr, uid, template_id, context=context)
|
||||
vals.update({'auto_delete': template_data.auto_delete})
|
||||
if context.get('active_model') and context.get('active_id') and template_data.user_signature:
|
||||
model_pool = self.pool.get(context['active_model'])
|
||||
user = model_pool.browse(cr, uid, context['active_id'], context=context).user_id
|
||||
signature = user and user.signature or ''
|
||||
vals['body'] = vals['body'] + '\n' + signature
|
||||
return {'value': vals}
|
||||
|
||||
email_compose_message()
|
||||
|
|
|
@ -90,10 +90,6 @@ class email_template_preview(osv.osv_memory):
|
|||
vals['email_cc'] = self.get_template_value(cr, uid, template.email_cc, model, res_id, context)
|
||||
vals['email_bcc'] = self.get_template_value(cr, uid, template.email_bcc, model, res_id, context)
|
||||
vals['reply_to'] = self.get_template_value(cr, uid, template.reply_to, model, res_id, context)
|
||||
if template.message_id:
|
||||
vals['message_id'] = self.get_template_value(cr, uid, message_id, model, res_id, context)
|
||||
elif template.track_campaign_item:
|
||||
vals['message_id'] = tools.generate_tracking_message_id(res_id)
|
||||
vals['subject'] = self.get_template_value(cr, uid, template.subject, model, res_id, context)
|
||||
description = self.get_template_value(cr, uid, template.body, model, res_id, context) or ''
|
||||
if template.user_signature:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
<field name="email_cc" readonly="1"/>
|
||||
<field name="email_bcc" readonly="1"/>
|
||||
<field name="reply_to" readonly="1"/>
|
||||
<field name="message_id" readonly="1" attrs="{'invisible':[('message_id','=',False)]}" groups="base.group_extended"/>
|
||||
<field name="subject" colspan="8" readonly="1"/>
|
||||
</group>
|
||||
<group col="4" colspan="4">
|
||||
|
|
|
@ -58,12 +58,6 @@ class email_template_send_wizard(osv.osv_memory):
|
|||
if 'smtp_server_id' in fields:
|
||||
result['smtp_server_id'] = template.smtp_server_id.id
|
||||
|
||||
if 'message_id' in fields:
|
||||
result['message_id'] = template.message_id
|
||||
|
||||
if 'track_campaign_item' in fields:
|
||||
result['track_campaign_item'] = template.track_campaign_item
|
||||
|
||||
if 'attachment_ids' in fields:
|
||||
result['attachment_ids'] = template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids']
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ def format_date_tz(date, tz=None):
|
|||
class email_message_common(osv.osv_memory):
|
||||
_name = 'email.message.common'
|
||||
_columns = {
|
||||
'subject':fields.text('Subject', translate=True),
|
||||
'subject':fields.text('Subject'),
|
||||
'model': fields.char('Object Name', size=128, select=1),
|
||||
'res_id': fields.integer('Resource ID', select=1),
|
||||
'date': fields.datetime('Date'),
|
||||
|
@ -87,7 +87,7 @@ class email_message_common(osv.osv_memory):
|
|||
'sub_type': fields.char('Sub Type', size=32),
|
||||
'headers': fields.text('x_headers'),
|
||||
'priority':fields.integer('Priority'),
|
||||
'body': fields.text('Description', translate=True),
|
||||
'body': fields.text('Description'),
|
||||
'body_html': fields.text('HTML', help="Contains HTML version of email"),
|
||||
'smtp_server_id':fields.many2one('ir.mail_server', 'SMTP Server'),
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ class email_message(osv.osv):
|
|||
msg_txt['message-id'] = message_id
|
||||
_logger.info('Parsing Message without message-id, generating a random one: %s', message_id)
|
||||
|
||||
|
||||
|
||||
fields = msg_txt.keys()
|
||||
msg['id'] = message_id
|
||||
msg['message-id'] = message_id
|
||||
|
@ -422,7 +422,7 @@ 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,
|
||||
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,
|
||||
|
|
|
@ -100,6 +100,8 @@ class email_compose_message(osv.osv_memory):
|
|||
|
||||
_columns = {
|
||||
'attachment_ids': fields.many2many('ir.attachment','email_message_send_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'),
|
||||
'auto_delete': fields.boolean('Auto Delete', help="Permanently delete emails after sending"),
|
||||
'filter_id': fiels
|
||||
}
|
||||
|
||||
def get_value(self, cr, uid, model, res_id, context=None):
|
||||
|
@ -130,7 +132,7 @@ class email_compose_message(osv.osv_memory):
|
|||
'body' : description,
|
||||
'subject' : subject,
|
||||
'message_id' : message_data and message_data.message_id or False,
|
||||
'attachment_ids' : message_data and message_pool.read(cr, uid, message_id, ['attachment_ids'])['attachment_ids'] or [],
|
||||
'attachment_ids' : [],
|
||||
'res_id' : message_data and message_data.res_id or False,
|
||||
'email_from' : message_data and message_data.email_to or False,
|
||||
'email_to' : message_data and message_data.email_from or False,
|
||||
|
@ -153,62 +155,60 @@ class email_compose_message(osv.osv_memory):
|
|||
context = {}
|
||||
|
||||
record = self.browse(cr, uid, ids[0], context=context)
|
||||
if context.get('mass_mail') and context['active_ids'] and context.get('template_id'):
|
||||
email_message_pool = self.pool.get('email.message')
|
||||
email_temp_pool = self.pool.get('email.template')
|
||||
for res_id in context['active_ids']:
|
||||
subject = email_temp_pool.get_template_value(cr, uid, record.subject, context['active_model'], res_id)
|
||||
body = email_temp_pool.get_template_value(cr, uid, record.body, context['active_model'], res_id)
|
||||
email_to = email_temp_pool.get_template_value(cr, uid, record.email_to, context['active_model'], res_id)
|
||||
email_from = email_temp_pool.get_template_value(cr, uid, record.email_from, context['active_model'], res_id)
|
||||
email_cc = email_temp_pool.get_template_value(cr, uid, record.email_cc, context['active_model'], res_id)
|
||||
reply_to = email_temp_pool.get_template_value(cr, uid, record.reply_to, context['active_model'], res_id)
|
||||
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid, email_from,
|
||||
email_to, subject or False, body or False, context['active_model'], email_cc or False, openobject_id=int(res_id),
|
||||
context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
if context.get('mass_mail') and context.get('active_ids') and not context.get('template_id'):
|
||||
self.do_mass_mail(cr, uid, context['active_ids'], record.subject or False, record.body or False, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
email_id = self.save_to_mailbox(cr, uid, ids, context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def do_mass_mail(self, cr, uid, ids, subject, body, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
if context.get('active_model'):
|
||||
email_message_pool = self.pool.get('email.message')
|
||||
model_pool = self.pool.get(context['active_model'])
|
||||
for data in model_pool.browse(cr, uid, ids, context=context):
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid,
|
||||
data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
|
||||
data.email_from or False, subject, body, model=context['active_model'],
|
||||
email_cc=tools.ustr(data.email_cc or ''), openobject_id=int(data.id), context=context)
|
||||
return True
|
||||
|
||||
def save_to_mailbox(self, cr, uid, ids, context=None):
|
||||
email_ids = []
|
||||
email_message_pool = self.pool.get('email.message')
|
||||
email_message_pool = self.pool.get('email.message')
|
||||
attachment = []
|
||||
email_ids = []
|
||||
for mail in self.browse(cr, uid, ids, context=context):
|
||||
for attach in mail.attachment_ids:
|
||||
attachment.append((attach.datas_fname, attach.datas))
|
||||
references = False
|
||||
message_id = False
|
||||
|
||||
# Reply Email
|
||||
if context.get('mail',False) == 'reply' and mail.message_id:
|
||||
references = mail.references and mail.references + "," + mail.message_id or mail.message_id
|
||||
else:
|
||||
message_id = mail.message_id
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid, mail.email_from, mail.email_to, mail.subject, mail.body,
|
||||
|
||||
# Mass mailing
|
||||
if context.get('mass_mail', False):
|
||||
if context['active_ids'] and context['active_model']:
|
||||
active_ids = context['active_ids']
|
||||
active_model = context['active_model']
|
||||
|
||||
else:
|
||||
active_model = record.model.model
|
||||
active_ids = active_model_pool.search(cr, uid, record.filter_id.domain, record.filter_id.context)
|
||||
|
||||
for active_id in active_ids:
|
||||
subject = self.get_template_value(cr, uid, mail.subject, active_model, active_id)
|
||||
body = self.get_template_value(cr, uid, mail.body, active_model, active_id)
|
||||
email_to = self.get_template_value(cr, uid, mail.email_to, active_model, active_id)
|
||||
email_from = self.get_template_value(cr, uid, mail.email_from, active_model, active_id)
|
||||
email_cc = self.get_template_value(cr, uid, mail.email_cc, active_model, active_id)
|
||||
reply_to = self.get_template_value(cr, uid, mail.reply_to, active_model, active_id)
|
||||
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid, mail.email_from, mail.email_to, mail.subject, mail.body,
|
||||
model=mail.model, email_cc=mail.email_cc, email_bcc=mail.email_bcc, reply_to=mail.reply_to,
|
||||
attach=attachment, message_id=message_id, references=references, openobject_id=int(mail.res_id),
|
||||
subtype=mail.sub_type, x_headers=mail.headers, priority=mail.priority, smtp_server_id=mail.smtp_server_id and mail.smtp_server_id.id,
|
||||
auto_delete=mail.auto_delete or False, context=context)
|
||||
email_ids.append(email_id)
|
||||
|
||||
else:
|
||||
email_id = email_message_pool.schedule_with_attach(cr, uid, mail.email_from, mail.email_to, mail.subject, mail.body,
|
||||
model=mail.model, email_cc=mail.email_cc, email_bcc=mail.email_bcc, reply_to=mail.reply_to,
|
||||
attach=attachment, message_id=message_id, references=references, openobject_id=int(mail.res_id),
|
||||
subtype=mail.sub_type, x_headers=mail.headers, priority=mail.priority, smtp_server_id=mail.smtp_server_id and mail.smtp_server_id.id, context=context)
|
||||
email_ids.append(email_id)
|
||||
subtype=mail.sub_type, x_headers=mail.headers, priority=mail.priority, smtp_server_id=mail.smtp_server_id and mail.smtp_server_id.id,
|
||||
auto_delete=mail.auto_delete or False, context=context)
|
||||
email_ids.append(email_id)
|
||||
return email_ids
|
||||
#return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
def get_template_value(self, cr, uid, message, model, resource_id, context=None):
|
||||
return message
|
||||
|
||||
|
||||
email_compose_message()
|
||||
|
||||
|
|
|
@ -7,16 +7,18 @@
|
|||
<field name="model">email.compose.message</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Reply Email">
|
||||
<form string="Compose Email">
|
||||
<group col="6" colspan="4">
|
||||
<field name="model" invisible="1"/>
|
||||
<field name="smtp_server_id" widget="selection" colspan="4"/>
|
||||
<field name="model" invisible="context.get('active_model',False)"/>
|
||||
<field name='filter_id' invisible="context.get('active_model',False)"/>
|
||||
<field name="smtp_server_id" widget="selection" colspan="4" invisible="1"/>
|
||||
<field name="email_from" colspan="4" required="1"/>
|
||||
<field name="email_to" colspan="4" required="1"/>
|
||||
<field name="email_cc" colspan="4"/>
|
||||
<field name="email_bcc" colspan="4"/>
|
||||
<field name="reply_to" colspan="4"/>
|
||||
<field name="subject" colspan="4" widget="char" size="512"/>
|
||||
<field name="auto_delete" colspan="4" invisible="1"/>
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<notebook colspan="4">
|
||||
|
@ -38,7 +40,7 @@
|
|||
</record>
|
||||
|
||||
<record id="action_email_compose_message_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Send E-mail</field>
|
||||
<field name="name">Compose E-mail</field>
|
||||
<field name="res_model">email.compose.message</field>
|
||||
<field name="src_model">email.compose.message</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
|
|
Loading…
Reference in New Issue