[IMP]: crm: Improvement in crm send mail wizard, converted it into osv_memory wizard, Merged old send new mail and send mail wizards into new one

bzr revid: rpa@tinyerp.com-20100318135430-t7gfwb7n98poeorb
This commit is contained in:
rpa (Open ERP) 2010-03-18 19:24:30 +05:30
parent 3b8a7a9b44
commit 15e91924f2
15 changed files with 376 additions and 587 deletions

View File

@ -71,7 +71,8 @@ between mails and Open ERP.""",
'wizard/crm_opportunity_to_meeting_view.xml',
'wizard/crm_opportunity_to_phonecall_view.xml',
'wizard/crm_send_new_email_view.xml',
'crm_wizard.xml',
'crm_view.xml',

View File

@ -157,7 +157,11 @@
</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"/>
<button colspan="4"
string="Reply to Last Email"
name="%(crm.action_crm_reply_mail)d"
context="{'mail':'reply', 'model': 'crm.claim'}" icon="gtk-undo"
type="action" />
</form>
<tree string="Communication history">
<field name="description"/>
@ -165,8 +169,11 @@
<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"/>
</page>
<button colspan="4" string="Send New Email"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'crm.claim'}" icon="gtk-go-forward"
type="action" />
</page>
</notebook>
</group>
</form>

View File

@ -155,15 +155,22 @@
</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>
<button colspan="4"
string="Reply to Last Email"
name="%(crm.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="%(crm.wizard_crm_new_send_mail)d" context="{'mail':'new'}" icon="gtk-go-forward" type="action"/>
<button colspan="4" string="Send New Email"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'crm.fundraising'}" icon="gtk-go-forward"
type="action" />
</page>
</notebook>
</form>

View File

@ -103,7 +103,11 @@
</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"/>
<button colspan="4"
string="Reply to Last Email"
name="%(crm.action_crm_reply_mail)d"
context="{'mail':'reply', 'model': 'crm.helpdesk'}"
icon="gtk-undo" type="action" />
</form>
<tree string="Communication history">
<field name="description"/>
@ -111,7 +115,10 @@
<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 colspan="4" string="Send New Email"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'crm.helpdesk'}" icon="gtk-go-forward"
type="action" />
</page>
</notebook>
</form>

View File

@ -124,8 +124,13 @@
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"/>
<field name="description" colspan="4"
nolabel="1" widget="text_tag" readonly="1" />
<button colspan="4"
string="Reply to Last Email"
name="%(crm.action_crm_reply_mail)d"
context="{'mail':'reply', 'model': 'crm.lead'}"
icon="gtk-go-forward" type="action" />
</form>
<tree string="Communication history">
<field name="description"/>
@ -134,8 +139,8 @@
</tree>
</field>
<button colspan="4" string="Send New Email"
name="%(crm.wizard_crm_new_send_mail)d"
context="{'mail':'new'}" icon="gtk-go-forward"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'crm.lead'}" icon="gtk-go-forward"
type="action" />
</page>
<page string="Extra Info" groups="base.group_extended">

View File

@ -147,7 +147,11 @@
</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"/>
<button colspan="4"
string="Reply to Last Email"
name="%(crm.action_crm_reply_mail)d"
context="{'mail':'reply', 'model': 'crm.opportunity'}" icon="gtk-undo"
type="action" />
</form>
<tree string="Communication history">
<field name="description"/>
@ -155,7 +159,10 @@
<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 colspan="4" string="Send New Email"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'crm.opportunity'}" icon="gtk-go-forward"
type="action" />
</page>
</notebook>
</form>

View File

@ -4,11 +4,6 @@
<!-- <menuitem icon="terp-crm" id="menu_crm" name="CRM &amp; 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" />
<!-- Case Sections -->
<record id="crm_case_section_view_form" model="ir.ui.view">
<field name="name">crm.case.section.form</field>
@ -353,7 +348,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"/>
@ -361,7 +360,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_new_mail)d"
context="{'mail':'new', 'model': 'crm.case'}"
icon="gtk-go-forward" type="action" />
</page>
</notebook>
</form>

View File

@ -19,10 +19,7 @@
#
##############################################################################
import crm_phonecall_wizard
import wizard_crm_send_email
import wizard_crm_new_send_email
import crm_send_new_email
import wizard_history_event
import crm_lead_to_partner

View File

@ -1,314 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 mx.DateTime import now
import wizard
import netsvc
import ir
import pooler
from tools.translate import _
class partner_create(wizard.interface):
case_form = """<?xml version="1.0"?>
<form string="Create a Partner">
<label string="Are you sure you want to create a partner based on this phonecall ?" colspan="4"/>
<label string="You may have to verify that this partner does not exist already." colspan="4"/>
<!--field name="close"/-->
</form>"""
case_fields = {
'close': {'type':'boolean', 'string':'Close Phonecall'}
}
partner_form = """<?xml version="1.0"?>
<form string="Create a Partner">
<label string="Are you sure you want to create a partner based on this lead ?" colspan="4"/>
<label string="You may have to verify that this partner does not exist already." colspan="4"/>
<newline />
<field name="action"/>
<group attrs="{'invisible':[('action','!=','exist')]}">
<field name="partner_id"/>
</group>
</form>"""
partner_fields = {
'action': {'type':'selection',
'selection':[('exist','Link to an existing partner'),('create','Create a new partner')],
'string':'Action', 'required':True, 'default': lambda *a:'exist'},
'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
}
def _selectPartner(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
case_obj = pool.get('crm.phonecall')
for case in case_obj.browse(cr, uid, data['ids']):
if case.partner_id:
raise wizard.except_wizard(_('Warning !'),
_('A partner is already defined on this phonecall.'))
return {}
def _create_partner(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
case_obj = pool.get('crm.phonecall')
partner_obj = pool.get('res.partner')
contact_obj = pool.get('res.partner.address')
partner_ids = []
partner_id = False
contact_id = False
for case in case_obj.browse(cr, uid, data['ids']):
if data['form']['action'] == 'create':
partner_id = partner_obj.create(cr, uid, {
'name': case.partner_contact or case.name,
'user_id': case.user_id.id,
'comment': case.description,
})
contact_id = contact_obj.create(cr, uid, {
'partner_id': partner_id,
'name': case.name,
'phone': case.partner_phone,
'mobile': case.partner_mobile,
'email': case.email_from
})
else:
if data['form']['partner_id']:
partner = partner_obj.browse(cr,uid,data['form']['partner_id'])
partner_id = partner.id
contact_id = partner.address and partner.address[0].id
partner_ids.append(partner_id)
vals = {}
if partner_id:
vals.update({'partner_id': partner_id})
if contact_id:
vals.update({'partner_address_id': contact_id})
case_obj.write(cr, uid, [case.id], vals)
return partner_ids
def _make_partner(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
partner_ids = self._create_partner(cr, uid, data, context)
mod_obj = pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
res = mod_obj.read(cr, uid, result, ['res_id'])
value = {
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
states = {
'init': {
'actions': [_selectPartner],
'result': {'type': 'form', 'arch': case_form, 'fields': case_fields,
'state' : [('end', 'Cancel', 'gtk-cancel'),('create_partner', 'Create Partner', 'gtk-go-forward')]}
},
'create_partner': {
'actions': [],
'result': {'type': 'form', 'arch': partner_form, 'fields': partner_fields,
'state' : [('end', 'Cancel', 'gtk-cancel'),('create', 'Continue', 'gtk-go-forward')]}
},
'create': {
'actions': [],
'result': {'type': 'action', 'action': _make_partner, 'state': 'end'}
}
}
partner_create('crm.phonecall.partner_create')
class phonecall2opportunity(partner_create):
case_form = """<?xml version="1.0"?>
<form string="Convert To Opportunity">
<field name="name"/>
<field name="partner_id"/>
<newline/>
<field name="planned_revenue"/>
<field name="probability"/>
</form>"""
case_fields = {
'name': {'type':'char', 'size':64, 'string':'Opportunity Summary', 'required':True},
'planned_revenue': {'type':'float', 'digits':(16,2), 'string': 'Expected Revenue'},
'probability': {'type':'float', 'digits':(16,2), 'string': 'Success Probability'},
'partner_id' : {'type':'many2one', 'relation':'res.partner', 'string':'Partner'},
}
def _check_state(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
case_obj = pool.get('crm.phonecall')
for case in case_obj.browse(cr, uid, data['ids']):
if case.state in ['done', 'cancel']:
raise wizard.except_wizard(_('Warning !'),
_('Closed/Cancelled Phone Call Could not convert into Opportunity.'))
return {}
def _selectopportunity(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
case_obj = pool.get('crm.phonecall')
case = case_obj.browse(cr, uid, data['id'])
return {'name': case.name, 'partner_id':case.partner_id and case.partner_id.id or False}
def _selectChoice(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
case_obj = pool.get('crm.phonecall')
for case in case_obj.browse(cr, uid, data['ids']):
if not case.partner_id:
return 'create_partner'
return 'opportunity'
def _makeOrder(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
data_obj = pool.get('ir.model.data')
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
phonecall_case_obj = pool.get('crm.phonecall')
opportunity_case_obj = pool.get('crm.opportunity')
for phonecall in phonecall_case_obj.browse(cr, uid, data['ids']):
new_opportunity_id = opportunity_case_obj.create(cr, uid, {
'name': data['form']['name'],
'planned_revenue': data['form']['planned_revenue'],
'probability': data['form']['probability'],
'partner_id': data['form']['partner_id'],
'section_id': phonecall.section_id.id,
'description': phonecall.description,
'phonecall_id': phonecall.id,
'priority': phonecall.priority,
'phone': phonecall.partner_phone,
})
new_opportunity = opportunity_case_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': data['form']['partner_id'],
'opportunity_id' : new_opportunity_id,
}
phonecall_case_obj.write(cr, uid, [phonecall.id], vals)
phonecall_case_obj.case_close(cr, uid, [phonecall.id])
opportunity_case_obj.case_open(cr, uid, [new_opportunity_id])
value = {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.opportunity',
'res_id': int(new_opportunity_id),
'view_id': False,
'views': [(id2,'form'),(id3,'tree'),(False,'calendar'),(False,'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
def _makePartner(self, cr, uid, data, context):
partner_ids = self._create_partner(cr, uid, data, context)
return {}
states = {
'init': {
'actions': [_check_state],
'result': {'type':'choice','next_state':_selectChoice}
},
'create_partner': {
'actions': [],
'result': {'type': 'form', 'arch': partner_create.partner_form, 'fields': partner_create.partner_fields,
'state' : [('end', 'Cancel', 'gtk-cancel'),('opportunity', 'Skip', 'gtk-goto-last'),('create', 'Continue', 'gtk-go-forward')]}
},
'create': {
'actions': [],
'result': {'type': 'action', 'action': _makePartner, 'state':'opportunity' }
},
'opportunity': {
'actions': [_selectopportunity],
'result': {'type': 'form', 'arch': case_form, 'fields': case_fields,
'state' : [('end', 'Cancel', 'gtk-cancel'),('confirm', 'Create Opportunity', 'gtk-go-forward')]}
},
'confirm': {
'actions': [],
'result': {'type': 'action', 'action': _makeOrder, 'state': 'end'}
}
}
phonecall2opportunity('crm.phonecall.opportunity_set')
class phonecall2meeting(wizard.interface):
def _makeMeeting(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
phonecall_case_obj = pool.get('crm.phonecall')
data_obj = pool.get('ir.model.data')
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
id = data_obj.read(cr, uid, result, ['res_id'])
id1 = data_obj._get_id(cr, uid, 'crm', 'crm_case_calendar_view_meet')
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_meet')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_meet')
if id1:
id1 = data_obj.browse(cr, uid, id1, context=context).res_id
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
phonecall = phonecall_case_obj.browse(cr, uid, data['id'], context=context)
partner_id = phonecall.partner_id and phonecall.partner_id.id or False
name = phonecall.name
email = phonecall.email_from
section_id = phonecall.section_id and phonecall.section_id.id or False
return {
'name': _('Meetings'),
'domain' : "[('user_id','=',%s)]"%(uid),
'context': {'default_partner_id': partner_id, 'default_section_id': section_id, 'default_email_from': email, 'default_state':'open', 'default_name':name},
'view_type': 'form',
'view_mode': 'calendar,form,tree',
'res_model': 'crm.meeting',
'view_id': False,
'views': [(id1,'calendar'),(id2,'form'),(id3,'tree')],
'type': 'ir.actions.act_window',
'search_view_id': id['res_id']
}
states = {
'init': {
'actions': [],
'result': {'type': 'action', 'action': _makeMeeting, 'state': 'order'}
},
'order': {
'actions': [],
'result': {'type': 'state', 'state': 'end'}
}
}
phonecall2meeting('crm.phonecall.meeting_set')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,220 @@
# -*- 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 _
from osv import osv, fields
class crm_send_new_email(osv.osv_memory):
""" Sends new email for the case"""
_name = "crm.send.new.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 users 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 users 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)
flag = tools.email_send(
case.user_id.address_id.email,
emails,
data['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['state'] == 'unchanged':
pass
elif data['state'] == 'done':
case_pool.case_close(cr, uid, [data['id']])
elif data['state'] == 'pending':
case_pool.case_pending(cr, uid, [data['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 users 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': 'done'})
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 users 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:
res.update({'to': hist.email})
if 'text' in fields:
res.update({'text': '>' + hist.description.replace('\n', '\n> ')})
if 'subject' in fields:
res.update({'subject': case.name or ''})
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 users 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
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:

View File

@ -0,0 +1,78 @@
<?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.new.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="text" widget="text_tag"/>
<field name="doc1" />
<field name="doc2" />
<field name="doc3" />
<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_new_mail">
<field name="name">Send New Mail</field>
<field name="res_model">crm.send.new.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.new.send.mail.form</field>
<field name="model">crm.send.new.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="text" widget="text_tag"/>
<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.new.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>

View File

@ -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:

View File

@ -1,107 +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)
model_pool.write(cr, uid, [case.id], {
'som': False,
'canal_id': 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:

View File

@ -156,7 +156,11 @@
</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"/>
<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"/>
@ -164,8 +168,11 @@
<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"/>
</page>
<button colspan="4" string="Send New Email"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'hr.applicant'}" icon="gtk-go-forward"
type="action" />
</page>
</notebook>
</form>
</field>

View File

@ -109,7 +109,11 @@
</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"/>
<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"/>
@ -117,7 +121,10 @@
<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 colspan="4" string="Send New Email"
name="%(crm.action_crm_send_new_mail)d"
context="{'mail':'new', 'model': 'project.issue'}"
icon="gtk-go-forward" type="action" />
</page>
<page string="Worklogs">
<separator string="Timesheets" colspan="4" />