[MERGE] backlog3

bzr revid: hmo@tinyerp.com-20110420125313-6loxn2mbenusd70r
This commit is contained in:
Harry (OpenERP)
2011-04-20 18:23:13 +05:30
23 changed files with 187 additions and 725 deletions
-1
View File
@@ -84,7 +84,6 @@ Creates a dashboard for CRM that includes:
'wizard/crm_opportunity_to_phonecall_view.xml',
'wizard/crm_partner_to_opportunity_view.xml',
# 'wizard/crm_send_email_view.xml',
'wizard/crm_add_note_view.xml',
'wizard/crm_merge_opportunities_view.xml',
-262
View File
@@ -1,262 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from crm import crm
from osv import osv, fields
from tools.translate import _
import base64
import itertools
import tools
import re
AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
class crm_send_new_email(osv.osv_memory):
""" Sends new email for the case"""
_name = "crm.send.mail"
_description = "Send new email"
_columns = {
'email_to' : fields.char('To', size=512, required=True),
'email_from' : fields.char('From', size=128, required=True),
'reply_to' : fields.char('Reply To', size=128, required=True, help="Reply-to of the Sales team defined on this case"),
'email_cc' : fields.char('CC', size=512, help="These addresses will receive a copy of this email. To modify the permanent CC list, edit the global CC field of this case"),
'subject': fields.char('Subject', size=512, required=True),
'body': fields.text('Message Body', required=True),
'state': fields.selection(AVAILABLE_STATES, string='Set New State To', required=True),
'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id', 'Attachment'),
'html': fields.boolean('HTML formatting?', help="Select this if you want to send email with HTML formatting."),
}
def action_send(self, cr, uid, ids, context=None):
""" This sends an email to ALL the addresses of the selected partners.
"""
email_message_obj = self.pool.get('email.message')
if context is None:
context = {}
if not context.get('active_model'):
raise osv.except_osv(_('Error'), _('Can not send mail!'))
model = context.get('active_model')
case_pool = self.pool.get(model)
res_id = context and context.get('active_id', False) or False
for obj in self.browse(cr, uid, ids, context=context):
attach = [
(x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
]
subtype = 'plain'
message_id = None
ref_id = None
case = case_pool.browse(cr, uid, res_id, context=context)
if context.get('mail', 'new') == 'new':
if case.message_ids:
message_id = case.message_ids[0].message_id
elif context.get('mail') == 'forward':
# extract attachements from case and emails according to mode
attachments = []
attach_pool = self.pool.get('ir.attachment')
direct_attachments = attach_pool.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', res_id)], context=context)
attachments += attach_pool.browse(cr, uid, direct_attachments, context=context)
if obj.history in ['latest', 'whole'] and case.message_ids:
msgs = case.message_ids
if obj.history == 'latest':
msgs = msgs[:1]
attachments.extend(itertools.chain(*[m.attachment_ids for m in msgs]))
attach_all = [(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas]
attach += attach_all
else:
hist = email_message_obj.browse(cr, uid, res_id, context=context)
message_id = hist.message_id
model = hist.model
case_pool = self.pool.get(model)
res_id = hist.res_id
ref_id = hist.ref_id
case = case_pool.browse(cr, uid, res_id, context=context)
emails = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_to or '')
email_cc = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_cc or '')
emails = filter(None, emails)
body = obj.body
body = body and tools.ustr(body) or ''
email_from = getattr(obj, 'email_from', False)
x_headers = {}
if message_id:
x_headers['References'] = "%s" % (message_id)
if obj.html:
subtype = 'html'
flag = email_message_obj.schedule_with_attach(cr, uid,
email_from,
emails,
obj.subject,
body,
model='crm.send.mail',
email_cc=email_cc,
attach=attach,
subtype=subtype,
reply_to=obj.reply_to,
openobject_id=str(case.id),
x_headers=x_headers
)
if not flag:
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
msg_dict = {'new': 'Send', 'reply': 'Reply', 'forward': 'Forward'}
case_pool.history(cr, uid, [case], _(msg_dict[context.get('mail', 'new')]), history=True, \
email=obj.email_to, details=body, \
subject=obj.subject, email_from=email_from, \
email_cc=', '.join(email_cc), message_id=message_id, \
references=ref_id or message_id, attach=attach)
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])
elif obj.state in ['cancel', 'open', 'pending']:
act = 'case_' + obj.state
getattr(case_pool, act)(cr, uid, [case.id])
return {'type': 'ir.actions.act_window_close'}
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
"""
if context is None:
context = {}
if not context.get('active_model'):
raise osv.except_osv(_('Error'), _('Can not send mail!'))
res = super(crm_send_new_email, self).default_get(cr, uid, fields, context=context)
if context.get('mail') == 'reply':
res.update(self.get_reply_defaults(cr, uid, fields, context=context))
return res
model = context.get('active_model')
mod_obj = self.pool.get(model)
res_id = context and context.get('active_ids', []) or []
user_obj = self.pool.get('res.users')
user_mail_from = user_obj._get_email_from(cr, uid, [uid], context=context)[uid]
for case in mod_obj.browse(cr, uid, res_id, context=context):
if 'email_to' in fields:
res.update({'email_to': case.email_from and tools.ustr(case.email_from) or ''})
if 'email_from' in fields:
res.update({'email_from': user_mail_from and tools.ustr(user_mail_from) or ''})
if 'reply_to' in fields:
if hasattr(case, 'section_id'):
res.update({'reply_to': case.section_id and case.section_id.reply_to or False})
if 'subject' in fields:
res.update({'subject': tools.ustr(context.get('subject', case.name) or '')})
if 'email_cc' in fields:
res.update({'email_cc': tools.ustr(case.email_cc or '')})
if 'body' in fields:
res.update({'body': u'\n'+(tools.ustr(case.user_id.signature or ''))})
if 'state' in fields:
res.update({'state': u'pending'})
return res
def get_reply_defaults(self, cr, uid, fields, context=None):
"""
This function gets default values for reply mail
"""
hist_obj = self.pool.get('email.message')
res_ids = context and context.get('active_ids', []) or []
user_obj = self.pool.get('res.users')
user_mail_from = user_obj._get_email_from(cr, uid, [uid], context=context)[uid]
include_original = context and context.get('include_original', False) or False
res = {}
for hist in hist_obj.browse(cr, uid, res_ids, context=context):
model = hist.model
# In the case where the crm.case does not exist in the database
if not model:
return {'type': 'ir.actions.act_window_close'}
model_pool = self.pool.get(model)
res_id = hist.res_id
case = model_pool.browse(cr, uid, res_id)
if 'email_to' in fields:
res.update({'email_to': case.email_from and tools.ustr(case.email_from) or False})
if 'email_from' in fields:
res.update({'email_from': user_mail_from and tools.ustr(user_mail_from) or False})
signature = u'\n' + (tools.ustr(case.user_id.signature or '')) + u'\n'
original = [signature]
if include_original == True and 'body' in fields:
header = u'-------- Original Message --------'
sender = u'From: %s' %(tools.ustr(hist.email_from or ''))
to = u'To: %s' % (tools.ustr(hist.email_to or ''))
sentdate = u'Date: %s' % (tools.ustr(hist.date))
desc = u'\n%s'%(tools.ustr(hist.description))
original = [signature, header, sender, to, sentdate, desc]
res['body']= u'\n' + u'\n'.join(original)
if 'subject' in fields:
res.update({u'subject': u'Re: %s' %(tools.ustr(hist.name or ''))})
if 'email_cc' in fields:
email_cc = (case.email_cc and tools.ustr(case.email_cc) + ', ' or '') + (hist.email_cc or '')
res.update({'email_cc': email_cc})
if 'reply_to' in fields:
if hasattr(case, 'section_id'):
res.update({'reply_to': case.section_id.reply_to or ''})
if 'state' in fields:
res['state'] = u'pending'
return res
def view_init(self, cr, uid, fields_list, context=None):
"""
This function checks for precondition before wizard executes
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
"""
if context is None:
context = {}
if not context.get('active_model'):
raise osv.except_osv(_('Error'), _('Can not send mail!'))
return True
crm_send_new_email()
-104
View File
@@ -1,104 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Send New Mail view -->
<record model="ir.ui.view" id="crm_send_new_mail_view">
<field name="name">crm.new.send.mail.form</field>
<field name="model">crm.send.mail</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Send Mail" col="4">
<group colspan="4" col="2">
<field name="email_from"/>
<field name="reply_to"/>
<field name="email_to" />
<field name="email_cc"/>
<field name="subject"/>
<field name="html"/>
</group>
<notebook colspan="6">
<page string="Message">
<field name="body" nolabel="1" colspan="4" default_focus="1"/>
</page>
<page string="Attachments">
<field name="attachment_ids" colspan="4" nolabel="1">
<form string="Attachment">
<field name="binary" filename="name" />
<field name="name" />
</form>
<tree string="Attachments">
<field name="name" />
</tree>
</field>
</page>
</notebook>
<separator string="" colspan="6"/>
<group colspan="6" col="4" >
<field name="state" />
<button string="_Cancel" icon="gtk-close" special="cancel" />
<button name="action_send" type="object" string="_Send" icon="gtk-go-forward" />
</group>
</form>
</field>
</record>
<!-- Send New Mail action -->
<record model="ir.actions.act_window" id="action_crm_send_mail">
<field name="name">Send Mail</field>
<field name="res_model">crm.send.mail</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="crm_send_new_mail_view"/>
<field name="target">new</field>
</record>
<!-- Reply to Mail view -->
<record model="ir.ui.view" id="crm_reply_mail_view">
<field name="name">crm.mail.reply.form</field>
<field name="model">crm.send.mail</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Reply to last Mail" col="2">
<field name="email_from" />
<field name="email_to" />
<field name="email_cc" />
<field name="subject" />
<field name="attachment_ids" colspan="4" nolabel="1">
<form string="Attachment">
<field name="binary" filename="name" />
<field name="name" />
</form>
<tree string="Attachments">
<field name="name" />
</tree>
</field>
<separator string="" colspan="4"/>
<field name="body" nolabel="1" colspan="4"/>
<separator string=" " colspan="4"/>
<group colspan="4" col="3" >
<label string=" " />
<button string="_Cancel" icon="gtk-close" special="cancel" />
<button name="action_send" type="object" string="_Send Reply" icon="gtk-go-forward" />
</group>
</form>
</field>
</record>
<!-- Reply to Mail action -->
<record model="ir.actions.act_window" id="action_crm_reply_mail">
<field name="name">Reply to last Mail</field>
<field name="res_model">crm.send.mail</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="crm_reply_mail_view"/>
<field name="target">new</field>
</record>
</data>
</openerp>
+9 -2
View File
@@ -31,6 +31,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -43,8 +50,8 @@ class email_compose_message(osv.osv_memory):
'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,
'res_id': resource_id or False,
'model': model,
'res_id': resource_id,
})
if hasattr(data, 'section_id'):
result.update({'reply_to' : data.section_id and data.section_id.reply_to or False})
@@ -27,6 +27,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -39,8 +46,8 @@ class email_compose_message(osv.osv_memory):
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
'body' : '\n' + (tools.ustr(data.user_id.signature or '')),
'email_cc' : tools.ustr(data.email_cc or ''),
'model': model or False,
'res_id': resource_id or False,
'model': model,
'res_id': resource_id,
})
return result
-1
View File
@@ -42,7 +42,6 @@ for leads, the action will be added to the right side panel of the Lead form.
"update_xml": [
'wizard/email_template_preview_view.xml',
'email_template_view.xml',
'wizard/email_template_send_wizard_view.xml',
'wizard/email_compose_message_view.xml',
'security/ir.model.access.csv'
],
+41 -56
View File
@@ -84,14 +84,6 @@ class email_template(osv.osv):
help="The subject of email."
" Placeholders can be used here.",
translate=True),
# 'description':fields.text(
# 'Standard Body (Text)',
# help="The text version of the mail",
# translate=True),
# 'body_html':fields.text(
# 'Body (Text-Web Client Only)',
# help="The text version of the mail",
# translate=True),
'user_signature':fields.boolean(
'Signature',
help="the signature from the User details"
@@ -352,49 +344,50 @@ class email_template(osv.osv):
"""
if context is None:
context = {}
smtp_pool = self.pool.get('ir.mail_server')
email_message_pool = self.pool.get('email.message')
values = {
'subject': False,
'body': False,
'email_to': False,
'email_cc': False,
'email_bcc': False,
'reply_to': False,
'auto_delete': False,
'model': False,
'res_id': False,
'smtp_server_id': False,
'attachment': False,
'attachment_ids': False,
}
if not template_id:
return values
report_xml_pool = self.pool.get('ir.actions.report.xml')
template = self.get_email_template(cr, uid, template_id, record_id, context)
smtp_server_id = context.get('smtp_server_id', False)
if not smtp_server_id and template.smtp_server_id:
smtp_server_id = template.smtp_server_id.id
else:
smtp_ids = smtp_pool.search(cr, uid, [])
smtp_server_id = smtp_ids and smtp_ids[0]
smtp_server = smtp_pool.browse(cr, uid, smtp_server_id, context=context)
# determine name of sender, either it is specified in email_id
def _get_template_value(field):
if context.get('mass_mail',False): # Mass Mail: Gets original template values for multiple email change
return getattr(template, field)
else:
return self.get_template_value(cr, uid, getattr(template, field), template.model, record_id, context=context)
email_id = smtp_server.email_id.strip()
email_from = re.findall(r'([^ ,<@]+@[^> ,]+)', email_id)[0]
if email_from != email_id:
email_from = smtp_server.email_id
else:
email_from = tools.ustr(smtp_server.name) + "<" + tools.ustr(email_id) + ">"
model = template.model_id.model
#Use signatures if allowed
body = _get_template_value('body')
if template.user_signature:
signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
body += '\n' + signature
values = {
'email_from': email_from,
'email_to': self.get_template_value(cr, uid, template.email_to, model, record_id, context),
'email_cc': self.get_template_value(cr, uid, template.email_cc, model, record_id, context),
'email_bcc': self.get_template_value(cr, uid, template.email_bcc, model, record_id, context),
'reply_to': self.get_template_value(cr, uid, template.reply_to, model, record_id, context),
'subject': self.get_template_value(cr, uid, template.subject, model, record_id, context),
'body': self.get_template_value(cr, uid, template.description, model, record_id, context),
'auto_delete': self.get_template_value(cr, uid, template.auto_delete, model, record_id, context),
'smtp_server_id' : template.smtp_server_id.id,
'body' : body,
'email_to' : _get_template_value('email_to') or False,
'email_cc' : _get_template_value('email_cc') or False,
'email_bcc' : _get_template_value('email_bcc') or False,
'reply_to' : _get_template_value('reply_to') or False,
'subject' : _get_template_value('subject') or False,
'auto_delete': template.auto_delete,
'model' : template.model or False,
'res_id' : record_id or False,
#'body_html': self.get_template_value(cr, uid, template.body_html, model, record_id, context),
}
#Use signatures if allowed
if template.user_signature:
sign = self.pool.get('res.users').read(cr, uid, uid, ['signature'], context)['signature']
if values['description']:
values['description'] += '\n\n' + sign
#if values['body_html']:
# values['body_html'] += sign
attachment = []
attachment = {}
# Add report as a Document
if template.report_template:
report_name = template.report_name
@@ -412,22 +405,14 @@ class email_template(osv.osv):
if not report_name:
report_name = reportname
report_name = report_name + "." + format
attachment.append((report_name, result))
attachment[report_name] = result
# Add document attachments
for attach in template.attachment_ids:
#attach = attahcment_obj.browse(cr, uid, attachment_id, context)
attachment.append((attach.datas_fname, attach.datas))
#Send emails
context.update({'notemplate':True})
email_id = email_message_pool.schedule_with_attach(cr, uid, values.get('email_from'), values.get('email_to'), values.get('name'),
values.get('description'), model=model, email_cc=values.get('email_cc'), email_bcc=values.get('email_bcc'),
reply_to=values.get('reply_to'), attach=attachment, message_id=values.get('message_id'), openobject_id=record_id,
debug=True, subtype='plain', x_headers={}, priority='3', smtp_server_id=smtp_server.id, auto_delete=values.get('auto_delete'), context=context)
email_message_pool.write(cr, uid, email_id, {'template_id': context.get('template_id',template.id)})
return email_id
attachment[attach.datas_fname] = attach.datas
values['attachment'] = attachment
return values
email_template()
+3 -1
View File
@@ -47,7 +47,9 @@ def get_value(cr, uid, message=None, model=None, record_id=False, context=None):
}
templ = MakoTemplate(message, input_encoding='utf-8')
reply = MakoTemplate(message).render_unicode(object=record, peobject=record, env=env, format_exceptions=True)
return reply or False
if reply == 'False':
reply = ''
return reply
except Exception:
logging.exception("can't render %r", message)
return u""
-1
View File
@@ -20,6 +20,5 @@
#
##############################################################################
import email_template_preview
import email_template_send_wizard
import email_compose_message
@@ -23,45 +23,12 @@ from osv import osv
from osv import fields
import tools
from tools.translate import _
import binascii
class email_compose_message(osv.osv_memory):
_name = 'email.compose.message'
_inherit = 'email.compose.message'
def get_template_data(self, cr, uid, template_id, context=None):
result = {}
if not template_id:
return result
if context is None:
context = {}
template_pool = self.pool.get('email.template')
resource_id = context.get('active_id')
template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context)
def _get_template_value(field):
if context.get('mass_mail',False): # Multiple Mail: Gets original template values for multiple email change
return getattr(template, field)
else
return self.get_template_value(cr, uid, getattr(template, field), template.model, resource_id, context=context)
result.update({
'template_id' : template.id,
'smtp_server_id' : template.smtp_server_id.id,
'body' : _get_template_value('body') or False,
'subject' : _get_template_value('subject') or False,
'attachment_ids' : template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] or [],
'res_id' : resource_id or False,
'email_to' : _get_template_value('email_to') or False,
'email_cc' : _get_template_value('email_cc') or False,
'email_bcc' : _get_template_value('email_bcc') or False,
'reply_to' : _get_template_value('reply_to') or False,
'model' : template.model or False,
})
return result
def _get_templates(self, cr, uid, context=None):
"""
Return Email Template of particular Model.
@@ -90,13 +57,27 @@ class email_compose_message(osv.osv_memory):
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, template_id, context=None):
def on_change_template(self, cr, uid, ids, template_id, context=None):
if context is None:
context = {}
resource_id = context.get('active_id', False)
return self.get_template_data(cr, uid, resource_id, template_id, context)
att_ids = []
res_id = context.get('active_id', False)
values = self.pool.get('email.template').generate_email(cr, uid, template_id, res_id, context=context)
if values['attachment']:
attachment = values['attachment']
attachment_obj = self.pool.get('ir.attachment')
for fname, fcontent in attachment.items():
data_attach = {
'name': fname,
'datas': binascii.b2a_base64(str(fcontent)),
'datas_fname': fname,
'description': _('Mail attachment'),
'res_model' : self._name,
'res_id' : ids and ids[0] or False
}
att_ids.append(attachment_obj.create(cr, uid, data_attach))
values['attachment_ids'] = att_ids
return {'value': values}
email_compose_message()
@@ -10,7 +10,7 @@
<field name="arch" type="xml">
<field name="model" position="after">
<field name="template_id" colspan="4"
on_change="on_change_template(model, template_id, context)"/>
on_change="on_change_template(template_id, context)"/>
</field>
</field>
</record>
@@ -46,8 +46,9 @@ class email_template_preview(osv.osv_memory):
template = template_pool.browse(cr, uid, int(template_id), context=context)
template_object = template.model_id
model = self.pool.get(template_object.model)
record_ids = model.search(cr, uid, [], 0, 20, 'id', context=context)
record_ids = model.search(cr, uid, [], 0, 10, 'id', context=context)
default_id = context.get('default_res_id')
if default_id and default_id not in record_ids:
record_ids.insert(0, default_id)
@@ -1,166 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
from osv import osv, fields
import netsvc
from tools.translate import _
class email_template_send_wizard(osv.osv_memory):
_name = 'email_template.send.wizard'
_inherit = 'email.template'
_description = 'This is the wizard for sending mail'
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
result = super(email_template_send_wizard, self).default_get(cr, uid, fields, context=context)
template_pool = self.pool.get('email.template')
model_pool = self.pool.get('ir.model')
template_id=context.get('template_id', False)
template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context)
def _get_template_value(field):
if not template:
return False
if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets original template values for multiple email change
return getattr(template, field)
else: # Simple Mail: Gets computed template values
return self.get_template_value(cr, uid, getattr(template, field), template.model, context.get('active_id'), context)
if 'user_signature' in fields:
result['user_signature'] = template.user_signature
if 'report_template' in fields:
result['report_template'] = template.report_template and template.report_template.id or False
if 'template_id' in fields:
result['template_id'] = template.id
if 'smtp_server_id' in fields:
result['smtp_server_id'] = template.smtp_server_id.id
if 'attachment_ids' in fields:
result['attachment_ids'] = template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids']
if 'requested' in fields:
result['requested'] = len(context.get('src_rec_ids',''))
if 'state' in fields:
result['state'] = len(context.get('src_rec_ids','')) > 1 and 'multi' or 'single'
if 'model_id' in fields:
result['model_id'] = model_pool.search(cr, uid, [('model','=',context.get('src_model'))],context=context)[0]
if 'res_id' in fields:
result['res_id'] = context['active_id']
if 'email_to' in fields:
result['email_to'] = _get_template_value('email_to')
if 'email_cc' in fields:
result['email_cc'] = _get_template_value('email_cc')
if 'email_bcc' in fields:
result['email_bcc'] = _get_template_value('email_bcc')
if 'subject' in fields:
result['subject'] = _get_template_value('subject')
if 'body' in fields:
result['body'] = _get_template_value('description')
#if 'body_html' in fields:
# result['body_html'] = _get_template_value('body_html')
if 'reply_to' in fields:
result['reply_to'] = _get_template_value('reply_to')
if 'report_name' in fields:
result['report_name'] = _get_template_value('report_name')
return result
_columns = {
'requested':fields.integer('No of requested Mails',readonly=True),
'generated':fields.integer('No of generated Mails',readonly=True),
'full_success':fields.boolean('Complete Success',readonly=True),
'attachment_ids': fields.many2many('ir.attachment','send_wizard_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'),
'state':fields.selection([
('single','Simple Mail Wizard Step 1'),
('multi','Multiple Mail Wizard Step 1'),
('done','Wizard Complete')
],'State',readonly=True),
}
_defaults = {
}
#def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
# if context is None:
# context = {}
# result = super(email_template_send_wizard, self).fields_get(cr, uid, fields, context, write_access)
# if 'attachment_ids' in result and 'src_model' in context:
# result['attachment_ids']['domain'] = [('res_model','=',context['src_model']),('res_id','=',context['active_id'])]
# return result
def send_mail(self, cr, uid, ids, context=None):
if context is None:
context = {}
mailid = self.save_to_mailbox(cr, uid, ids, context)
return {'type': 'ir.actions.act_window_close'}
def get_generated(self, cr, uid, ids=None, context=None):
if ids is None:
ids = []
if context is None:
context = {}
logger = netsvc.Logger()
if context.get('src_rec_ids'):
#Means there are multiple items selected for email.
mail_ids = self.save_to_mailbox(cr, uid, ids, context)
if mail_ids:
logger.notifyChannel("email-template", netsvc.LOG_INFO, _("Emails for multiple items saved in outbox."))
self.write(cr, uid, ids, {
'generated':len(mail_ids),
'state':'done'
}, context)
else:
raise osv.except_osv(_("Email Template"),_("Email sending failed for one or more objects."))
return True
def save_to_mailbox(self, cr, uid, ids, context=None):
#def get_end_value(id, value):
# if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets value from the template
# return self.get_value(cr, uid, template, value, context, id)
# else:
# return value
email_ids = []
for template in self.browse(cr, uid, ids, context=context):
for record_id in context.get('src_rec_ids',[]):
email_id = self.generate_email(cr, uid, template.id, record_id, context)
email_ids.append(email_id)
return email_ids
email_template_send_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,62 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="email_template_send_wizard_form">
<field name="name">email_template.send.wizard.form</field>
<field name="model">email_template.send.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Send Email Wizard">
<group col="4" colspan="4">
<field name="smtp_server_id" widget="selection" required="1" colspan="4"/>
</group>
<group col="4" colspan="4">
<group col="6" colspan="4">
<field name="email_to" colspan="4"/>
<field name="email_cc" colspan="4"/>
<field name="email_bcc" colspan="4"/>
<field name="subject" colspan="4" attrs="{'required':[('state','=','single')]}"/>
<field name="report_name" colspan="4"/>
<field name="user_signature" colspan="4"/>
</group>
<separator string="" colspan="4"/>
<notebook colspan="4">
<page string="Body">
<field name="description" colspan="4" nolabel="1"/>
</page>
<!-- <page string="Body (HTML)">
<field name="body_html" colspan="4" nolabel="1"/>
</page> -->
<page string="Attachments">
<label string="Add here all attachments of the current document you want to include in the Email." colspan="4"/>
<field name="attachment_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
</group>
<field name="state" invisible="1"/>
<group col="4" colspan="4" attrs="{'invisible':[('state','=','single')]}">
<field name="requested"/>
<field name="generated"/>
<newline/>
<label string="After clicking Send All, emails will be sent to outbox and cleared in next Send/Recieve" colspan="4"/>
<label string="Tip: Multiple emails are sent in the same language (the first one is proposed). We suggest you send emails in groups according to language." colspan="4"/>
<newline/>
</group>
<label string="" colspan="2"/>
<group col="4" colspan="2" attrs="{'invisible':[('state','=','single')]}">
<button icon="gtk-cancel" special="cancel" string="Discard" states="multi"/>
<button icon="gtk-ok" name="get_generated" string="Send All" type="object" states="multi"/>
<button icon="gtk-ok" special="cancel" string="Close" states="done"/>
</group>
<group col="4" colspan="2" attrs="{'invisible':[('state','!=','single')]}">
<button icon="gtk-cancel" special="cancel" string="Discard"/>
<button icon="gtk-ok" name="send_mail" string="Send now" type="object"/>
</group>
</form>
</field>
</record>
</data>
</openerp>
+9 -2
View File
@@ -27,6 +27,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -39,8 +46,8 @@ class email_compose_message(osv.osv_memory):
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
'body' : '\n' + (tools.ustr(data.user_id.signature or '')),
'email_cc' : tools.ustr(data.email_cc or ''),
'model': model or False,
'res_id': resource_id or False,
'model': model,
'res_id': resource_id,
})
return result
@@ -28,6 +28,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -42,6 +49,7 @@ class email_compose_message(osv.osv_memory):
'subject': _("Reminder to fill up Survey"),
'body': msg,
'res_id': resource_id,
'model': model,
'email_cc': False,
'email_bcc': False,
'reply_to': False,
@@ -28,6 +28,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -40,8 +47,8 @@ class email_compose_message(osv.osv_memory):
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
'body' : '\n' + (tools.ustr(data.user_id.signature or '')),
'email_cc' : tools.ustr(data.email_cc or ''),
'model': model or False,
'res_id': resource_id or False,
'model': model,
'res_id': resource_id,
})
return result
+14
View File
@@ -94,6 +94,7 @@ class email_message_common(osv.osv_memory):
_rec_name = 'subject'
_sql_constraints = []
email_message_common()
class email_message(osv.osv):
@@ -105,6 +106,19 @@ class email_message(osv.osv):
_description = 'Email Message'
_order = 'date desc'
def _check_email_recipients(self, cr, uid, ids, context=None):
'''
checks email_to, email_cc, email_bcc
'''
for message in self.browse(cr, uid, ids, context=context):
if not (message.email_to or message.email_cc or message.email_bcc) and message.history:
return False
return True
_constraints = [
(_check_email_recipients, 'No recipients were specified. Please enter a recipient!', ['email_to', 'email_cc', 'email_bcc']),
]
def open_document(self, cr, uid, ids, context=None):
""" To Open Document
@param self: The object pointer.
+30 -18
View File
@@ -29,6 +29,13 @@ class email_compose_message(osv.osv_memory):
_description = 'This is the wizard for Compose E-mail'
def default_get(self, cr, uid, fields, context=None):
"""
Returns default values for fields
@param fields: list of fields, for which default values are required to be read
@param context: context arguments, like lang, time zone
@return: Returns a dictionary that contains default values for fields
"""
if context is None:
context = {}
result = super(email_compose_message, self).default_get(cr, uid, fields, context=context)
@@ -101,13 +108,17 @@ 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
'filter_id': fields.many2one('ir.filters', 'Filters'),
}
def get_value(self, cr, uid, model, res_id, context=None):
return {}
def get_message_data(self, cr, uid, message_id, context=None):
'''
Called by default_get() to get message detail
@param message_id: Id of the email message
'''
if context is None:
context = {}
result = {}
@@ -115,11 +126,7 @@ class email_compose_message(osv.osv_memory):
if message_id:
message_data = message_pool.browse(cr, uid, message_id, context)
subject = tools.ustr(message_data and message_data.subject or '')
if context.get('mail','') == 'reply':
subject = "Re :- " + subject
description = message_data and message_data.body or ''
message_body = False
if context.get('mail','') == 'reply':
header = '-------- Original Message --------'
sender = 'From: %s' % tools.ustr(message_data.email_from or '')
@@ -127,6 +134,8 @@ class email_compose_message(osv.osv_memory):
sentdate = 'Date: %s' % message_data.date
desc = '\n > \t %s' % tools.ustr(description.replace('\n', "\n > \t") or '')
description = '\n'.join([header, sender, email_to, sentdate, desc])
if not subject.startswith('Re: '):
subject = "Re: " + subject
result.update({
'body' : description,
@@ -151,14 +160,17 @@ class email_compose_message(osv.osv_memory):
return result
def send_mail(self, cr, uid, ids, context=None):
'''
Sends the email
'''
if context is None:
context = {}
record = self.browse(cr, uid, ids[0], context=context)
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
@@ -169,7 +181,7 @@ class email_compose_message(osv.osv_memory):
references = mail.references and mail.references + "," + mail.message_id or mail.message_id
else:
message_id = mail.message_id
# Mass mailing
if context.get('mass_mail', False):
if context['active_ids'] and context['active_model']:
@@ -177,19 +189,21 @@ class email_compose_message(osv.osv_memory):
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)
active_model = mail.model
active_model_pool = self.pool.get(active_model)
active_ids = active_model_pool.search(cr, uid, eval(mail.filter_id.domain), context=eval(mail.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)
email_bcc = self.get_template_value(cr, uid, mail.email_bcc, 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,
email_id = email_message_pool.schedule_with_attach(cr, uid, email_from, email_to, subject, body,
model=mail.model, email_cc=email_cc, email_bcc=email_bcc, reply_to=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)
@@ -200,15 +214,13 @@ class email_compose_message(osv.osv_memory):
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)
auto_delete=mail.auto_delete, context=context)
email_ids.append(email_id)
return email_ids
#return {'type': 'ir.actions.act_window_close'}
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()
@@ -27,6 +27,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -27,6 +27,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -39,8 +46,8 @@ class email_compose_message(osv.osv_memory):
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
'body' : '\n' + (tools.ustr(data.user_id.signature or '')),
'email_cc' : tools.ustr(data.email_cc or ''),
'model': model or False,
'res_id': resource_id or False,
'model': model,
'res_id': resource_id,
})
return result
@@ -27,6 +27,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
@@ -38,8 +45,8 @@ class email_compose_message(osv.osv_memory):
'email_to' : data.user_id.user_email or False,
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
'body' : '\n' + (tools.ustr(data.user_id.signature or '')),
'model': model or False,
'res_id': resource_id or False,
'model': model,
'res_id': resource_id,
})
return result
@@ -27,6 +27,13 @@ class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
'''
To get values of the resource_id for the model
@param model: Object
@param resource_id: id of a record for which values to be read
@return: Returns a dictionary
'''
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)