diff --git a/addons/crm/wizard/crm_merge_opportunities.py b/addons/crm/wizard/crm_merge_opportunities.py
index 0c024873fd2..01407b9688d 100644
--- a/addons/crm/wizard/crm_merge_opportunities.py
+++ b/addons/crm/wizard/crm_merge_opportunities.py
@@ -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'
}
diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py
index 8dff88296ab..344350b2baa 100644
--- a/addons/crm/wizard/crm_send_email.py
+++ b/addons/crm/wizard/crm_send_email.py
@@ -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:
diff --git a/addons/crm/wizard/crm_send_email_view.xml b/addons/crm/wizard/crm_send_email_view.xml
index ebbb72592f2..b9aa336cb28 100644
--- a/addons/crm/wizard/crm_send_email_view.xml
+++ b/addons/crm/wizard/crm_send_email_view.xml
@@ -44,6 +44,46 @@
+
+ crm.new.send.mass.mail.form
+ crm.send.mail
+ form
+
+
+
+
+
@@ -56,6 +96,14 @@
+
+
@@ -89,6 +137,9 @@
+
+
+
diff --git a/addons/crm_partner_assign/wizard/crm_forward_to_partner.py b/addons/crm_partner_assign/wizard/crm_forward_to_partner.py
index 0075d5c33f1..6273e054aab 100644
--- a/addons/crm_partner_assign/wizard/crm_forward_to_partner.py
+++ b/addons/crm_partner_assign/wizard/crm_forward_to_partner.py
@@ -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:
diff --git a/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml b/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml
index 9ee2870335a..3e28c56ee53 100644
--- a/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml
+++ b/addons/crm_partner_assign/wizard/crm_forward_to_partner_view.xml
@@ -38,14 +38,71 @@
+
Forward to Partner
crm.lead.forward.to.partner
form
form
-
+
new
+
+
+ crm.new.mass.forward.mail.form
+ crm.lead.mass.forward.to.partner
+ form
+
+
+
+
+
+
+
+ Mass forward to partner
+ crm.lead.mass.forward.to.partner
+ crm.lead
+
+ new
+ client_action_multi
+ {'mass_forward' : True}
+
+
+