[IMP] crm: send mail wizard
bzr revid: hmo@tinyerp.com-20100322103341-eyn3c15vaz90hms2
This commit is contained in:
parent
91619c0150
commit
426074796c
|
@ -61,6 +61,7 @@ between mails and Open ERP.""",
|
|||
],
|
||||
|
||||
'update_xml': [
|
||||
'wizard/crm_send_email_view.xml',
|
||||
'crm_wizard.xml',
|
||||
'crm_view.xml',
|
||||
'crm_action_rule_view.xml',
|
||||
|
|
|
@ -363,6 +363,8 @@ class crm_case(osv.osv):
|
|||
data['email'] = email or \
|
||||
(case.user_id and case.user_id.address_id and \
|
||||
case.user_id.address_id.email) or False
|
||||
data['email_from'] = (case.user_id and case.user_id.address_id and \
|
||||
case.user_id.address_id.email) or tools.config.get('email_from',False)
|
||||
res = obj.create(cr, uid, data, context)
|
||||
return True
|
||||
_history = __history
|
||||
|
@ -549,6 +551,7 @@ class crm_case_history(osv.osv):
|
|||
'description': fields.text('Description'),
|
||||
'note': fields.function(_note_get, method=True, string="Description", type="text"),
|
||||
'email': fields.char('Email', size=84),
|
||||
'email_from' : fields.char('From Email', size=84),
|
||||
'log_id': fields.many2one('crm.case.log','Log',ondelete='cascade'),
|
||||
}
|
||||
crm_case_history()
|
||||
|
|
|
@ -150,22 +150,29 @@
|
|||
<field name="date"/>
|
||||
<field name="email"/>
|
||||
<field name="canal_id"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.claim'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.claim'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</group>
|
||||
|
|
|
@ -149,21 +149,28 @@
|
|||
<field name="email"/>
|
||||
<field name="canal_id"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.fundraising'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.fundraising'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
|
@ -97,21 +97,28 @@
|
|||
<field name="email"/>
|
||||
<field name="canal_id"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.helpdesk'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.helpdesk'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
|
@ -119,24 +119,28 @@
|
|||
<field name="email"/>
|
||||
<field name="canal_id"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-go-forward" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(crm.wizard_crm_new_send_mail)d"
|
||||
context="{'mail':'new'}" icon="gtk-go-forward"
|
||||
type="action" />
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.lead'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.lead'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
<page string="Extra Info" groups="base.group_extended">
|
||||
<group colspan="2" col="2">
|
||||
|
|
|
@ -139,21 +139,28 @@
|
|||
<field name="email"/>
|
||||
<field name="canal_id"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.opportunity'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.opportunity'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
<openerp>
|
||||
<data>
|
||||
<!-- <menuitem icon="terp-crm" id="menu_crm" name="CRM & SRM"/>-->
|
||||
<menuitem id="menu_crm_configuration" name="Cases" parent="base.menu_base_config" sequence="0"/>
|
||||
|
||||
<wizard id="wizard_crm_send_mail" model="crm.case.history" name="crm.send.mail" string="Send Mail" menu="False"/>
|
||||
<wizard id="wizard_crm_new_send_mail" model="crm.case" name="crm.new.send.mail" string="Send New Mail" menu="False"/>
|
||||
|
||||
<menuitem id="menu_crm_configuration" name="Cases" parent="base.menu_base_config" sequence="0"/>
|
||||
<!-- Case Sections -->
|
||||
<record id="crm_case_section_view_form" model="ir.ui.view">
|
||||
<field name="name">crm.case.section.form</field>
|
||||
|
@ -351,7 +347,11 @@
|
|||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.case'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
|
@ -359,7 +359,10 @@
|
|||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.case'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
|
@ -206,7 +206,7 @@ class email_parser(object):
|
|||
# 'file_name':'file data',
|
||||
# }
|
||||
# }
|
||||
# #
|
||||
|
||||
def msg_body_get(self, msg):
|
||||
message = {};
|
||||
message['body'] = '';
|
||||
|
@ -215,7 +215,7 @@ class email_parser(object):
|
|||
counter = 1;
|
||||
def replace(match):
|
||||
return ''
|
||||
|
||||
|
||||
for part in msg.walk():
|
||||
if part.get_content_maintype() == 'multipart':
|
||||
continue
|
||||
|
@ -264,7 +264,7 @@ class email_parser(object):
|
|||
body['body'] = body_data
|
||||
|
||||
data = {
|
||||
'description': body['body'],
|
||||
# 'description': body['body'],
|
||||
}
|
||||
act = 'case_pending'
|
||||
if 'state' in actions:
|
||||
|
@ -291,7 +291,7 @@ class email_parser(object):
|
|||
|
||||
self.rpc(self.model, act, [id])
|
||||
self.rpc(self.model, 'write', [id], data)
|
||||
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
|
||||
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], body['body'])
|
||||
return id
|
||||
|
||||
def msg_send(self, msg, emails, priority=None):
|
||||
|
@ -318,11 +318,11 @@ class email_parser(object):
|
|||
body = message['body']
|
||||
act = 'case_open'
|
||||
self.rpc(self.model, act, [id])
|
||||
body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n')))
|
||||
data = {
|
||||
'description':body,
|
||||
}
|
||||
self.rpc(self.model, 'write', [id], data)
|
||||
#body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n')))
|
||||
#data = {
|
||||
# 'description':body,
|
||||
#}
|
||||
#self.rpc(self.model, 'write', [id], data)
|
||||
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
|
||||
return id
|
||||
|
||||
|
@ -375,7 +375,7 @@ class email_parser(object):
|
|||
|
||||
if __name__ == '__main__':
|
||||
import sys, optparse
|
||||
parser = optparse.OptionParser( usage='usage: %prog [options]', version='%prog v1.0')
|
||||
parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.0')
|
||||
group = optparse.OptionGroup(parser, "Note",
|
||||
"This program parse a mail from standard input and communicate "
|
||||
"with the Open ERP server for case management in the CRM module.")
|
||||
|
|
|
@ -23,8 +23,7 @@ import crm_opportunity_wizard
|
|||
import crm_lead_wizard
|
||||
import crm_phonecall_wizard
|
||||
|
||||
import wizard_crm_send_email
|
||||
import wizard_crm_new_send_email
|
||||
import crm_send_email
|
||||
import wizard_history_event
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,226 @@
|
|||
# -*- 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 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
|
||||
from tools.translate import _
|
||||
import base64
|
||||
import tools
|
||||
|
||||
class crm_send_new_email(osv.osv_memory):
|
||||
""" Sends new email for the case"""
|
||||
_name = "crm.send.mail"
|
||||
_description = "Case Send new email"
|
||||
|
||||
_columns = {
|
||||
'to' : fields.char('To', size=64, required=True),
|
||||
'cc' : fields.char('CC', size=128),
|
||||
'subject': fields.char('Subject', size=128, required=True),
|
||||
'text': fields.text('Message', required=True),
|
||||
'state': fields.selection([('done', 'Done'), ('pending', 'Pending'), ('unchanged', 'Unchanged')], string='State', required=True),
|
||||
'doc1': fields.binary("Attachment1"),
|
||||
'doc2': fields.binary("Attachment2"),
|
||||
'doc3': fields.binary("Attachment3"),
|
||||
}
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Closes Phonecall to Opportunity form
|
||||
@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 ids: List of Phonecall to Opportunity's IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
return {'type':'ir.actions.act_window_close'}
|
||||
|
||||
def action_send(self, cr, uid, ids, context=None):
|
||||
""" This sends an email to ALL the addresses of the selected partners.
|
||||
@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 ids: List of Phonecall to Opportunity's IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
if not context.get('model'):
|
||||
raise osv.except_osv(_('Error'), _('Can not send mail!'))
|
||||
|
||||
model = context.get('model')
|
||||
case_pool = self.pool.get(model)
|
||||
res_id = context and context.get('active_id', False) or False
|
||||
|
||||
for data in self.read(cr, uid, ids, context=context):
|
||||
attach = filter(lambda x: x, [data['doc1'], data['doc2'], data['doc3']])
|
||||
attach = map(lambda x: x and ('Attachment'+str(attach.index(x)+1), base64.decodestring(x)), attach)
|
||||
|
||||
if context.get('mail', 'new') == 'new':
|
||||
case = case_pool.browse(cr, uid, res_id)
|
||||
else:
|
||||
hist_obj = self.pool.get('crm.case.history')
|
||||
hist = hist_obj.browse(cr, uid, res_id)
|
||||
model = hist.log_id.model_id.model
|
||||
model_pool = self.pool.get(model)
|
||||
case = model_pool.browse(cr, uid, hist.log_id.res_id)
|
||||
emails = [data['to']] + (data['cc'] or '').split(',')
|
||||
emails = filter(None, emails)
|
||||
body = data['text']
|
||||
|
||||
if case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature)
|
||||
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['to'], details=body)
|
||||
email_from = (case.user_id and case.user_id.address_id and \
|
||||
case.user_id.address_id.email) or tools.config.get('email_from',False)
|
||||
flag = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
data['subject'],
|
||||
case_pool.format_body(body),
|
||||
attach=attach,
|
||||
reply_to=case.section_id.reply_to,
|
||||
openobject_id=str(case.id),
|
||||
)
|
||||
if flag:
|
||||
if data['state'] == 'unchanged':
|
||||
pass
|
||||
elif data['state'] == 'done':
|
||||
case_pool.case_close(cr, uid, [case.id])
|
||||
elif data['state'] == 'pending':
|
||||
case_pool.case_pending(cr, uid, [case.id])
|
||||
cr.commit()
|
||||
|
||||
# Commented because form does not close due to raise
|
||||
# raise osv.except_osv(_('Email!'), ("Email Successfully Sent"))
|
||||
# else:
|
||||
# raise osv.except_osv(_('Warning!'), _("Email not sent !"))
|
||||
return {}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
@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
|
||||
|
||||
@return : default values of fields.
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
if not context.get('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('model')
|
||||
mod_obj = self.pool.get(model)
|
||||
res_id = context and context.get('active_ids', []) or []
|
||||
|
||||
for case in mod_obj.browse(cr, uid, res_id):
|
||||
if 'to' in fields:
|
||||
res.update({'to': case.email_from})
|
||||
if 'subject' in fields:
|
||||
res.update({'subject': case.name})
|
||||
if 'cc' in fields:
|
||||
res.update({'cc': case.email_cc or ''})
|
||||
if 'text' in fields:
|
||||
res.update({'text': case.description or ''})
|
||||
if 'state' in fields:
|
||||
res.update({'state': 'pending'})
|
||||
return res
|
||||
|
||||
def get_reply_defaults(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values for reply mail
|
||||
@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
|
||||
|
||||
@return : default values of fields.
|
||||
"""
|
||||
hist_obj = self.pool.get('crm.case.history')
|
||||
res_ids = context and context.get('active_ids', []) or []
|
||||
res = {}
|
||||
for hist in hist_obj.browse(cr, uid, res_ids):
|
||||
model = hist.log_id.model_id.model
|
||||
model_pool = self.pool.get(model)
|
||||
case = model_pool.browse(cr, uid, hist.log_id.res_id)
|
||||
if 'to' in fields and hist.email:
|
||||
res.update({'to': hist.email})
|
||||
if 'text' in fields:
|
||||
header = '-------- Original Message --------'
|
||||
sender = 'From: %s' %(hist.email_from or tools.config.get('email_from',False))
|
||||
to = 'To: %s' % (hist.email)
|
||||
sentdate = 'Sent: %s' % (hist.date)
|
||||
desc = '\n%s'%(hist.description)
|
||||
original = [header, sender, to, sentdate, desc]
|
||||
original = '\n'.join(original)
|
||||
res.update({'text': '\n\n%s'%(original)})
|
||||
if 'subject' in fields:
|
||||
res.update({'subject': '[%s] %s' %(str(case.id), case.name or '')})
|
||||
#if 'state' in fields:
|
||||
# res.update({'state': '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 not context:
|
||||
context = {}
|
||||
|
||||
if not context.get('model'):
|
||||
raise osv.except_osv(_('Error'), _('Can not send mail!'))
|
||||
model = context.get('model')
|
||||
mod_obj = self.pool.get(model)
|
||||
if context.get('mail') == 'reply':
|
||||
return True
|
||||
if tools.config.get('email_from'):
|
||||
return True
|
||||
|
||||
for case in mod_obj.browse(cr, uid, context.get('active_ids', [])):
|
||||
if not case.user_id:
|
||||
raise osv.except_osv(_('Error'), _('You must define a responsible user for this case in order to use this action!'))
|
||||
if not case.user_id.address_id.email:
|
||||
raise osv.except_osv(_('Warning!'), _("Please specify user's email address !"))
|
||||
|
||||
return True
|
||||
|
||||
crm_send_new_email()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,83 @@
|
|||
<?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 New Mail" col="2">
|
||||
<field name="to" />
|
||||
<field name="cc" />
|
||||
<field name="subject" />
|
||||
<field name="doc1" />
|
||||
<field name="doc2" />
|
||||
<field name="doc3" />
|
||||
<separator string="" colspan="4"/>
|
||||
<field name="text" nolabel="1" colspan="4"/>
|
||||
<separator colspan="4" string="Set case state to" />
|
||||
<field name="state" />
|
||||
<separator string=" " colspan="4"/>
|
||||
<group colspan="4" col="3" >
|
||||
<label string=" " />
|
||||
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" 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 New 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="to" />
|
||||
<field name="cc" />
|
||||
<field name="subject" />
|
||||
<field name="doc1" />
|
||||
<field name="doc2" />
|
||||
<field name="doc3" />
|
||||
<separator string="" colspan="4"/>
|
||||
<field name="text" nolabel="1" colspan="4"/>
|
||||
<separator string=" " colspan="4"/>
|
||||
<group colspan="4" col="3" >
|
||||
<label string=" " />
|
||||
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" 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>
|
|
@ -1,135 +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 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 mx.DateTime import now
|
||||
|
||||
import wizard
|
||||
import netsvc
|
||||
import ir
|
||||
import pooler
|
||||
import tools
|
||||
import base64
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
email_send_form = '''<?xml version="1.0"?>
|
||||
<form string="Mass Mailing">
|
||||
<field name="to"/>
|
||||
<newline/>
|
||||
<field name="cc"/>
|
||||
<newline/>
|
||||
<field name="subject"/>
|
||||
<newline/>
|
||||
<field name="text" />
|
||||
<newline/>
|
||||
<field name="doc1" />
|
||||
<newline/>
|
||||
<field name="doc2" />
|
||||
<newline/>
|
||||
<field name="doc3" />
|
||||
<separator colspan="4" string="Set case state to"/>
|
||||
<newline/>
|
||||
<field name="state" />
|
||||
</form>'''
|
||||
|
||||
email_send_fields = {
|
||||
'to': {'string':"To", 'type':'char', 'size':64, 'required':True},
|
||||
'cc': {'string':"CC", 'type':'char', 'size':128,},
|
||||
'subject': {'string':'Subject', 'type':'char', 'size':128, 'required':True},
|
||||
'text': {'string':'Message', 'type':'text_tag', 'required':True},
|
||||
'state':{'string':'State', 'type':'selection', 'selection':[('done','Done'),('pending','Pending'),('unchanged','Unchanged')]},
|
||||
'doc1' : {'string':"Attachment1", 'type':'binary'},
|
||||
'doc2' : {'string':"Attachment2", 'type':'binary'},
|
||||
'doc3' : {'string':"Attachment3", 'type':'binary'},
|
||||
'state' : {'string':"Set State to", 'type':'selection', 'required' : True, 'default' :'done',\
|
||||
'selection': [('unchanged','Unchanged'),('done','Done'),('pending','Pending')]},
|
||||
}
|
||||
|
||||
# this sends an email to ALL the addresses of the selected partners.
|
||||
def _mass_mail_send(self, cr, uid, data, context):
|
||||
attach = filter(lambda x: x, [data['form']['doc1'], data['form']['doc2'], data['form']['doc3']])
|
||||
attach = map(lambda x: x and ('Attachment'+str(attach.index(x)+1), base64.decodestring(x)), attach)
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
case_pool=pool.get(data.get('model'))
|
||||
|
||||
case = case_pool.browse(cr,uid,data['ids'])[0]
|
||||
emails = [data['form']['to']] + (data['form']['cc'] or '').split(',')
|
||||
emails = filter(None, emails)
|
||||
body = data['form']['text']
|
||||
if case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature)
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['form']['to'], details=body)
|
||||
flag = tools.email_send(
|
||||
case.user_id.address_id.email,
|
||||
emails,
|
||||
data['form']['subject'],
|
||||
case_pool.format_body(body),
|
||||
attach=attach,
|
||||
reply_to=case.section_id.reply_to,
|
||||
openobject_id=str(case.id),
|
||||
subtype="html"
|
||||
)
|
||||
if flag:
|
||||
if data['form']['state'] == 'unchanged':
|
||||
pass
|
||||
elif data['form']['state'] == 'done':
|
||||
case_pool.case_close(cr, uid, data['ids'])
|
||||
elif data['form']['state'] == 'pending':
|
||||
case_pool.case_pending(cr, uid, data['ids'])
|
||||
cr.commit()
|
||||
raise wizard.except_wizard(_('Email!'),("Email Successfully Sent"))
|
||||
else:
|
||||
raise wizard.except_wizard(_('Warning!'),_("Email not sent !"))
|
||||
return {}
|
||||
|
||||
def _get_info(self, cr, uid, data, context):
|
||||
if not data['id']:
|
||||
return {}
|
||||
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
case = pool.get(data.get('model')).browse(cr, uid, data['id'])
|
||||
if not case.user_id:
|
||||
raise wizard.except_wizard(_('Error'),_('You must define a responsible user for this case in order to use this action!'))
|
||||
if not case.user_id.address_id.email:
|
||||
raise wizard.except_wizard(_('Warning!'),_("Please specify user's email address !"))
|
||||
|
||||
return {
|
||||
'to': case.email_from,
|
||||
'subject': case.name,
|
||||
'cc': case.email_cc or ''
|
||||
}
|
||||
|
||||
class wizard_send_mail(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_get_info],
|
||||
'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel','gtk-cancel'), ('send','Send Email','gtk-go-forward')]}
|
||||
},
|
||||
'send': {
|
||||
'actions': [_mass_mail_send],
|
||||
'result': {'type': 'state', 'state':'end'}
|
||||
}
|
||||
}
|
||||
wizard_send_mail('crm.new.send.mail')
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -1,103 +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 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 mx.DateTime import now
|
||||
|
||||
import wizard
|
||||
import netsvc
|
||||
import ir
|
||||
import pooler
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
email_send_form = '''<?xml version="1.0"?>
|
||||
<form string="Mass Mailing">
|
||||
<field name="to"/>
|
||||
<newline/>
|
||||
<field name="cc"/>
|
||||
<newline/>
|
||||
<field name="subject"/>
|
||||
<newline/>
|
||||
<field name="text" />
|
||||
</form>'''
|
||||
|
||||
email_send_fields = {
|
||||
'to': {'string':"To", 'type':'char', 'size':64, 'required':True},
|
||||
'cc': {'string':"CC", 'type':'char', 'size':128,},
|
||||
'subject': {'string':'Subject', 'type':'char', 'size':128, 'required':True},
|
||||
'text': {'string':'Message', 'type':'text_tag', 'required':True}
|
||||
}
|
||||
|
||||
# this sends an email to ALL the addresses of the selected partners.
|
||||
def _mass_mail_send(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
hist_obj = pool.get('crm.case.history').browse(cr,uid,data['ids'])[0]
|
||||
model = hist_obj.log_id.model_id.model
|
||||
model_pool = pool.get(model)
|
||||
case = model_pool.browse(cr, uid, hist_obj.log_id.res_id)
|
||||
model_pool._history(cr, uid, [case], _('Send'), history=True, email=False)
|
||||
emails = [data['form']['to']] + (data['form']['cc'] or '').split(',')
|
||||
emails = filter(None, emails)
|
||||
body = data['form']['text']
|
||||
if case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature)
|
||||
tools.email_send(
|
||||
case.user_id.address_id.email,
|
||||
emails,
|
||||
data['form']['subject'],
|
||||
model_pool.format_body(body),
|
||||
reply_to=case.section_id.reply_to,
|
||||
openobject_id=str(case.id),
|
||||
subtype="html"
|
||||
)
|
||||
return {}
|
||||
|
||||
def _get_info(self, cr, uid, data, context):
|
||||
if not data['id']:
|
||||
raise wizard.except_wizard(_('Error'),_('There is no mail to reply!'))
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
hist_obj = pool.get('crm.case.history').browse(cr,uid,data['ids'])[0]
|
||||
model = hist_obj.log_id.model_id.model
|
||||
model_pool = pool.get(model)
|
||||
case = model_pool.browse(cr, uid, hist_obj.log_id.res_id)
|
||||
if not case.email_from:
|
||||
raise wizard.except_wizard(_('Error'),_('You must put a Partner eMail to use this action!'))
|
||||
if not case.user_id:
|
||||
raise wizard.except_wizard(_('Error'),_('You must define a responsible user for this case in order to use this action!'))
|
||||
return {'to': case.email_from,'subject': '['+str(case.id)+'] '+case.name,'cc': case.email_cc or '', 'text': '> ' + hist_obj.description.replace('\n','\n> ')}
|
||||
|
||||
class wizard_send_mail(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_get_info],
|
||||
'result': {'type': 'form', 'arch': email_send_form, 'fields': email_send_fields, 'state':[('end','Cancel','gtk-cancel'), ('send','Send Email','gtk-go-forward')]}
|
||||
},
|
||||
'send': {
|
||||
'actions': [_mass_mail_send],
|
||||
'result': {'type': 'state', 'state':'end'}
|
||||
}
|
||||
}
|
||||
wizard_send_mail('crm.send.mail')
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
@ -150,21 +150,28 @@
|
|||
<field name="date"/>
|
||||
<field name="email"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(crm.action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'hr.applicant'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(crm.action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'hr.applicant'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
|
@ -104,21 +104,28 @@
|
|||
<field name="email"/>
|
||||
<field name="canal_id"/>
|
||||
<button
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4" string="Reply to Last Email" name="%(crm.wizard_crm_send_mail)d" context="{'mail':'reply'}" icon="gtk-undo" type="action"/>
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email" name="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
|
||||
string="Add a CC"
|
||||
name="%(crm.action_view_crm_email_add_cc_wizard)d"
|
||||
icon="gtk-add" type="action"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<button colspan="4"
|
||||
string="Reply to Last Email"
|
||||
name="%(crm.action_crm_reply_mail)d"
|
||||
context="{'mail':'reply', 'model': 'project.issue'}"
|
||||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
name="%(crm.action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'project.issue'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
<page string="Worklogs">
|
||||
<separator string="Timesheets" colspan="4" />
|
||||
|
|
Loading…
Reference in New Issue