[ADD] Mass mailing + Mass forward
bzr revid: tfr@openerp.com-20110228171827-32ftmy34psg9c600
This commit is contained in:
parent
1f2f2ef7ba
commit
6ef20247f0
|
@ -108,6 +108,7 @@ class crm_merge_opportunity(osv.osv_memory):
|
|||
'street' : self._get_first_not_null('street', op_ids),
|
||||
'street2' : self._get_first_not_null('street2', op_ids),
|
||||
'zip' : self._get_first_not_null('zip', op_ids),
|
||||
'state' : 'open'
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,22 @@ class crm_send_new_email(osv.osv_memory):
|
|||
'html': fields.boolean('HTML formatting?', help="Select this if you want to send email with HTML formatting."),
|
||||
}
|
||||
|
||||
def action_mass_send(self, cr, uid, ids, context=None):
|
||||
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
context.update({'mail' : 'new'})
|
||||
actives_ids = context.get('active_ids')
|
||||
print "mass_mail", context.get('mass_mail')
|
||||
model = context.get('active_model')
|
||||
case_pool = self.pool.get(model)
|
||||
for id in actives_ids:
|
||||
context.update({'active_id' : id})
|
||||
self.action_send(cr, uid, ids, context=context)
|
||||
|
||||
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.
|
||||
"""
|
||||
|
@ -75,6 +91,8 @@ class crm_send_new_email(osv.osv_memory):
|
|||
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
|
||||
|
@ -110,8 +128,14 @@ class crm_send_new_email(osv.osv_memory):
|
|||
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 '')
|
||||
if context.get('mass_mail'):
|
||||
email_temp = case.email_from and tools.ustr(case.email_from) or ''
|
||||
emails = re.findall(r'([^ ,<@]+@[^> ,]+)', email_temp)
|
||||
|
||||
email_cc = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_cc or '')
|
||||
|
||||
emails = filter(None, emails)
|
||||
body = obj.body
|
||||
|
||||
|
@ -183,6 +207,8 @@ class crm_send_new_email(osv.osv_memory):
|
|||
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 context.get('mass_mail'):
|
||||
res.update({'email_to': ''})
|
||||
if 'email_from' in fields:
|
||||
res.update({'email_from': user_mail_from and tools.ustr(user_mail_from) or ''})
|
||||
if 'reply_to' in fields:
|
||||
|
@ -190,8 +216,12 @@ class crm_send_new_email(osv.osv_memory):
|
|||
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 context.get('mass_mail'):
|
||||
res.update({'subject': ''})
|
||||
if 'email_cc' in fields:
|
||||
res.update({'email_cc': tools.ustr(case.email_cc or '')})
|
||||
if context.get('mass_mail'):
|
||||
res.update({'email_cc': ''})
|
||||
if 'body' in fields:
|
||||
res.update({'body': u'\n'+(tools.ustr(case.user_id.signature or ''))})
|
||||
if 'state' in fields:
|
||||
|
|
|
@ -44,6 +44,46 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="crm_send_new_mass_mail_view">
|
||||
<field name="name">crm.new.send.mass.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" invisible="True" />
|
||||
<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-cancel" special="cancel" />
|
||||
<button name="action_mass_send" type="object" string="_Send to All" icon="gtk-go-forward" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Send New Mail action -->
|
||||
|
||||
<record model="ir.actions.act_window" id="action_crm_send_mail">
|
||||
|
@ -56,6 +96,14 @@
|
|||
</record>
|
||||
|
||||
|
||||
<act_window id="action_crm_send_mass_mail"
|
||||
multi="True"
|
||||
key2="client_action_multi" name="Send emails"
|
||||
res_model="crm.send.mail" src_model="crm.lead"
|
||||
view_mode="form" target="new" view_type="form"
|
||||
context="{'mass_mail' : True}"
|
||||
view_id="crm_send_new_mass_mail_view"/>
|
||||
|
||||
<!-- Reply to Mail view -->
|
||||
|
||||
<record model="ir.ui.view" id="crm_reply_mail_view">
|
||||
|
@ -89,6 +137,9 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Reply to Mail action -->
|
||||
|
||||
<record model="ir.actions.act_window" id="action_crm_reply_mail">
|
||||
|
|
|
@ -208,7 +208,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
|||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def get_lead_details(self, cr, uid, lead_id, context=None):
|
||||
body = ["""Dear,
|
||||
template = ["""Dear,
|
||||
|
||||
Below is possibly an interesting lead for you.
|
||||
|
||||
|
@ -268,12 +268,13 @@ Kind regards, OpenERP Team
|
|||
"Lead Category: %s" % (lead.categ_id and lead.categ_id.name or ''),
|
||||
"Details: %s" % (lead.description or ''),
|
||||
]
|
||||
return "\n".join(body + ['---'])
|
||||
return "\n".join(template + body + ['---'])
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
"""
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
|
@ -283,15 +284,61 @@ Kind regards, OpenERP Team
|
|||
return defaults
|
||||
|
||||
lead_proxy = self.pool.get('crm.lead')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
lead = lead_proxy.browse(cr, uid, active_id, context=context)
|
||||
|
||||
email_cc = ''
|
||||
email = ''
|
||||
if lead.partner_assigned_id:
|
||||
partner = partner_obj.browse(cr, uid, [lead.partner_assigned_id.id])
|
||||
user_id = partner and partner[0].user_id or False
|
||||
email_cc = user_id and user_id.user_email or ''
|
||||
|
||||
addr = partner_obj.address_get(cr, uid, [partner[0].id], ['contact'])
|
||||
email = self.pool.get('res.partner.address').browse(cr, uid, addr['contact']).email
|
||||
|
||||
|
||||
|
||||
body = self._get_case_history(cr, uid, defaults.get('history', 'latest'), lead.id, context=context)
|
||||
defaults.update({
|
||||
'subject' : '%s: %s' % (_('Fwd'), lead.name),
|
||||
'subject' : '%s: %s - %s' % (_('Fwd'), 'Openerp lead forward', lead.name),
|
||||
'body' : body,
|
||||
'email_cc' : email_cc,
|
||||
'email_to' : email,
|
||||
})
|
||||
return defaults
|
||||
|
||||
crm_lead_forward_to_partner()
|
||||
|
||||
class crm_lead_mass_forward_to_partner(osv.osv_memory):
|
||||
_name = 'crm.lead.mass.forward.to.partner'
|
||||
_inherit = 'crm.lead.forward.to.partner'
|
||||
|
||||
def action_mass_forward(self, cr, uid, ids, context=None):
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
active_ids = context.get('active_ids')
|
||||
case_obj = self.pool.get('crm.lead')
|
||||
for case in case_obj.browse(cr, uid, active_ids, context=context):
|
||||
if case.type != "opportunity":
|
||||
continue
|
||||
|
||||
if not case.partner_assigned_id:
|
||||
case_obj.assign_partner(cr,uid, [case.id], context=context)
|
||||
case = case_obj.browse(cr, uid, case.id, context=context)
|
||||
|
||||
if not case.partner_assigned_id:
|
||||
continue
|
||||
|
||||
context.update({'active_id' : case.id})
|
||||
value = self.default_get(cr, uid, ['body', 'email_to', 'email_cc', 'subject', 'history'], context=context)
|
||||
self.write(cr, uid, ids, value, context=context)
|
||||
self.action_forward(cr,uid, ids, context=context)
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
crm_lead_mass_forward_to_partner()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -38,14 +38,71 @@
|
|||
</button>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="crm_lead_forward_to_partner_act">
|
||||
<field name="name">Forward to Partner</field>
|
||||
<field name="res_model">crm.lead.forward.to.partner</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="crm_lead_forward_to_partner_form1"/>
|
||||
<field name="view_id" ref="crm_lead_forward_to_partner_form"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="crm_forward_mass_mail_view">
|
||||
<field name="name">crm.new.mass.forward.mail.form</field>
|
||||
<field name="model">crm.lead.mass.forward.to.partner</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Send Mail" col="4">
|
||||
<group colspan="4" col="2">
|
||||
<separator string="Forward to Partner" colspan="4" />
|
||||
|
||||
<field name="history" colspan="2" on_change="on_change_history(history, context)" invisible="1"/>
|
||||
<field name="email_from"/>
|
||||
<field name="reply_to"/>
|
||||
<field name="email_to" invisible="1" />
|
||||
<field name="email_cc" invisible="1" />
|
||||
<field name="subject" invisible="1" />
|
||||
<field name="html"/>
|
||||
</group>
|
||||
<notebook colspan="6" >
|
||||
<page string="Message" >
|
||||
<field name="body" nolabel="1" colspan="4" default_focus="1" readonly="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-cancel" special="cancel" />
|
||||
<button name="action_mass_forward" type="object" string="_Mass forward" icon="gtk-go-forward" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="ir.actions.act_window" id="action_crm_send_mass_forward">
|
||||
<field name="name">Mass forward to partner</field>
|
||||
<field name="res_model">crm.lead.mass.forward.to.partner</field>
|
||||
<field name="src_model">crm.lead</field>
|
||||
<field name="view_id" ref="crm_forward_mass_mail_view"/>
|
||||
<field name="target">new</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="context">{'mass_forward' : True}</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue