[IMP] move crm.wizard.mail_compose_message to module mail, to reduce module dependencies on crm
bzr revid: rco@openerp.com-20120703131453-dz0gpdq3t9155bfw
This commit is contained in:
parent
1e123ce0c8
commit
6b1606f8de
|
@ -41,6 +41,7 @@ class crm_lead(base_stage, osv.osv):
|
|||
_description = "Lead/Opportunity"
|
||||
_order = "priority,date_action,id desc"
|
||||
_inherit = ['ir.needaction_mixin', 'mail.thread']
|
||||
_mail_compose_message = True
|
||||
|
||||
def _get_default_section_id(self, cr, uid, context=None):
|
||||
""" Gives default section by checking if present in the context """
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import mail_compose_message
|
||||
import crm_add_note
|
||||
|
||||
import crm_lead_to_partner
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
# -*- 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 or ''),
|
||||
'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:
|
|
@ -22,14 +22,11 @@
|
|||
from base_status.base_stage import base_stage
|
||||
import binascii
|
||||
from crm import crm
|
||||
from crm import wizard
|
||||
from osv import fields, osv
|
||||
import time
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
wizard.mail_compose_message.SUPPORTED_MODELS.append('crm.claim')
|
||||
|
||||
CRM_CLAIM_PENDING_STATES = (
|
||||
crm.AVAILABLE_STATES[2][0], # Cancelled
|
||||
crm.AVAILABLE_STATES[3][0], # Done
|
||||
|
@ -75,6 +72,7 @@ class crm_claim(base_stage, osv.osv):
|
|||
_description = "Claim"
|
||||
_order = "priority,date desc"
|
||||
_inherit = ['mail.thread']
|
||||
_mail_compose_message = True
|
||||
_columns = {
|
||||
'id': fields.integer('ID', readonly=True),
|
||||
'name': fields.char('Claim Subject', size=128, required=True),
|
||||
|
|
|
@ -21,12 +21,9 @@
|
|||
|
||||
from base_status.base_stage import base_stage
|
||||
from crm import crm
|
||||
from crm import wizard
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
wizard.mail_compose_message.SUPPORTED_MODELS.append('crm.fundraising')
|
||||
|
||||
class crm_fundraising(base_stage, osv.osv):
|
||||
""" Fund Raising Cases """
|
||||
|
||||
|
@ -34,6 +31,7 @@ class crm_fundraising(base_stage, osv.osv):
|
|||
_description = "Fund Raising"
|
||||
_order = "id desc"
|
||||
_inherit = ['mail.thread']
|
||||
_mail_compose_message = True
|
||||
_columns = {
|
||||
'id': fields.integer('ID', readonly=True),
|
||||
'name': fields.char('Name', size=128, required=True),
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
from base_status.base_state import base_state
|
||||
from crm import crm
|
||||
from crm import wizard
|
||||
from osv import fields, osv
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
@ -32,8 +31,6 @@ CRM_HELPDESK_STATES = (
|
|||
crm.AVAILABLE_STATES[4][0], # Pending
|
||||
)
|
||||
|
||||
wizard.mail_compose_message.SUPPORTED_MODELS.append('crm.helpdesk')
|
||||
|
||||
class crm_helpdesk(base_state, osv.osv):
|
||||
""" Helpdesk Cases """
|
||||
|
||||
|
@ -41,6 +38,7 @@ class crm_helpdesk(base_state, osv.osv):
|
|||
_description = "Helpdesk"
|
||||
_order = "id desc"
|
||||
_inherit = ['mail.thread']
|
||||
_mail_compose_message = True
|
||||
_columns = {
|
||||
'id': fields.integer('ID', readonly=True),
|
||||
'name': fields.char('Name', size=128, required=True),
|
||||
|
|
|
@ -24,15 +24,10 @@ import time
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from osv import fields, osv
|
||||
from crm import crm
|
||||
import tools
|
||||
import collections
|
||||
import binascii
|
||||
import tools
|
||||
from tools.translate import _
|
||||
from crm import wizard
|
||||
|
||||
wizard.mail_compose_message.SUPPORTED_MODELS.append('hr.applicant')
|
||||
|
||||
AVAILABLE_STATES = [
|
||||
('draft', 'New'),
|
||||
|
@ -98,6 +93,7 @@ class hr_applicant(base_stage, osv.Model):
|
|||
_description = "Applicant"
|
||||
_order = "id desc"
|
||||
_inherit = ['ir.needaction_mixin', 'mail.thread']
|
||||
_mail_compose_message = True
|
||||
|
||||
def _get_default_department_id(self, cr, uid, context=None):
|
||||
""" Gives default department by checking if present in the context """
|
||||
|
|
|
@ -292,4 +292,43 @@ class mail_compose_message(osv.osv_memory):
|
|||
return tools.ustr(result)
|
||||
return template and EXPRESSION_PATTERN.sub(merge, template)
|
||||
|
||||
|
||||
|
||||
class mail_compose_message_extended(osv.osv_memory):
|
||||
""" Extension of 'mail.compose.message' to support default field values related
|
||||
to CRM-like models that follow the following conventions:
|
||||
|
||||
1. The model object must have an attribute '_mail_compose_message' equal to True.
|
||||
|
||||
2. The model should define the following fields:
|
||||
- 'name' as subject of the message (required);
|
||||
- 'email_from' as destination email address (required);
|
||||
- 'email_cc' as cc email addresses (required);
|
||||
- 'section_id.reply_to' as reply-to address (optional).
|
||||
"""
|
||||
_inherit = 'mail.compose.message'
|
||||
|
||||
def get_value(self, cr, uid, model, res_id, context=None):
|
||||
"""Overrides the default implementation to provide more default field values
|
||||
related to the corresponding CRM case.
|
||||
"""
|
||||
result = super(mail_compose_message_extended, self).get_value(cr, uid, model, res_id, context=context)
|
||||
model_obj = self.pool.get(model)
|
||||
if getattr(model_obj, '_mail_compose_message', False) and res_id:
|
||||
data = model_obj.browse(cr, uid , res_id, context)
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
result.update({
|
||||
'model': model,
|
||||
'res_id': res_id,
|
||||
'email_from': user.user_email or tools.config.get('email_from', False),
|
||||
'email_to': data.email_from or False,
|
||||
'email_cc': tools.ustr(data.email_cc or ''),
|
||||
'subject': data.name or False,
|
||||
'body_text': '\n' + tools.ustr(user.signature or ''),
|
||||
'subtype': 'plain',
|
||||
})
|
||||
if hasattr(data, 'section_id'):
|
||||
result['reply_to'] = data.section_id and data.section_id.reply_to or False
|
||||
return result
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -27,9 +27,6 @@ from tools.translate import _
|
|||
import binascii
|
||||
import time
|
||||
import tools
|
||||
from crm import wizard
|
||||
|
||||
wizard.mail_compose_message.SUPPORTED_MODELS.append('project.issue')
|
||||
|
||||
class project_issue_version(osv.osv):
|
||||
_name = "project.issue.version"
|
||||
|
@ -50,6 +47,7 @@ class project_issue(base_stage, osv.osv):
|
|||
_description = "Project Issue"
|
||||
_order = "priority, create_date desc"
|
||||
_inherit = ['ir.needaction_mixin', 'mail.thread']
|
||||
_mail_compose_message = True
|
||||
|
||||
def _get_default_project_id(self, cr, uid, context=None):
|
||||
""" Gives default project by checking if present in the context """
|
||||
|
|
Loading…
Reference in New Issue