diff options
| author | Bharat (OpenERP) <bde@tinyerp.com> | 2011-09-15 17:02:01 +0530 |
|---|---|---|
| committer | Bharat (OpenERP) <bde@tinyerp.com> | 2011-09-15 17:02:01 +0530 |
| commit | d72be842e320dfff08b7ad4b443740060dfd5a4e (patch) | |
| tree | fd8315220318e2abd672b4270a18a763c8564e9d /addons/crm/wizard | |
| parent | 1e767f0d14dfb0870767524bf16c9909bcaee995 (diff) | |
| parent | fbf6708d1041f84018bb9c13e997b705e6086648 (diff) | |
[MERGE] merged with main addons
bzr revid: bde@tinyerp.com-20110915113201-fgbs2d2qr45ljmsg
Diffstat (limited to 'addons/crm/wizard')
| -rw-r--r-- | addons/crm/wizard/__init__.py | 2 | ||||
| -rw-r--r-- | addons/crm/wizard/crm_add_note.py | 27 | ||||
| -rw-r--r-- | addons/crm/wizard/crm_lead_to_opportunity.py | 21 | ||||
| -rw-r--r-- | addons/crm/wizard/crm_merge_opportunities.py | 53 | ||||
| -rw-r--r-- | addons/crm/wizard/crm_send_email.py | 303 | ||||
| -rw-r--r-- | addons/crm/wizard/crm_send_email_view.xml | 154 | ||||
| -rw-r--r-- | addons/crm/wizard/mail_compose_message.py | 63 | ||||
| -rw-r--r-- | addons/crm/wizard/wizard_history_event.py | 2 |
8 files changed, 109 insertions, 516 deletions
diff --git a/addons/crm/wizard/__init__.py b/addons/crm/wizard/__init__.py index 9730b8d1d55..3ebdceda437 100644 --- a/addons/crm/wizard/__init__.py +++ b/addons/crm/wizard/__init__.py @@ -19,7 +19,7 @@ # ############################################################################## -import crm_send_email +import mail_compose_message import crm_add_note import crm_lead_to_partner diff --git a/addons/crm/wizard/crm_add_note.py b/addons/crm/wizard/crm_add_note.py index 3419c89d33a..478f051fe58 100644 --- a/addons/crm/wizard/crm_add_note.py +++ b/addons/crm/wizard/crm_add_note.py @@ -1,11 +1,10 @@ from crm import crm from osv import fields, osv from tools.translate import _ -import base64 +from mail.mail_message import truncate_text AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')] - class crm_add_note(osv.osv_memory): """Adds a new note to the case.""" _name = 'crm.add.note' @@ -14,8 +13,11 @@ class crm_add_note(osv.osv_memory): _columns = { 'body': fields.text('Note Body', required=True), 'state': fields.selection(AVAILABLE_STATES, string='Set New State To', - required=True), - 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'), + required=True), + } + + _defaults = { + 'state': 'unchanged' } def action_add(self, cr, uid, ids, context=None): @@ -32,14 +34,8 @@ class crm_add_note(osv.osv_memory): case_list = case_pool.browse(cr, uid, context['active_ids'], context=context) case = case_list[0] - user_obj = self.pool.get('res.users') - user_name = user_obj.browse(cr, uid, [uid], context=context)[0].name - attach = [ - (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids - ] - case_pool.history(cr, uid, [case], self.pool.get('mailgate.message').truncate_data(cr, uid, obj.body, context=context), history=False, - details=obj.body, email_from=user_name, attach=attach) - + case_pool.message_append(cr, uid, [case], truncate_text(obj.body), + body_text=obj.body) if obj.state == 'unchanged': pass elif obj.state == 'done': @@ -52,11 +48,4 @@ class crm_add_note(osv.osv_memory): return {'type': 'ir.actions.act_window_close'} - def default_get(self, cr, uid, fields, context=None): - """ - This function gets default values - """ - return {'state': u'unchanged'} - - crm_add_note() diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index 16223f8c28f..8200dbd1675 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -132,26 +132,25 @@ class crm_lead2opportunity_partner(osv.osv_memory): vals['partner_address_id'] = False lead.write(vals, context=context) - leads.history(cr, uid, [lead], _('Converted to opportunity'), details='Converted to Opportunity', context=context) + text = _('Converted to opportunity') + leads.message_append(cr, uid, [lead], text, body_text=text, context=context) if lead.partner_id: msg_ids = [ x.id for x in lead.message_ids] - self.pool.get('mailgate.message').write(cr, uid, msg_ids, { + self.pool.get('mail.message').write(cr, uid, msg_ids, { 'partner_id': lead.partner_id.id }, context=context) leads.log(cr, uid, lead.id, _("Lead '%s' has been converted to an opportunity.") % lead.name) - def send_mail_to_salesman(self, lead): + def send_mail_to_salesman(self, cr, uid, lead): email_to = lead.user_id and lead.user_id.user_email if not email_to: - return + return False + message_pool = self.pool.get('mail.message') email_from = lead.section_id and lead.section_id.user_id and lead.section_id.user_id.user_email or email_to - partner = lead.partner_id and lead.partner_id.name or lead.partner_name + partner = lead.partner_id and lead.partner_id.name or lead.partner_name subject = "lead %s converted into opportunity" % lead.name - body = "Info \n Id : %s \n Subject: %s \n Partner: %s \n Description : %s " % (lead.id, lead.name, lead.partner_id.name, lead.description) - try : - tools.email_send(email_from, [email_to], subject, body) - except: - pass + body = "Info \n Id : %s \n Subject: %s \n Partner: %s \n Description : %s " % (lead.id, lead.name, lead.partner_id.name, lead.description) + return message_pool.schedule_with_attach(cr, uid, email_from, [email_to], subject, body) def action_apply(self, cr, uid, ids, context=None): """ @@ -205,7 +204,7 @@ class crm_lead2opportunity_partner(osv.osv_memory): partner_id = False self._convert(cr, uid, ids, lead, partner_id, stage_ids, context=context) - self.send_mail_to_salesman(lead) + self.send_mail_to_salesman(cr, uid, lead) #If we convert in mass, don't merge if there is no other opportunity but no warning if data.name == 'merge' and (len(data.opportunity_ids) > 1 or not context.get('mass_convert') ): merge_obj = self.pool.get('crm.merge.opportunity') diff --git a/addons/crm/wizard/crm_merge_opportunities.py b/addons/crm/wizard/crm_merge_opportunities.py index 57620f8c016..d2d46749746 100644 --- a/addons/crm/wizard/crm_merge_opportunities.py +++ b/addons/crm/wizard/crm_merge_opportunities.py @@ -49,14 +49,9 @@ class crm_merge_opportunity(osv.osv_memory): def get_attachments(self, cr, uid, id, context=None): - attach_obj = self.pool.get('ir.attachment') - attach_ids = attach_obj.search(cr, uid, [('res_model' , '=', 'crm.lead'), ('res_id', '=', id)]) - return attach_ids - - def set_attachements_res_id(self, cr, uid, op_id, attach_ids, context=None): - attach_obj = self.pool.get('ir.attachment') - attach_obj.write(cr, uid, attach_ids, {'res_id' : op_id}) - + proxy = self.pool.get('ir.attachment') + ids = proxy.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', id)], context=context) + return proxy.browse(cr, uid, ids, context=context) def find_oldest(self, cr, uid, op_ids, context=None): if not context: @@ -70,9 +65,9 @@ class crm_merge_opportunity(osv.osv_memory): return False opps = lead_obj.browse(cr, uid, [op_id[0]], context=context) return opps[0] - + def _update_data(self, op_ids, oldest_opp): - data = { + data = { 'partner_id': self._get_first_not_null_id('partner_id', op_ids, oldest_opp), # !! 'title': self._get_first_not_null_id('title', op_ids, oldest_opp), 'name' : self._get_first_not_null('name', op_ids, oldest_opp), #not lost @@ -105,16 +100,15 @@ class crm_merge_opportunity(osv.osv_memory): 'email_from' : self._get_first_not_null('email_from', op_ids, oldest_opp), 'email_cc' : self._get_first_not_null('email_cc', op_ids, oldest_opp), 'partner_name' : self._get_first_not_null('partner_name', op_ids, oldest_opp), - - } - return data + } + return data def merge(self, cr, uid, op_ids, context=None): """ - @param opp_ids : list of opportunities ids to merge + :param opp_ids: list of opportunities ids to merge """ opp_obj = self.pool.get('crm.lead') - message_obj = self.pool.get('mailgate.message') + message_obj = self.pool.get('mail.message') lead_ids = context and context.get('lead_ids', []) or [] @@ -130,15 +124,23 @@ class crm_merge_opportunity(osv.osv_memory): else: first_opportunity = opportunities_list[0] tail_opportunities = opportunities_list[1:] - - - data = self._update_data(op_ids, oldest_opp) + #copy message into the first opportunity + merge attachement - - for opp in tail_opportunities + [first_opportunity]: - attach_ids = self.get_attachments(cr, uid, opp, context=context) - self.set_attachements_res_id(cr, uid, first_opportunity.id, attach_ids) + count = 1 + first_attachments = self.get_attachments(cr, uid, first_opportunity, context=context) + for opp in tail_opportunities: + attachments = self.get_attachments(cr, uid, opp, context=context) + for first in first_attachments: + for attachment in attachments: + if attachment.name == first.name: + values = dict( + name = "%s (%s)" % (attachment.name, count,), + res_id = first_opportunity.id, + ) + attachment.write(values) + count+=1 + for history in opp.message_ids: message_obj.write(cr, uid, history.id, {'res_id': first_opportunity.id, 'name' : _("From %s : %s") % (opp.name, history.name) }, context=context) @@ -172,16 +174,14 @@ class crm_merge_opportunity(osv.osv_memory): subject = subject[0] + ", ".join(subject[1:]) details = "\n\n".join(details) - opp_obj._history(cr, uid, [first_opportunity], subject, details=details) + opp_obj.message_append(cr, uid, [first_opportunity], subject, body_text=details) #data.update({'message_ids' : [(6, 0 ,self._concat_o2m('message_ids', op_ids))]}) - opp_obj.write(cr, uid, [first_opportunity.id], data) + opp_obj.write(cr, uid, [first_opportunity.id], data, context=context) unlink_ids = map(lambda x: x.id, tail_opportunities) opp_obj.unlink(cr, uid, unlink_ids, context=context) models_data = self.pool.get('ir.model.data') - - # Get Opportunity views opportunity_view_form = models_data._get_id( cr, uid, 'crm', 'crm_case_form_view_oppor') @@ -216,7 +216,6 @@ class crm_merge_opportunity(osv.osv_memory): context['lead_ids'] = [op_ids[0].id] return self.merge(cr, uid, op_ids, context) - _columns = { 'opportunity_ids' : fields.many2many('crm.lead', 'merge_opportunity_rel', 'merge_id', 'opportunity_id', 'Opportunities', domain=[('type', '=', 'opportunity')]), } diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py deleted file mode 100644 index d4ba8b476a1..00000000000 --- a/addons/crm/wizard/crm_send_email.py +++ /dev/null @@ -1,303 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved -# $Id$ -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -############################################################################## - -from crm import crm -from osv import osv, fields -from tools.translate import _ -import base64 -import itertools -import tools -import re - - -AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')] - - -class crm_send_new_email_attachment(osv.osv_memory): - _name = 'crm.send.mail.attachment' - - _columns = { - 'binary' : fields.binary('Attachment', required=True), - 'name' : fields.char('Name', size=128, required=True), - 'wizard_id' : fields.many2one('crm.send.mail', 'Wizard', required=True), - } - -crm_send_new_email_attachment() - -class crm_send_new_email(osv.osv_memory): - """ Sends new email for the case""" - _name = "crm.send.mail" - _description = "Send new email" - - _columns = { - 'email_to' : fields.char('To', size=512, required=True), - 'email_from' : fields.char('From', size=128, required=True), - 'reply_to' : fields.char('Reply To', size=128, required=True, help="Reply-to of the Sales team defined on this case"), - 'email_cc' : fields.char('CC', size=512, help="These addresses will receive a copy of this email. To modify the permanent CC list, edit the global CC field of this case"), - 'subject': fields.char('Subject', size=512, required=True), - 'body': fields.text('Message Body', required=True), - 'state': fields.selection(AVAILABLE_STATES, string='Set New State To', required=True), - 'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id', 'Attachment'), - 'html': fields.boolean('HTML formatting?', help="Select this if you want to send email with HTML formatting."), - } - - def action_mass_send(self, cr, uid, ids, context=None): - - if not context: - context = {} - - context.update({'mail' : 'new'}) - actives_ids = context.get('active_ids') - 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. - """ - hist_obj = self.pool.get('mailgate.message') - - if context is None: - context = {} - - if not context.get('active_model'): - raise osv.except_osv(_('Error'), _('Can not send mail!')) - - model = context.get('active_model') - case_pool = self.pool.get(model) - res_id = context and context.get('active_id', False) or False - - - - for obj in self.browse(cr, uid, ids, context=context): - attach = [ - (x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids - ] - - subtype = 'plain' - message_id = None - ref_id = None - - case = case_pool.browse(cr, uid, res_id, context=context) - if context.get('mail', 'new') == 'new': - if case.message_ids: - message_id = case.message_ids[0].message_id - elif context.get('mail') == 'forward': - # extract attachements from case and emails according to mode - attachments = [] - attach_pool = self.pool.get('ir.attachment') - direct_attachments = attach_pool.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', res_id)], context=context) - attachments += attach_pool.browse(cr, uid, direct_attachments, context=context) - if obj.history in ['latest', 'whole'] and case.message_ids: - msgs = case.message_ids - if obj.history == 'latest': - msgs = msgs[:1] - attachments.extend(itertools.chain(*[m.attachment_ids for m in msgs])) - attach_all = [(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas] - attach += attach_all - - else: - hist = hist_obj.browse(cr, uid, res_id, context=context) - message_id = hist.message_id - model = hist.model - case_pool = self.pool.get(model) - res_id = hist.res_id - ref_id = hist.ref_id - case = case_pool.browse(cr, uid, res_id, context=context) - - if context.get('mass_mail'): - email_temp = case.email_from and tools.ustr(case.email_from) or '' - emails = re.findall(r'([^ ,<@]+@[^> ,]+)', email_temp) - else: - emails = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_to or '') - - email_cc = re.findall(r'([^ ,<@]+@[^> ,]+)', obj.email_cc or '') - - emails = filter(None, emails) - body = obj.body - - body = body and tools.ustr(body) or '' - email_from = getattr(obj, 'email_from', False) - x_headers = {} - if message_id: - x_headers['References'] = "%s" % (message_id) - - if obj.html: - subtype = 'html' - - flag = tools.email_send( - email_from, - emails, - obj.subject, - body, - email_cc=email_cc, - attach=attach, - subtype=subtype, - reply_to=obj.reply_to, - openobject_id=str(case.id), - x_headers=x_headers - ) - - if not flag: - raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.')) - - msg_dict = {'new': 'Send', 'reply': 'Reply', 'forward': 'Forward'} - case_pool.history(cr, uid, [case], _(msg_dict[context.get('mail', 'new')]), history=True, \ - email=obj.email_to, details=body, \ - subject=obj.subject, email_from=email_from, \ - email_cc=', '.join(email_cc), message_id=message_id, \ - references=ref_id or message_id, attach=attach) - if obj.state == 'unchanged': - pass - elif obj.state == 'done': - case_pool.case_close(cr, uid, [case.id]) - elif obj.state == 'draft': - case_pool.case_reset(cr, uid, [case.id]) - elif obj.state in ['cancel', 'open', 'pending']: - act = 'case_' + obj.state - getattr(case_pool, act)(cr, uid, [case.id]) - - return {'type': 'ir.actions.act_window_close'} - - def default_get(self, cr, uid, fields, context=None): - """ - This function gets default values - """ - if context is None: - context = {} - - if not context.get('active_model'): - raise osv.except_osv(_('Error'), _('Can not send mail!')) - - res = super(crm_send_new_email, self).default_get(cr, uid, fields, context=context) - - if context.get('mail') == 'reply': - res.update(self.get_reply_defaults(cr, uid, fields, context=context)) - return res - - model = context.get('active_model') - mod_obj = self.pool.get(model) - res_id = context and context.get('active_ids', []) or [] - - user_obj = self.pool.get('res.users') - user_mail_from = user_obj._get_email_from(cr, uid, [uid], context=context)[uid] - for case in mod_obj.browse(cr, uid, res_id, context=context): - if 'email_to' in fields: - res.update({'email_to': case.email_from and tools.ustr(case.email_from) or ''}) - if 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: - if hasattr(case, 'section_id'): - res.update({'reply_to': case.section_id and case.section_id.reply_to or False}) - if 'subject' in fields: - res.update({'subject': tools.ustr(context.get('subject', case.name) or '')}) - if 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: - res.update({'state': u'pending'}) - - return res - - def get_reply_defaults(self, cr, uid, fields, context=None): - """ - This function gets default values for reply mail - """ - hist_obj = self.pool.get('mailgate.message') - res_ids = context and context.get('active_ids', []) or [] - - user_obj = self.pool.get('res.users') - user_mail_from = user_obj._get_email_from(cr, uid, [uid], context=context)[uid] - - include_original = context and context.get('include_original', False) or False - res = {} - for hist in hist_obj.browse(cr, uid, res_ids, context=context): - model = hist.model - - # In the case where the crm.case does not exist in the database - if not model: - return {'type': 'ir.actions.act_window_close'} - - model_pool = self.pool.get(model) - res_id = hist.res_id - case = model_pool.browse(cr, uid, res_id) - if 'email_to' in fields: - res.update({'email_to': case.email_from and tools.ustr(case.email_from) or False}) - if 'email_from' in fields: - res.update({'email_from': user_mail_from and tools.ustr(user_mail_from) or False}) - - signature = u'\n' + (tools.ustr(case.user_id.signature or '')) + u'\n' - original = [signature] - - if include_original == True and 'body' in fields: - header = u'-------- Original Message --------' - sender = u'From: %s' %(tools.ustr(hist.email_from or '')) - to = u'To: %s' % (tools.ustr(hist.email_to or '')) - sentdate = u'Date: %s' % (tools.ustr(hist.date)) - desc = u'\n%s'%(tools.ustr(hist.description)) - - original = [signature, header, sender, to, sentdate, desc] - - res['body']= u'\n' + u'\n'.join(original) - - if 'subject' in fields: - res.update({u'subject': u'Re: %s' %(tools.ustr(hist.name or ''))}) - if 'email_cc' in fields: - email_cc = (case.email_cc and tools.ustr(case.email_cc) + ', ' or '') + (hist.email_cc or '') - res.update({'email_cc': email_cc}) - if 'reply_to' in fields: - if hasattr(case, 'section_id'): - res.update({'reply_to': case.section_id.reply_to or ''}) - if 'state' in fields: - res['state'] = u'pending' - return res - - def view_init(self, cr, uid, fields_list, context=None): - """ - This function checks for precondition before wizard executes - @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param fields: List of fields for default value - @param context: A standard dictionary for contextual values - - """ - if context is None: - context = {} - - if not context.get('active_model'): - raise osv.except_osv(_('Error'), _('Can not send mail!')) - return True - -crm_send_new_email() - diff --git a/addons/crm/wizard/crm_send_email_view.xml b/addons/crm/wizard/crm_send_email_view.xml deleted file mode 100644 index be1644b6bbb..00000000000 --- a/addons/crm/wizard/crm_send_email_view.xml +++ /dev/null @@ -1,154 +0,0 @@ -<?xml version="1.0"?> -<openerp> - <data> - -<!-- Send New Mail view --> - - <record model="ir.ui.view" id="crm_send_new_mail_view"> - <field name="name">crm.new.send.mail.form</field> - <field name="model">crm.send.mail</field> - <field name="type">form</field> - <field name="arch" type="xml"> - <form string="Send Mail" col="4"> - <group colspan="4" col="2"> - <field name="email_from"/> - <field name="reply_to"/> - <field name="email_to" /> - <field name="email_cc"/> - <field name="subject"/> - <field name="html"/> - </group> - <notebook colspan="6"> - <page string="Message"> - <field name="body" nolabel="1" colspan="4" default_focus="1"/> - </page> - <page string="Attachments"> - <field name="attachment_ids" colspan="4" nolabel="1"> - <form string="Attachment"> - <field name="binary" filename="name" /> - <field name="name" /> - </form> - <tree string="Attachments"> - <field name="name" /> - </tree> - </field> - </page> - </notebook> - <separator string="" colspan="6"/> - <group colspan="6" col="4" > - <field name="state" /> - <button string="_Cancel" icon="gtk-close" special="cancel" /> - <button name="action_send" type="object" string="_Send" icon="gtk-go-forward" /> - </group> - </form> - </field> - </record> - - <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_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"> - <field name="name">Send Mail</field> - <field name="res_model">crm.send.mail</field> - <field name="view_type">form</field> - <field name="view_mode">form</field> - <field name="view_id" ref="crm_send_new_mail_view"/> - <field name="target">new</field> - </record> - - - <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"> - <field name="name">crm.mail.reply.form</field> - <field name="model">crm.send.mail</field> - <field name="type">form</field> - <field name="arch" type="xml"> - <form string="Reply to last Mail" col="2"> - <field name="email_from" /> - <field name="email_to" /> - <field name="email_cc" /> - <field name="subject" /> - <field name="attachment_ids" colspan="4" nolabel="1"> - <form string="Attachment"> - <field name="binary" filename="name" /> - <field name="name" /> - </form> - <tree string="Attachments"> - <field name="name" /> - </tree> - </field> - <separator string="" colspan="4"/> - <field name="body" nolabel="1" colspan="4"/> - <separator string=" " colspan="4"/> - <group colspan="4" col="3" > - <label string=" " /> - <button string="_Cancel" icon="gtk-close" special="cancel" /> - <button name="action_send" type="object" string="_Send Reply" icon="gtk-go-forward" /> - </group> - </form> - </field> - </record> - - - - -<!-- Reply to Mail action --> - - <record model="ir.actions.act_window" id="action_crm_reply_mail"> - <field name="name">Reply to last Mail</field> - <field name="res_model">crm.send.mail</field> - <field name="view_type">form</field> - <field name="view_mode">form</field> - <field name="view_id" ref="crm_reply_mail_view"/> - <field name="target">new</field> - </record> - - </data> -</openerp> diff --git a/addons/crm/wizard/mail_compose_message.py b/addons/crm/wizard/mail_compose_message.py new file mode 100644 index 00000000000..512d9ece77a --- /dev/null +++ b/addons/crm/wizard/mail_compose_message.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/> +# +############################################################################## + +from osv import osv +from osv import fields +import tools + +SUPPORTED_MODELS = ['crm.lead',] + +class mail_compose_message(osv.osv_memory): + _inherit = 'mail.compose.message' + + def get_value(self, cr, uid, model, res_id, context=None): + """Returns a defaults-like dict with initial values for the composition + wizard when sending an email related to the document record identified + by ``model`` and ``res_id``. + + Overrides the default implementation to provide more default field values + related to the corresponding CRM case. + + :param str model: model name of the document record this mail is related to. + :param int res_id: id of the document record this mail is related to. + :param dict context: several context values will modify the behavior + of the wizard, cfr. the class description. + """ + result = super(mail_compose_message, self).get_value(cr, uid, model, res_id, context=context) + if model in SUPPORTED_MODELS and res_id: + model_obj = self.pool.get(model) + data = model_obj.browse(cr, uid , res_id, context) + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + result.update({ + 'subject' : data.name or False, + 'email_to' : data.email_from or False, + 'email_from' : user.user_email or tools.config.get('email_from', False), + 'body_text' : '\n' + tools.ustr(user.signature), + 'email_cc' : tools.ustr(data.email_cc or ''), + 'model': model, + 'res_id': res_id, + 'subtype': 'plain', + }) + if hasattr(data, 'section_id'): + result.update({'reply_to' : data.section_id and data.section_id.reply_to or False}) + return result + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm/wizard/wizard_history_event.py b/addons/crm/wizard/wizard_history_event.py index caaf37a88d8..bb501e0b750 100644 --- a/addons/crm/wizard/wizard_history_event.py +++ b/addons/crm/wizard/wizard_history_event.py @@ -32,7 +32,7 @@ def _open_history_event(self, cr, uid, data, context=None): if id2: id2 = data_obj.browse(cr, uid, id2, context=context).res_id res = '' - if data.get('model',False) and data.get('ids',False): + if data.get('model') and data.get('ids'): model_obj = pooler.get_pool(cr.dbname).get(data['model']) res = model_obj.browse(cr, uid, data['ids'], context=context) if len(res): |
