[MERGE]: merge with email-framwork-addons

bzr revid: rha@tinyerp.com-20110415112857-cs1dxoei0hfrso6e
This commit is contained in:
Rifakat Haradwala (Open ERP) 2011-04-15 16:58:57 +05:30
commit ec1a1abc6c
140 changed files with 3491 additions and 3925 deletions

View File

@ -44,7 +44,7 @@ Note that if you want to check the followup level for a given partner/account en
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'images': ['images/follow_ups.jpeg','images/send_followups.jpeg'],
'depends': ['account'],
'depends': ['account', 'mail'],
'init_xml': [],
'update_xml': [
'security/ir.model.access.csv',

View File

@ -205,6 +205,7 @@ class account_followup_print_all(osv.osv_memory):
move_obj = self.pool.get('account.move.line')
user_obj = self.pool.get('res.users')
line_obj = self.pool.get('account_followup.stat')
email_message_obj = self.pool.get('email.message')
if context is None:
context = {}
@ -277,7 +278,7 @@ class account_followup_print_all(osv.osv_memory):
msg = ''
if dest:
try:
tools.email_send(src, dest, sub, body)
email_message_obj.schedule_with_attach(cr, uid, src, dest, sub, body, model='account.followup.print.all')
msg_sent += partner.name + '\n'
except Exception, e:
raise osv.except_osv('Error !', e )

View File

@ -36,7 +36,7 @@ trigger an automatic reminder email.
""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'depends': ['base'],
'depends': ['base', 'mail'],
'init_xml': [
'base_action_rule_data.xml'
],

View File

@ -24,7 +24,7 @@ from tools.translate import _
from datetime import datetime
from datetime import timedelta
from tools.safe_eval import safe_eval
import pooler
import pooler
import re
import time
import tools
@ -39,7 +39,7 @@ class base_action_rule(osv.osv):
_name = 'base.action.rule'
_description = 'Action Rules'
def _state_get(self, cr, uid, context=None):
""" Get State
@param self: The object pointer
@ -55,7 +55,7 @@ class base_action_rule(osv.osv):
@param uid: the current users ID for security checks,
@param context: A standard dictionary for contextual values """
return [('', '')]
def priority_get(self, cr, uid, context=None):
""" Get Priority
@param self: The object pointer
@ -65,57 +65,57 @@ class base_action_rule(osv.osv):
return [('', '')]
_columns = {
'name': fields.char('Rule Name', size=64, required=True),
'model_id': fields.many2one('ir.model', 'Object', required=True),
'create_date': fields.datetime('Create Date', readonly=1),
'name': fields.char('Rule Name', size=64, required=True),
'model_id': fields.many2one('ir.model', 'Object', required=True),
'create_date': fields.datetime('Create Date', readonly=1),
'active': fields.boolean('Active', help="If the active field is set to False,\
it will allow you to hide the rule without removing it."),
it will allow you to hide the rule without removing it."),
'sequence': fields.integer('Sequence', help="Gives the sequence order \
when displaying a list of rules."),
when displaying a list of rules."),
'trg_date_type': fields.selection([
('none', 'None'),
('create', 'Creation Date'),
('action_last', 'Last Action Date'),
('date', 'Date'),
('deadline', 'Deadline'),
], 'Trigger Date', size=16),
('none', 'None'),
('create', 'Creation Date'),
('action_last', 'Last Action Date'),
('date', 'Date'),
('deadline', 'Deadline'),
], 'Trigger Date', size=16),
'trg_date_range': fields.integer('Delay after trigger date', \
help="Delay After Trigger Date,\
specifies you can put a negative number. If you need a delay before the \
trigger date, like sending a reminder 15 minutes before a meeting."),
trigger date, like sending a reminder 15 minutes before a meeting."),
'trg_date_range_type': fields.selection([('minutes', 'Minutes'), ('hour', 'Hours'), \
('day', 'Days'), ('month', 'Months')], 'Delay type'),
'trg_user_id': fields.many2one('res.users', 'Responsible'),
'trg_partner_id': fields.many2one('res.partner', 'Partner'),
'trg_partner_categ_id': fields.many2one('res.partner.category', 'Partner Category'),
'trg_state_from': fields.selection(_state_get, 'State', size=16),
'trg_state_to': fields.selection(_state_get, 'Button Pressed', size=16),
('day', 'Days'), ('month', 'Months')], 'Delay type'),
'trg_user_id': fields.many2one('res.users', 'Responsible'),
'trg_partner_id': fields.many2one('res.partner', 'Partner'),
'trg_partner_categ_id': fields.many2one('res.partner.category', 'Partner Category'),
'trg_state_from': fields.selection(_state_get, 'State', size=16),
'trg_state_to': fields.selection(_state_get, 'Button Pressed', size=16),
'act_method': fields.char('Call Object Method', size=64),
'act_user_id': fields.many2one('res.users', 'Set Responsible to'),
'act_state': fields.selection(_state_get, 'Set State to', size=16),
'act_method': fields.char('Call Object Method', size=64),
'act_user_id': fields.many2one('res.users', 'Set Responsible to'),
'act_state': fields.selection(_state_get, 'Set State to', size=16),
'act_email_cc': fields.char('Add Watchers (Cc)', size=250, help="\
These people will receive a copy of the future communication between partner \
and users by email"),
and users by email"),
'act_remind_partner': fields.boolean('Remind Partner', help="Check \
this if you want the rule to send a reminder by email to the partner."),
this if you want the rule to send a reminder by email to the partner."),
'act_remind_user': fields.boolean('Remind Responsible', help="Check \
this if you want the rule to send a reminder by email to the user."),
'act_reply_to': fields.char('Reply-To', size=64),
'act_remind_attach': fields.boolean('Remind with Attachment', help="Check this if you want that all documents attached to the object be attached to the reminder email sent."),
this if you want the rule to send a reminder by email to the user."),
'act_reply_to': fields.char('Reply-To', size=64),
'act_remind_attach': fields.boolean('Remind with Attachment', help="Check this if you want that all documents attached to the object be attached to the reminder email sent."),
'act_mail_to_user': fields.boolean('Mail to Responsible', help="Check\
this if you want the rule to send an email to the responsible person."),
'act_mail_to_watchers': fields.boolean('Mail to Watchers (CC)',
this if you want the rule to send an email to the responsible person."),
'act_mail_to_watchers': fields.boolean('Mail to Watchers (CC)',
help="Check this if you want \
the rule to mark CC(mail to any other person defined in actions)."),
the rule to mark CC(mail to any other person defined in actions)."),
'act_mail_to_email': fields.char('Mail to these Emails', size=128, \
help="Email-id of the persons whom mail is to be sent"),
'act_mail_body': fields.text('Mail body', help="Content of mail"),
help="Email-id of the persons whom mail is to be sent"),
'act_mail_body': fields.text('Mail body', help="Content of mail"),
'regex_name': fields.char('Regex on Resource Name', size=128, help="Regular expression for matching name of the resource\
\ne.g.: 'urgent.*' will search for records having name starting with the string 'urgent'\
\nNote: This is case sensitive search."),
'server_action_id': fields.many2one('ir.actions.server', 'Server Action', help="Describes the action name.\neg:on which object which action to be taken on basis of which condition"),
'filter_id':fields.many2one('ir.filters', 'Filter', required=False),
\nNote: This is case sensitive search."),
'server_action_id': fields.many2one('ir.actions.server', 'Server Action', help="Describes the action name.\neg:on which object which action to be taken on basis of which condition"),
'filter_id':fields.many2one('ir.filters', 'Filter', required=False),
'act_email_from' : fields.char('Email From', size=64, required=False,
help="Use a python expression to specify the right field on which one than we will use for the 'From' field of the header"),
'act_email_to' : fields.char('Email To', size=64, required=False,
@ -124,17 +124,17 @@ the rule to mark CC(mail to any other person defined in actions)."),
}
_defaults = {
'active': lambda *a: True,
'trg_date_type': lambda *a: 'none',
'trg_date_range_type': lambda *a: 'day',
'act_mail_to_user': lambda *a: 0,
'act_remind_partner': lambda *a: 0,
'act_remind_user': lambda *a: 0,
'act_mail_to_watchers': lambda *a: 0,
'active': lambda *a: True,
'trg_date_type': lambda *a: 'none',
'trg_date_range_type': lambda *a: 'day',
'act_mail_to_user': lambda *a: 0,
'act_remind_partner': lambda *a: 0,
'act_remind_user': lambda *a: 0,
'act_mail_to_watchers': lambda *a: 0,
}
_order = 'sequence'
def onchange_model_id(self, cr, uid, ids, name):
#This is not a good solution as it will affect the domain only on onchange
res = {'domain':{'filter_id':[]}}
@ -174,7 +174,7 @@ the rule to mark CC(mail to any other person defined in actions)."),
self.pre_action(cr, uid, [new_id], model, context=context)
return new_id
return make_call_old
def _write(self, old_write, model, context=None):
if context is None:
context = {}
@ -202,9 +202,9 @@ the rule to mark CC(mail to any other person defined in actions)."),
return True
def create(self, cr, uid, vals, context=None):
res_id = super(base_action_rule, self).create(cr, uid, vals, context=context)
self._register_hook(cr, uid, [res_id], context=context)
self._register_hook(cr, uid, [res_id], context=context)
return res_id
def write(self, cr, uid, ids, vals, context=None):
res = super(base_action_rule, self).write(cr, uid, ids, vals, context=context)
self._register_hook(cr, uid, ids, context=context)
@ -272,18 +272,18 @@ the rule to mark CC(mail to any other person defined in actions)."),
@param self: The object pointer """
data = {
'object_id': obj.id,
'object_subject': hasattr(obj, 'name') and obj.name or False,
'object_date': hasattr(obj, 'date') and obj.date or False,
'object_description': hasattr(obj, 'description') and obj.description or False,
'object_user': hasattr(obj, 'user_id') and (obj.user_id and obj.user_id.name) or '/',
'object_id': obj.id,
'object_subject': hasattr(obj, 'name') and obj.name or False,
'object_date': hasattr(obj, 'date') and obj.date or False,
'object_description': hasattr(obj, 'description') and obj.description or False,
'object_user': hasattr(obj, 'user_id') and (obj.user_id and obj.user_id.name) or '/',
'object_user_email': hasattr(obj, 'user_id') and (obj.user_id and \
obj.user_id.address_id and obj.user_id.address_id.email) or '/',
obj.user_id.address_id and obj.user_id.address_id.email) or '/',
'object_user_phone': hasattr(obj, 'user_id') and (obj.user_id and\
obj.user_id.address_id and obj.user_id.address_id.phone) or '/',
'partner': hasattr(obj, 'partner_id') and (obj.partner_id and obj.partner_id.name) or '/',
obj.user_id.address_id and obj.user_id.address_id.phone) or '/',
'partner': hasattr(obj, 'partner_id') and (obj.partner_id and obj.partner_id.name) or '/',
'partner_email': hasattr(obj, 'partner_address_id') and (obj.partner_address_id and\
obj.partner_address_id.email) or '/',
obj.partner_address_id.email) or '/',
}
return self.format_body(body % data)
@ -302,6 +302,7 @@ the rule to mark CC(mail to any other person defined in actions)."),
if context is None:
context = {}
email_message_obj = self.pool.get('email.message')
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.address_id and\
@ -312,9 +313,9 @@ the rule to mark CC(mail to any other person defined in actions)."),
emailfrom = tools.ustr(emailfrom)
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_('Error!'),
raise osv.except_osv(_('Error!'),
_("No E-Mail ID Found for your Company address!"))
return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id))
return email_message_obj.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id))
def do_check(self, cr, uid, action, obj, context=None):
@ -325,7 +326,7 @@ the rule to mark CC(mail to any other person defined in actions)."),
@param context: A standard dictionary for contextual values """
if context is None:
context = {}
ok = True
ok = True
if action.filter_id:
if action.model_id.model == action.filter_id.model_id:
context.update(eval(action.filter_id.context))
@ -480,15 +481,15 @@ the rule to mark CC(mail to any other person defined in actions)."),
return True
_constraints = [
(_check_mail, 'Error: The mail is not well formated', ['act_mail_body']),
(_check_mail, 'Error: The mail is not well formated', ['act_mail_body']),
]
base_action_rule()
class ir_cron(osv.osv):
_inherit = 'ir.cron'
_inherit = 'ir.cron'
def _poolJobs(self, db_name, check=False):
try:
db = pooler.get_db(db_name)

View File

@ -1,11 +1,57 @@
# -*- 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/>.
#
##############################################################################
{
"name": "Base calendar",
"version": "2.0",
"depends": ['base'],
"js": [
'static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler.js',
'static/src/js/calendar.js'
"name" : "Basic Calendar Functionality",
"version" : "1.0",
"depends" : ["base", "mail"],
'description': """
This is a full-featured calendar system.
========================================
It supports:
- Calendar of events
- Alerts (create requests)
- Recurring events
- Invitations to people""",
"author" : "OpenERP SA",
'category': 'Tools',
'website': 'http://www.openerp.com',
"init_xml" : [
'base_calendar_data.xml'
],
"css": ['static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler.css'],
'active': True
"demo_xml" : [],
"update_xml" : [
'security/calendar_security.xml',
'security/ir.model.access.csv',
'wizard/calendar_event_edit_all_view.xml',
'wizard/base_calendar_invite_attendee_view.xml',
'wizard/base_calendar_set_exrule_view.xml',
'base_calendar_view.xml'
],
"test" : ['test/base_calendar_test.yml'],
"installable" : True,
"active" : False,
"certificate" : "00694071962960352821",
'images': ['images/base_calendar1.jpeg','images/base_calendar2.jpeg','images/base_calendar3.jpeg','images/base_calendar4.jpeg',],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -411,7 +411,7 @@ property or property parameter."),
cal = vobject.iCalendar()
event = cal.add('vevent')
if not event_obj.date_deadline or not event_obj.date:
raise osv.except_osv(_('Warning !'),_("Couldn't Invite because date is not specified!"))
raise osv.except_osv(_('Warning !'),_("Couldn't Invite because date is not specified!"))
event.add('created').value = ics_datetime(time.strftime('%Y-%m-%d %H:%M:%S'))
event.add('dtstart').value = ics_datetime(event_obj.date)
event.add('dtend').value = ics_datetime(event_obj.date_deadline)
@ -456,7 +456,7 @@ property or property parameter."),
trigger.value = delta
# Compute other details
valarm.add('DESCRIPTION').value = alarm_data['name'] or 'OpenERP'
for attendee in event_obj.attendee_ids:
attendee_add = event.add('attendee')
attendee_add.params['CUTYPE'] = [str(attendee.cutype)]
@ -480,6 +480,7 @@ property or property parameter."),
context = {}
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.name
email_message_obj = self.pool.get('email.message')
for att in self.browse(cr, uid, ids, context=context):
sign = att.sent_by_uid and att.sent_by_uid.signature or ''
sign = '<br>'.join(sign and sign.split('\n') or [])
@ -506,11 +507,12 @@ property or property parameter."),
body = html_invitation % body_vals
if mail_to and email_from:
attach = self.get_ics_file(cr, uid, res_obj, context=context)
tools.email_send(
email_message_obj.schedule_with_attach(cr, uid,
email_from,
mail_to,
sub,
body,
model='calendar.attendee',
attach=attach and [('invitation.ics', attach)] or None,
subtype='html',
reply_to=email_from
@ -674,7 +676,7 @@ true, it will allow you to hide the event alarm information without removing it.
new_res_alarm = alarm_ids[0]
cr.execute('UPDATE %s ' % model_obj._table + \
' SET base_calendar_alarm_id=%s, alarm_id=%s ' \
' WHERE id=%s',
' WHERE id=%s',
(cal_alarm.id, new_res_alarm, data.id))
self.do_alarm_unlink(cr, uid, [data.id], model)
@ -809,6 +811,7 @@ class calendar_alarm(osv.osv):
return True # XXX FIXME REMOVE THIS AFTER FIXING get_recurrent_dates!!
if context is None:
context = {}
email_message_obj = self.pool.get('email.message')
current_datetime = datetime.now()
request_obj = self.pool.get('res.request')
alarm_ids = self.search(cr, uid, [('state', '!=', 'done')], context=context)
@ -890,11 +893,12 @@ From:
for att in alarm.attendee_ids:
mail_to.append(att.user_id.address_id.email)
if mail_to:
tools.email_send(
email_message_obj.schedule_with_attach(cr, uid,
tools.config.get('email_from', False),
mail_to,
sub,
body
body,
model='calendar.alarm'
)
if next_trigger_date:
update_vals.update({'trigger_date': next_trigger_date})
@ -966,7 +970,7 @@ class calendar_event(osv.osv):
value['date_deadline'] = end.strftime("%Y-%m-%d %H:%M:%S")
elif end_date and duration and not allday:
# we have both, keep them synchronized:
# set duration based on end_date (arbitrary decision: this avoid
# set duration based on end_date (arbitrary decision: this avoid
# getting dates like 06:31:48 instead of 06:32:00)
end = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S")
diff = end - start
@ -1130,7 +1134,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=-1SU'),
'rrule_type': fields.selection([('none', ''), ('daily', 'Daily'), \
('weekly', 'Weekly'), ('monthly', 'Monthly'), \
('yearly', 'Yearly'),],
('yearly', 'Yearly'),],
'Recurrency', states={'done': [('readonly', True)]},
help="Let the event automatically repeat at that interval"),
'alarm_id': fields.many2one('res.alarm', 'Alarm', states={'done': [('readonly', True)]},
@ -1148,7 +1152,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
('weekly', 'Weeks'),
('monthly', 'Months'),
('yearly', 'Years'), ], 'Frequency'),
'end_type' : fields.selection([('forever', 'Forever'), ('count', 'Fix amout of times'), ('end_date','End date')], 'Way to end reccurency'),
'interval': fields.integer('Repeat every', help="Repeat every (Days/Week/Month/Year)"),
'count': fields.integer('Repeat', help="Repeat x times"),
@ -1159,7 +1163,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
'fr': fields.boolean('Fri'),
'sa': fields.boolean('Sat'),
'su': fields.boolean('Sun'),
'select1': fields.selection([('date', 'Date of month'),
'select1': fields.selection([('date', 'Date of month'),
('day', 'Day of month')], 'Option'),
'day': fields.integer('Date of month'),
'week_list': fields.selection([('MO', 'Monday'), ('TU', 'Tuesday'), \
@ -1176,8 +1180,8 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
'allday': fields.boolean('All Day', states={'done': [('readonly', True)]}),
'active': fields.boolean('Active', help="If the active field is set to \
true, it will allow you to hide the event alarm information without removing it."),
'recurrency': fields.boolean('Recurrent', help="Recurrent Meeting"),
'edit_all': fields.boolean('Edit All', help="Edit all Occurrences of recurrent Meeting."),
'recurrency': fields.boolean('Recurrent', help="Recurrent Meeting"),
'edit_all': fields.boolean('Edit All', help="Edit all Occurrences of recurrent Meeting."),
}
def default_organizer(self, cr, uid, context=None):
user_pool = self.pool.get('res.users')
@ -1204,12 +1208,12 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
def onchange_edit_all(self, cr, uid, ids, rrule_type,edit_all, context=None):
if not context:
context = {}
value = {}
if edit_all and rrule_type:
for id in ids:
base_calendar_id2real_id(id)
return value
return value
def modify_all(self, cr, uid, event_ids, defaults, context=None, *args):
"""
@ -1342,7 +1346,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
freq=datas.get('rrule_type')
if freq == 'none':
return ''
interval_srting = datas.get('interval') and (';INTERVAL=' + str(datas.get('interval'))) or ''
if freq == 'weekly':
@ -1358,7 +1362,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
elif datas.get('select1')=='date':
monthstring = ';BYMONTHDAY=' + str(datas.get('day'))
if datas.get('end_date'):
datas['end_date'] = ''.join((re.compile('\d')).findall(datas.get('end_date'))) + 'T235959Z'
enddate = (datas.get('count') and (';COUNT=' + str(datas.get('count'))) or '') +\
@ -1403,7 +1407,7 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
res = self.get_recurrent_ids(cr, uid, res, start_date, until_date, limit)
return res
def get_edit_all(self, cr, uid, id, vals=None):
"""
@ -1414,10 +1418,10 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
if(vals and 'edit_all' in vals): #we jsut check edit_all
return vals['edit_all']
else: #it's a recurrent event and edit_all is already check
return meeting['recurrency'] and meeting['edit_all']
return meeting['recurrency'] and meeting['edit_all']
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
"""
@ -1440,12 +1444,12 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
res = False
for event_id in select:
real_event_id = base_calendar_id2real_id(event_id)
if(self.get_edit_all(cr, uid, event_id, vals=vals)):
event_id = real_event_id
if len(str(event_id).split('-')) > 1:
data = self.read(cr, uid, event_id, ['date', 'date_deadline', \
'rrule', 'duration', 'exdate'])
@ -1459,15 +1463,15 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
'edit_all': False,
'recurrency' : False,
})
new_id = self.copy(cr, uid, real_event_id, default=data, context=context)
date_new = event_id.split('-')[1]
date_new = time.strftime("%Y%m%dT%H%M%S", \
time.strptime(date_new, "%Y%m%d%H%M%S"))
exdate = (data['exdate'] and (data['exdate'] + ',') or '') + date_new
res = self.write(cr, uid, [real_event_id], {'exdate': exdate})
context.update({'active_id': new_id, 'active_ids': [new_id]})
continue
if not real_event_id in new_ids:
@ -1590,10 +1594,10 @@ e.g.: Every other month on the last Sunday of the month for 10 occurrences:\
res = False
for event_datas in self.read(cr, uid, ids, ['date', 'rrule', 'exdate'], context=context):
event_id = event_datas['id']
if self.get_edit_all(cr, uid, event_id, vals=None):
event_id = base_calendar_id2real_id(event_id)
if isinstance(event_id, (int, long)):
res = super(calendar_event, self).unlink(cr, uid, event_id, context=context)
self.pool.get('res.alarm').do_alarm_unlink(cr, uid, [event_id], self._name)
@ -1711,7 +1715,7 @@ class calendar_todo(osv.osv):
@param args: list of tuples of form [(name_of_the_field, operator, value), ...].
@param context: A standard dictionary for contextual values
"""
assert name == 'date'
return self.write(cr, uid, id, { 'date_start': value }, context=context)
@ -1743,9 +1747,9 @@ class ir_attachment(osv.osv):
for arg in args:
args1.append(map(lambda x:str(x).split('-')[0], arg))
return super(ir_attachment, self).search_count(cr, user, args1, context)
def create(self, cr, uid, vals, context=None):
if context:
id = context.get('default_res_id', False)

View File

@ -57,7 +57,7 @@ Creates a dashboard for CRM that includes:
'base',
'base_action_rule',
'process',
'mail_gateway',
'mail',
'base_calendar',
'resource',
'board'
@ -84,7 +84,7 @@ Creates a dashboard for CRM that includes:
'wizard/crm_opportunity_to_phonecall_view.xml',
'wizard/crm_partner_to_opportunity_view.xml',
'wizard/crm_send_email_view.xml',
# 'wizard/crm_send_email_view.xml',
'wizard/crm_add_note_view.xml',
'wizard/crm_merge_opportunities_view.xml',

View File

@ -308,8 +308,8 @@ class crm_case(object):
return {'value': {'phone': address.phone}}
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None):
mailgate_pool = self.pool.get('mailgate.thread')
return mailgate_pool.history(cr, uid, cases, keyword, history=history,\
thread_pool = self.pool.get('email.thread')
return thread_pool.history(cr, uid, cases, keyword, history=history,\
subject=subject, email=email, \
details=details, email_from=email_from,\
message_id=message_id, attach=attach, \
@ -452,12 +452,13 @@ class crm_case(object):
@param ids: List of case's IDs to remind
@param context: A standard dictionary for contextual values
"""
email_message_obj = self.pool.get('email.message')
for case in self.browse(cr, uid, ids, context=context):
if not destination and not case.email_from:
raise osv.except_osv(_('Error!'), ("Partner Email is not specified in Case"))
if not case.user_id.user_email:
raise osv.except_osv(_('Error!'), ("User Email is not specified in Case"))
if destination and case.section_id.user_id:
case_email = case.section_id.user_id.user_email
else:
@ -485,19 +486,19 @@ class crm_case(object):
attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname', 'datas'])
attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send)
# Send an email
subject = "Reminder: [%s] %s" % (str(case.id), case.name,)
tools.email_send(
# Send an email
subject = "Reminder: [%s] %s" % (str(case.id), case.name, )
email_message_obj.schedule_with_attach(cr, uid,
src,
[dest],
subject,
body,
reply_to=case.section_id.reply_to or '',
model='crm.case',
reply_to=case.section_id.reply_to,
openobject_id=str(case.id),
attach=attach_to_send
)
self._history(cr, uid, [case], _('Send'), history=True, subject=subject, email=dest, details=body, email_from=src)
return True
def _check(self, cr, uid, ids=False, context=None):
@ -537,7 +538,7 @@ class crm_case(object):
def format_mail(self, obj, body):
return self.pool.get('base.action.rule').format_mail(obj, body)
def message_followers(self, cr, uid, ids, context=None):
def thread_followers(self, cr, uid, ids, context=None):
""" Get a list of emails of the people following this thread
"""
res = {}

View File

@ -37,25 +37,26 @@ class base_action_rule(osv.osv):
""" Base Action Rule """
_inherit = 'base.action.rule'
_description = 'Action Rules'
_columns = {
'trg_section_id': fields.many2one('crm.case.section', 'Sales Team'),
'trg_max_history': fields.integer('Maximum Communication History'),
'trg_categ_id': fields.many2one('crm.case.categ', 'Category'),
'regex_history' : fields.char('Regular Expression on Case History', size=128),
'act_section_id': fields.many2one('crm.case.section', 'Set Team to'),
'act_categ_id': fields.many2one('crm.case.categ', 'Set Category to'),
'trg_section_id': fields.many2one('crm.case.section', 'Sales Team'),
'trg_max_history': fields.integer('Maximum Communication History'),
'trg_categ_id': fields.many2one('crm.case.categ', 'Category'),
'regex_history' : fields.char('Regular Expression on Case History', size=128),
'act_section_id': fields.many2one('crm.case.section', 'Set Team to'),
'act_categ_id': fields.many2one('crm.case.categ', 'Set Category to'),
'act_mail_to_partner': fields.boolean('Mail to Partner', help="Check \
this if you want the rule to send an email to the partner."),
this if you want the rule to send an email to the partner."),
}
def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from', False), context=None):
email_message_obj = self.pool.get('email.message')
body = self.format_mail(obj, body)
if not emailfrom:
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.address_id and obj.user_id.address_id.email:
emailfrom = obj.user_id.address_id.email
name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
emailfrom = tools.ustr(emailfrom)
if hasattr(obj, 'section_id') and obj.section_id and obj.section_id.reply_to:
@ -63,10 +64,10 @@ this if you want the rule to send an email to the partner."),
else:
reply_to = emailfrom
if not emailfrom:
raise osv.except_osv(_('Error!'),
raise osv.except_osv(_('Error!'),
_("No E-Mail ID Found for your Company address!"))
return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id))
return email_message_obj.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id))
def do_check(self, cr, uid, action, obj, context=None):
""" @param self: The object pointer
@param cr: the current row, from the database cursor,
@ -79,7 +80,7 @@ this if you want the rule to send an email to the partner."),
if hasattr(obj, 'categ_id'):
ok = ok and (not action.trg_categ_id or action.trg_categ_id.id==obj.categ_id.id)
#Cheking for history
#Cheking for history
regex = action.regex_history
result_history = True
if regex:
@ -109,7 +110,7 @@ this if you want the rule to send an email to the partner."),
@param context: A standard dictionary for contextual values """
res = super(base_action_rule, self).do_action(cr, uid, action, model_obj, obj, context=context)
write = {}
if hasattr(action, 'act_section_id') and action.act_section_id:
obj.section_id = action.act_section_id
write['section_id'] = action.act_section_id.id

View File

@ -40,7 +40,7 @@ class crm_lead(crm_case, osv.osv):
_name = "crm.lead"
_description = "Lead/Opportunity"
_order = "date_action, priority, id desc"
_inherit = ['mailgate.thread','res.partner.address']
_inherit = ['email.thread','res.partner.address']
def _compute_day(self, cr, uid, ids, fields, args, context=None):
"""
@param cr: the current row, from the database cursor,
@ -169,8 +169,7 @@ class crm_lead(crm_case, osv.osv):
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'subjects': fields.function(_get_email_subject, fnct_search=_history_search, string='Subject of Email', method=True, type='char', size=64),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
}
@ -336,8 +335,9 @@ class crm_lead(crm_case, osv.osv):
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks
@param msg: dictionary object to contain email message data
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
@ -354,26 +354,13 @@ class crm_lead(crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
res = thread_pool.get_partner(cr, uid, msg.get('from', False))
if res:
vals.update(res)
res = self.create(cr, uid, vals, context)
attachents = msg.get('attachments', [])
for attactment in attachents or []:
data_attach = {
'name': attactment,
'datas':binascii.b2a_base64(str(attachents.get(attactment))),
'datas_fname': attactment,
'description': 'Mail attachment',
'res_model': self._name,
'res_id': res,
}
self.pool.get('ir.attachment').create(cr, uid, data_attach)
return self.create(cr, uid, vals, context)
return res
def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None):
def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@ -410,18 +397,6 @@ class crm_lead(crm_case, osv.osv):
res = self.write(cr, uid, [case.id], values, context=context)
return res
def msg_send(self, cr, uid, id, *args, **argv):
""" Send The Message
@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 emails IDs
@param *args: Return Tuple Value
@param **args: Return Dictionary of Keyword Value
"""
return True
def on_change_optin(self, cr, uid, ids, optin):
return {'value':{'optin':optin,'optout':False}}

View File

@ -105,10 +105,11 @@
</group>
<group colspan="2" col="3">
<separator string="Communication" colspan="4" col="3"/>
<field name="email_from" widget="email"/><button string="Send Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.lead'}"
icon="terp-mail-message-new" type="action" colspan="1"/>
<field name="email_from" widget="email"/>
<button string="Send Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model':'crm.lead', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action" colspan="1"/>
<newline/>
<field name="phone"/>
<newline/>
@ -188,46 +189,46 @@
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="History">
<group col="4" colspan="4">
<field name="email_from"/>
<field name="date"/>
<field name="email_to" size="512"/>
<field name="email_cc" size="512"/>
<field name="name" colspan="4" widget="char" attrs="{'invisible': [('history', '=', False)]}" size="512"/>
<field name="display_text" colspan="4" attrs="{'invisible': [('history', '=', True)]}"/>
<field name="history" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Details">
<field name="description" colspan="4" nolabel="1"/>
<group attrs="{'invisible': [('history', '!=', True)]}">
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
</group>
</page>
<page string="Attachments">
<field name="attachment_ids" colspan="4" readonly="1" nolabel="1"/>
</page>
</notebook>
</form>
<form string="Communication history">
<group col="4" colspan="4">
<field name="email_from"/>
<field name="date"/>
<field name="email_to" widget="char" size="512"/>
<field name="email_cc" widget="char" size="512"/>
<field name="subject" colspan="4" widget="char" size="512"/>
<field name="history" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="body" colspan="4" nolabel="1" height="250"/>
<button colspan="4" string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
<field name="display_text" colspan="4" nolabel="1" height="250"/>
</group>
</page>
<page string="Attachments">
<field name="attachment_ids" colspan="4" readonly="1" nolabel="1"/>
</page>
</notebook>
</form>
</field>
<button string="Add Internal Note"
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.lead'}"
icon="terp-mail-message-new" type="action" />
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model':'crm.lead', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
</notebook>
</form>

View File

@ -42,15 +42,15 @@ class crm_meeting(crm_case, osv.osv):
_name = 'crm.meeting'
_description = "Meeting"
_order = "id desc"
_inherit = ['mailgate.thread',"calendar.event"]
_inherit = ['email.thread',"calendar.event"]
_columns = {
# From crm.case
'name': fields.char('Summary', size=124, required=True, states={'done': [('readonly', True)]}),
'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)]}),
'name': fields.char('Summary', size=124, required=True, states={'done': [('readonly', True)]}),
'partner_id': fields.many2one('res.partner', 'Partner', states={'done': [('readonly', True)]}),
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
domain="[('partner_id','=',partner_id)]", states={'done': [('readonly', True)]}),
domain="[('partner_id','=',partner_id)]", states={'done': [('readonly', True)]}),
'section_id': fields.many2one('crm.case.section', 'Sales Team', states={'done': [('readonly', True)]}, \
select=True, help='Sales team to which Case belongs to.'),
select=True, help='Sales team to which Case belongs to.'),
'email_from': fields.char('Email', size=128, states={'done': [('readonly', True)]}, help="These people will receive email."),
'id': fields.integer('ID'),
'create_date': fields.datetime('Creation Date' , readonly=True),
@ -67,7 +67,7 @@ class crm_meeting(crm_case, osv.osv):
'event_id', 'attendee_id', 'Attendees', states={'done': [('readonly', True)]}),
'date_closed': fields.datetime('Closed', readonly=True),
'date_deadline': fields.datetime('Deadline', states={'done': [('readonly', True)]}),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'state': fields.selection([('open', 'Confirmed'),
('draft', 'Unconfirmed'),
('cancel', 'Cancelled'),
@ -75,7 +75,7 @@ class crm_meeting(crm_case, osv.osv):
size=16, readonly=True),
}
_defaults = {
'state': 'draft',
'state': 'draft',
'active': 1,
'user_id': lambda self, cr, uid, ctx: uid,
}
@ -147,7 +147,7 @@ class res_users(osv.osv):
except:
# Tolerate a missing shortcut. See product/product.py for similar code.
logging.getLogger('orm').debug('Skipped meetings shortcut for user "%s"', data.get('name','<new'))
return user_id
res_users()

View File

@ -60,11 +60,11 @@
<group col="3" colspan="2">
<field name="email_from" string="Email" />
<button string="Send Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.lead'}"
icon="terp-mail-message-new" type="action" />
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model': 'crm.lead', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</group>
<field name="phone"/>
<field name="phone"/>
</group>
<group col="2" colspan="2">
@ -144,11 +144,10 @@
<tree string="History">
<field name="display_text" string="History Information"/>
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</tree>
<form string="History">
<group col="4" colspan="4">
@ -156,19 +155,18 @@
<field name="date"/>
<field name="email_to" size="512"/>
<field name="email_cc" size="512"/>
<field name="name" colspan="4" widget="char" attrs="{'invisible': [('history', '=', False)]}" size="512"/>
<field name="display_text" colspan="4" attrs="{'invisible': [('history', '=', True)]}"/>
<field name="subject" colspan="4" attrs="{'invisible': [('history', '=', True)]}"/>
<field name="display_text" colspan="4" attrs="{'invisible': [('history', '=', False)]}"/>
<field name="history" invisible="1"/>
</group>
<notebook colspan="4">
<page string="Details">
<field name="description" colspan="4" nolabel="1"/>
<field name="body" colspan="4" nolabel="1"/>
<group attrs="{'invisible': [('history', '!=', True)]}">
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</group>
@ -183,10 +181,10 @@
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.lead'}"
icon="terp-mail-message-new" type="action" />
<button string="Send New Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model': 'crm.lead', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
<page string="Extra Info" groups="base.group_extended">
<group col="2" colspan="2">

View File

@ -32,65 +32,65 @@ class crm_phonecall(crm_case, osv.osv):
_name = "crm.phonecall"
_description = "Phonecall"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
# From crm.case
'id': fields.integer('ID'),
'name': fields.char('Call Summary', size=64),
'active': fields.boolean('Active', required=False),
'active': fields.boolean('Active', required=False),
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'create_date': fields.datetime('Creation Date' , readonly=True),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help='Sales team to which Case belongs to.'),
'user_id': fields.many2one('res.users', 'Responsible'),
'partner_id': fields.many2one('res.partner', 'Partner'),
select=True, help='Sales team to which Case belongs to.'),
'user_id': fields.many2one('res.users', 'Responsible'),
'partner_id': fields.many2one('res.partner', 'Partner'),
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
domain="[('partner_id','=',partner_id)]"),
'company_id': fields.many2one('res.company', 'Company'),
'description': fields.text('Description'),
domain="[('partner_id','=',partner_id)]"),
'company_id': fields.many2one('res.company', 'Company'),
'description': fields.text('Description'),
'state': fields.selection([
('draft', 'Draft'),
('open', 'Todo'),
('cancel', 'Cancelled'),
('done', 'Done'),
('draft', 'Draft'),
('open', 'Todo'),
('cancel', 'Cancelled'),
('done', 'Done'),
('pending', 'Pending'),
], 'State', size=16, readonly=True,
], 'State', size=16, readonly=True,
help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'date_open': fields.datetime('Opened', readonly=True),
# phonecall fields
'duration': fields.float('Duration', help="Duration in Minutes"),
'duration': fields.float('Duration', help="Duration in Minutes"),
'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="['|',('section_id','=',section_id),('section_id','=',False),\
('object_id.model', '=', 'crm.phonecall')]"),
'partner_phone': fields.char('Phone', size=32),
('object_id.model', '=', 'crm.phonecall')]"),
'partner_phone': fields.char('Phone', size=32),
'partner_contact': fields.related('partner_address_id', 'name', \
type="char", string="Contact", size=128),
'partner_mobile': fields.char('Mobile', size=32),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
type="char", string="Contact", size=128),
'partner_mobile': fields.char('Mobile', size=32),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'canal_id': fields.many2one('res.partner.canal', 'Channel', \
help="The channels represent the different communication\
modes available with the customer." \
" With each commercial opportunity, you can indicate\
the canall which is this opportunity source."),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Date'),
'opportunity_id': fields.many2one ('crm.lead', 'Opportunity'),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
the canall which is this opportunity source."),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Date'),
'opportunity_id': fields.many2one ('crm.lead', 'Opportunity'),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'priority': crm.AVAILABLE_PRIORITIES[2][0],
'state': 'open',
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'priority': crm.AVAILABLE_PRIORITIES[2][0],
'state': 'open',
'user_id': lambda self,cr,uid,ctx: uid,
'active': 1,
'active': 1,
}
# From crm.case
def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
@ -174,23 +174,23 @@ class crm_phonecall(crm_case, osv.osv):
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
context = {
'default_phonecall_id': phonecall.id,
'default_partner_id': phonecall.partner_id and phonecall.partner_id.id or False,
'default_email': phonecall.email_from ,
'default_phonecall_id': phonecall.id,
'default_partner_id': phonecall.partner_id and phonecall.partner_id.id or False,
'default_email': phonecall.email_from ,
'default_name': phonecall.name
}
value = {
'name': _('Meetings'),
'domain' : "[('user_id','=',%s)]" % (uid),
'context': context,
'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': res['res_id'],
'name': _('Meetings'),
'domain' : "[('user_id','=',%s)]" % (uid),
'context': context,
'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': res['res_id'],
'nodestroy': True
}

View File

@ -109,7 +109,7 @@ class crm_lead_report(osv.osv):
c.planned_revenue,
c.planned_revenue*(c.probability/100) as probable_revenue,
1 as nbr,
(SELECT count(id) FROM mailgate_message WHERE model='crm.lead' AND res_id=c.id AND history=True) AS email,
(SELECT count(id) FROM email_message WHERE model='crm.lead' AND res_id=c.id AND history=True) AS email,
date_trunc('day',c.create_date) as create_date,
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
abs(extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24)) as delay_expected,

View File

@ -27,15 +27,15 @@
"access_res_partner_manager","res.partner.crm.manager","base.model_res_partner","base.group_sale_manager",1,0,0,0
"access_res_partner_address_manager","res.partner.address.crm.user.manager","base.model_res_partner_address","base.group_sale_manager",1,0,0,0
"access_res_partner_category_manager","res.partner.category.crm.manager","base.model_res_partner_category","base.group_sale_manager",1,0,0,0
"mail_gateway_mailgate_message_manager","mail_gateway.mailgate.message.manager","mail_gateway.model_mailgate_message","base.group_sale_manager",1,0,0,0
"mail_gateway_mailgate_thread_manager","mail_gateway.mailgate.thread.manager","mail_gateway.model_mailgate_thread","base.group_sale_manager",1,1,1,1
"email_email_message_manager","mail.email.message.manager","mail.model_email_message","base.group_sale_manager",1,0,0,0
"email_thread_manager","mail.thread.manager","mail.model_email_thread","base.group_sale_manager",1,1,1,1
"access_calendar_attendee_crm_user","calendar.attendee.crm.user","model_calendar_attendee","base.group_sale_salesman",1,1,1,0
"access_calendar_attendee_crm_manager","calendar.attendee.crm.manager","model_calendar_attendee","base.group_sale_manager",1,1,1,1
"access_res_partner","res.partner.crm.user","base.model_res_partner","base.group_sale_salesman",1,1,1,0
"access_res_partner_address","res.partner.address.crm.user","base.model_res_partner_address","base.group_sale_salesman",1,1,1,0
"access_res_partner_category","res.partner.category.crm.user","base.model_res_partner_category","base.group_sale_salesman",1,1,1,0
"mail_gateway_mailgate_thread","mail_gateway.mailgate.thread","mail_gateway.model_mailgate_thread","base.group_sale_salesman",1,1,1,1
"mail_gateway_mailgate_message_user","mail_gateway.mailgate.message.user","mail_gateway.model_mailgate_message","base.group_sale_salesman",1,1,1,1
"email_mailgate_thread","email.thread","mail.model_email_thread","base.group_sale_salesman",1,1,1,1
"email_gateway_email_message_user","mail.email.message.user","mail.model_email_message","base.group_sale_salesman",1,1,1,1
"access_crm_case_categ_manager","crm.case.categ manager","model_crm_case_categ","base.group_sale_manager",1,1,1,1
"access_base_action_rule_manager","base.action.rule manager","model_base_action_rule","base.group_sale_manager",1,1,1,1
"access_crm_lead_report_user","crm.lead.report user","model_crm_lead_report","base.group_sale_salesman",1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
27 access_res_partner_manager res.partner.crm.manager base.model_res_partner base.group_sale_manager 1 0 0 0
28 access_res_partner_address_manager res.partner.address.crm.user.manager base.model_res_partner_address base.group_sale_manager 1 0 0 0
29 access_res_partner_category_manager res.partner.category.crm.manager base.model_res_partner_category base.group_sale_manager 1 0 0 0
30 mail_gateway_mailgate_message_manager email_email_message_manager mail_gateway.mailgate.message.manager mail.email.message.manager mail_gateway.model_mailgate_message mail.model_email_message base.group_sale_manager 1 0 0 0
31 mail_gateway_mailgate_thread_manager email_thread_manager mail_gateway.mailgate.thread.manager mail.thread.manager mail_gateway.model_mailgate_thread mail.model_email_thread base.group_sale_manager 1 1 1 1
32 access_calendar_attendee_crm_user calendar.attendee.crm.user model_calendar_attendee base.group_sale_salesman 1 1 1 0
33 access_calendar_attendee_crm_manager calendar.attendee.crm.manager model_calendar_attendee base.group_sale_manager 1 1 1 1
34 access_res_partner res.partner.crm.user base.model_res_partner base.group_sale_salesman 1 1 1 0
35 access_res_partner_address res.partner.address.crm.user base.model_res_partner_address base.group_sale_salesman 1 1 1 0
36 access_res_partner_category res.partner.category.crm.user base.model_res_partner_category base.group_sale_salesman 1 1 1 0
37 mail_gateway_mailgate_thread email_mailgate_thread mail_gateway.mailgate.thread email.thread mail_gateway.model_mailgate_thread mail.model_email_thread base.group_sale_salesman 1 1 1 1
38 mail_gateway_mailgate_message_user email_gateway_email_message_user mail_gateway.mailgate.message.user mail.email.message.user mail_gateway.model_mailgate_message mail.model_email_message base.group_sale_salesman 1 1 1 1
39 access_crm_case_categ_manager crm.case.categ manager model_crm_case_categ base.group_sale_manager 1 1 1 1
40 access_base_action_rule_manager base.action.rule manager model_base_action_rule base.group_sale_manager 1 1 1 1
41 access_crm_lead_report_user crm.lead.report user model_crm_lead_report base.group_sale_salesman 1 1 1 1

View File

@ -19,7 +19,8 @@
#
##############################################################################
import crm_send_email
#import crm_send_email
import email_compose_message
import crm_add_note
import crm_lead_to_partner

View File

@ -5,6 +5,16 @@ import base64
AVAILABLE_STATES = crm.AVAILABLE_STATES + [('unchanged', 'Unchanged')]
class crm_add_note_email_attachment(osv.osv_memory):
_name = 'crm.add.note.email.attachment'
_columns = {
'binary' : fields.binary('Attachment', required=True),
'name' : fields.char('Name', size=128, required=True),
'wizard_id' : fields.many2one('crm.add.note', 'Wizard', required=True),
}
crm_add_note_email_attachment()
class crm_add_note(osv.osv_memory):
"""Adds a new note to the case."""
@ -14,8 +24,8 @@ 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),
'attachment_ids' : fields.one2many('crm.add.note.email.attachment', 'wizard_id'),
}
def action_add(self, cr, uid, ids, context=None):
@ -37,7 +47,7 @@ class crm_add_note(osv.osv_memory):
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,
case_pool.history(cr, uid, [case], self.pool.get('email.message').truncate_data(cr, uid, obj.body, context=context), history=False,
details=obj.body, email_from=user_name, attach=attach)
if obj.state == 'unchanged':

View File

@ -135,7 +135,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
leads.history(cr, uid, [lead], _('Converted to opportunity'), details='Converted to Opportunity', 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('email.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)

View File

@ -76,7 +76,7 @@ class crm_merge_opportunity(osv.osv_memory):
@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('email.message')
lead_ids = context and context.get('lead_ids', []) or []
@ -217,7 +217,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')]),
}

View File

@ -31,18 +31,6 @@ 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"
@ -79,8 +67,7 @@ class crm_send_new_email(osv.osv_memory):
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')
email_message_obj = self.pool.get('email.message')
if context is None:
context = {}
@ -121,7 +108,7 @@ class crm_send_new_email(osv.osv_memory):
attach += attach_all
else:
hist = hist_obj.browse(cr, uid, res_id, context=context)
hist = email_message_obj.browse(cr, uid, res_id, context=context)
message_id = hist.message_id
model = hist.model
case_pool = self.pool.get(model)
@ -149,11 +136,12 @@ class crm_send_new_email(osv.osv_memory):
if obj.html:
subtype = 'html'
flag = tools.email_send(
flag = email_message_obj.schedule_with_attach(cr, uid,
email_from,
emails,
obj.subject,
body,
model='crm.send.mail',
email_cc=email_cc,
attach=attach,
subtype=subtype,
@ -234,7 +222,7 @@ class crm_send_new_email(osv.osv_memory):
"""
This function gets default values for reply mail
"""
hist_obj = self.pool.get('mailgate.message')
hist_obj = self.pool.get('email.message')
res_ids = context and context.get('active_ids', []) or []
user_obj = self.pool.get('res.users')

View File

@ -0,0 +1,55 @@
# -*- 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
email_model = [
'crm.lead',
]
class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def get_value(self, cr, uid, model, resource_id, context=None):
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
if model in email_model and resource_id:
model_obj = self.pool.get(model)
data = model_obj.browse(cr, uid , resource_id, context)
result.update({
'name' : data.name or False,
'email_to' : data.email_from or False,
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
'description' : '\n' + (tools.ustr(data.user_id.signature or '')),
'email_cc' : tools.ustr(data.email_cc or ''),
'model': model or False,
'res_id': resource_id or False,
})
if hasattr(data, 'section_id'):
result.update({'reply_to' : data.section_id and data.section_id.reply_to or False})
return result
email_compose_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -22,10 +22,12 @@
from osv import fields, osv
from crm import crm
import time
from crm import wizard
import binascii
import tools
from tools.translate import _
wizard.email_compose_message.email_model.append('crm.claim')
CRM_CLAIM_PENDING_STATES = (
crm.AVAILABLE_STATES[2][0], # Cancelled
crm.AVAILABLE_STATES[3][0], # Done
@ -39,49 +41,49 @@ class crm_claim(crm.crm_case, osv.osv):
_name = "crm.claim"
_description = "Claim"
_order = "priority,date desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Claim Subject', size=128, required=True),
'id': fields.integer('ID', readonly=True),
'name': fields.char('Claim Subject', size=128, required=True),
'action_next': fields.char('Next Action', size=200),
'date_action_next': fields.datetime('Next Action Date'),
'description': fields.text('Description'),
'resolution': fields.text('Resolution'),
'create_date': fields.datetime('Creation Date' , readonly=True),
'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Claim Date'),
'ref' : fields.reference('Reference', selection=crm._links_get, size=128),
'description': fields.text('Description'),
'resolution': fields.text('Resolution'),
'create_date': fields.datetime('Creation Date' , readonly=True),
'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Claim Date'),
'ref' : fields.reference('Reference', selection=crm._links_get, size=128),
'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.claim')]"),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
('object_id.model', '=', 'crm.claim')]"),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'type_action': fields.selection([('correction','Corrective Action'),('prevention','Preventive Action')], 'Action Type'),
'user_id': fields.many2one('res.users', 'Responsible'),
'user_fault': fields.char('Trouble Responsible', size=64),
'user_id': fields.many2one('res.users', 'Responsible'),
'user_fault': fields.char('Trouble Responsible', size=64),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help="Sales team to which Case belongs to."\
"Define Responsible user and Email account for"\
" mail gateway."),
'company_id': fields.many2one('res.company', 'Company'),
'partner_id': fields.many2one('res.partner', 'Partner'),
" mail gateway."),
'company_id': fields.many2one('res.company', 'Company'),
'partner_id': fields.many2one('res.partner', 'Partner'),
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
# domain="[('partner_id','=',partner_id)]"
),
'email_cc': fields.text('Watchers Emails', size=252, help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'partner_phone': fields.char('Phone', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('type','=','claim')]"),
'cause': fields.text('Root Cause'),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
),
'email_cc': fields.text('Watchers Emails', size=252, help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'partner_phone': fields.char('Phone', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('type','=','claim')]"),
'cause': fields.text('Root Cause'),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
}
def stage_next(self, cr, uid, ids, context=None):
stage = super(crm_claim, self).stage_next(cr, uid, ids, context=context)
if stage:
@ -95,7 +97,7 @@ class crm_claim(crm.crm_case, osv.osv):
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context)
self.history(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name)
return stage
def _get_stage_id(self, cr, uid, context=None):
"""Finds type of stage according to object.
@param self: The object pointer
@ -110,18 +112,18 @@ class crm_claim(crm.crm_case, osv.osv):
return stage_ids and stage_ids[0] or False
_defaults = {
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from':crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'section_id':crm.crm_case. _get_section,
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from':crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'section_id':crm.crm_case. _get_section,
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
#'stage_id': _get_stage_id,
#'stage_id': _get_stage_id,
}
def onchange_partner_id(self, cr, uid, ids, part, email=False):
"""This function returns value of partner address based on partner
@param self: The object pointer
@ -133,7 +135,7 @@ class crm_claim(crm.crm_case, osv.osv):
"""
if not part:
return {'value': {'partner_address_id': False,
'email_from': False,
'email_from': False,
'partner_phone': False,
'partner_mobile': False
}}
@ -155,21 +157,21 @@ class crm_claim(crm.crm_case, osv.osv):
return {'value': {'email_from': False}}
address = self.pool.get('res.partner.address').browse(cr, uid, add)
return {'value': {'email_from': address.email, 'partner_phone': address.phone, 'partner_mobile': address.mobile}}
def case_open(self, cr, uid, ids, *args):
"""
Opens Claim
"""
res = super(crm_claim, self).case_open(cr, uid, ids, *args)
claims = self.browse(cr, uid, ids)
for i in xrange(0, len(ids)):
if not claims[i].stage_id :
stage_id = self._find_first_stage(cr, uid, 'claim', claims[i].section_id.id or False)
self.write(cr, uid, [ids[i]], {'stage_id' : stage_id})
return res
def message_new(self, cr, uid, msg, context=None):
"""
Automatically calls when new email message arrives
@ -177,8 +179,9 @@ class crm_claim(crm.crm_case, osv.osv):
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks
@param msg: dictionary object to contain email message data
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
@ -195,31 +198,18 @@ class crm_claim(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
res = thread_pool.get_partner(cr, uid, msg.get('from', False))
if res:
vals.update(res)
res = self.create(cr, uid, vals, context)
attachents = msg.get('attachments', [])
for attactment in attachents or []:
data_attach = {
'name': attactment,
'datas':binascii.b2a_base64(str(attachents.get(attactment))),
'datas_fname': attactment,
'description': 'Mail attachment',
'res_model': self._name,
'res_id': res,
}
self.pool.get('ir.attachment').create(cr, uid, data_attach)
return self.create(cr, uid, vals, context)
return res
def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None):
def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None):
"""
@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 update mails IDs
@param ids: List of update mails IDs
"""
if isinstance(ids, (str, int, long)):
ids = [ids]
@ -251,34 +241,22 @@ class crm_claim(crm.crm_case, osv.osv):
res = self.write(cr, uid, [case.id], values, context=context)
return res
def msg_send(self, cr, uid, id, *args, **argv):
""" Send The Message
@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 emails IDs
@param *args: Return Tuple Value
@param **args: Return Dictionary of Keyword Value
"""
return True
crm_claim()
class crm_stage_claim(osv.osv):
def _get_type_value(self, cr, user, context):
list = super(crm_stage_claim, self)._get_type_value(cr, user, context)
list.append(('claim','Claim'))
return list
_inherit = "crm.case.stage"
_columns = {
'type': fields.selection(_get_type_value, 'Type'),
}
crm_stage_claim()

View File

@ -91,15 +91,10 @@
<group>
<field name="name" />
<field name="date"/>
</group>
<group colspan="4" col="6">
<field name="user_id"/>
<field name="section_id" widget="selection" />
<group colspan="2" col="4">
<field name="stage_id" domain="[('type','=','claim')]"/>
<button name="stage_previous" string="" type="object" icon="gtk-go-back" />
@ -180,11 +175,11 @@
<field name="message_ids" colspan="4" nolabel="1" mode="tree,form">
<tree string="History">
<field name="display_text" string="History Information"/>
<button
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.claim', 'include_original' : True}"
icon="terp-mail-replied" type="action" attrs="{'invisible': [('history', '!=', True)]}" />
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="Communication &amp; History">
<group col="4" colspan="4">
@ -199,11 +194,10 @@
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.claim', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button colspan="4" string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
<field name="display_text" colspan="4" nolabel="1" height="250"/>
@ -219,10 +213,10 @@
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.claim'}"
icon="terp-mail-message-new" type="action" />
<button string="Send New Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model':'crm.claim', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
</notebook>
</group>

View File

@ -60,7 +60,7 @@ class crm_claim_report(osv.osv):
('11', 'November'), ('12', 'December')], 'Month', readonly=True),
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'create_date': fields.datetime('Create Date', readonly=True, select=True),
'day': fields.char('Day', size=128, readonly=True),
'day': fields.char('Day', size=128, readonly=True),
'delay_close': fields.float('Delay to close', digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', readonly=True, domain="[('type','=','claim')]"),
'categ_id': fields.many2one('crm.case.categ', 'Category',\
@ -71,8 +71,8 @@ class crm_claim_report(osv.osv):
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'priority': fields.selection(AVAILABLE_PRIORITIES, 'Priority'),
'type_action': fields.selection([('correction','Corrective Action'),('prevention','Preventive Action')], 'Action Type'),
'date_closed': fields.date('Close Date', readonly=True, select=True),
'date_deadline': fields.date('Deadline', readonly=True, select=True),
'date_closed': fields.date('Close Date', readonly=True, select=True),
'date_deadline': fields.date('Deadline', readonly=True, select=True),
'delay_expected': fields.float('Overpassed Deadline',digits=(16,2),readonly=True, group_operator="avg"),
'email': fields.integer('# Emails', size=128, readonly=True),
'probability': fields.float('Probability',digits=(16,2),readonly=True, group_operator="avg")
@ -106,7 +106,7 @@ class crm_claim_report(osv.osv):
c.type_action as type_action,
date_trunc('day',c.create_date) as create_date,
avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close,
(SELECT count(id) FROM mailgate_message WHERE model='crm.claim' AND res_id=c.id AND history=True) AS email,
(SELECT count(id) FROM email_message WHERE model='crm.claim' AND res_id=c.id AND history=True) AS email,
(SELECT avg(probability) FROM crm_case_stage WHERE type='claim' AND id=c.stage_id) AS probability,
extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24) as delay_expected
from

View File

@ -21,6 +21,9 @@
from osv import fields, osv
from crm import crm
from crm import wizard
wizard.email_compose_message.email_model.append('crm.fundraising')
class crm_fundraising(crm.crm_case, osv.osv):
""" Fund Raising Cases """
@ -28,85 +31,85 @@ class crm_fundraising(crm.crm_case, osv.osv):
_name = "crm.fundraising"
_description = "Fund Raising"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
'id': fields.integer('ID'),
'id': fields.integer('ID'),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
'active': fields.boolean('Active', required=False),
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'description': fields.text('Description'),
'create_date': fields.datetime('Creation Date' , readonly=True),
'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'user_id': fields.many2one('res.users', 'Responsible'),
'date_action_next': fields.datetime('Next Action', readonly=1),
'description': fields.text('Description'),
'create_date': fields.datetime('Creation Date' , readonly=True),
'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'user_id': fields.many2one('res.users', 'Responsible'),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help='Sales team to which Case belongs to. Define Responsible user and Email account for mail gateway.'),
'company_id': fields.many2one('res.company', 'Company'),
'partner_id': fields.many2one('res.partner', 'Partner'),
select=True, help='Sales team to which Case belongs to. Define Responsible user and Email account for mail gateway.'),
'company_id': fields.many2one('res.company', 'Company'),
'partner_id': fields.many2one('res.partner', 'Partner'),
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
domain="[('partner_id','=',partner_id)]"),
'email_cc': fields.text('Watchers Emails', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Date'),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
domain="[('partner_id','=',partner_id)]"),
'email_cc': fields.text('Watchers Emails', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Date'),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.fundraising')]"),
'planned_revenue': fields.float('Planned Revenue'),
'planned_cost': fields.float('Planned Costs'),
'probability': fields.float('Probability (%)'),
'partner_name': fields.char("Employee's Name", size=64),
'partner_name2': fields.char('Employee Email', size=64),
'partner_phone': fields.char('Phone', size=32),
'partner_mobile': fields.char('Mobile', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('type', '=', 'fundraising')]"),
('object_id.model', '=', 'crm.fundraising')]"),
'planned_revenue': fields.float('Planned Revenue'),
'planned_cost': fields.float('Planned Costs'),
'probability': fields.float('Probability (%)'),
'partner_name': fields.char("Employee's Name", size=64),
'partner_name2': fields.char('Employee Email', size=64),
'partner_phone': fields.char('Phone', size=32),
'partner_mobile': fields.char('Mobile', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="[('type', '=', 'fundraising')]"),
'type_id': fields.many2one('crm.case.resource.type', 'Campaign', \
domain="[('section_id','=',section_id)]"),
'duration': fields.float('Duration'),
'ref': fields.reference('Reference', selection=crm._links_get, size=128),
'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
domain="[('section_id','=',section_id)]"),
'duration': fields.float('Duration'),
'ref': fields.reference('Reference', selection=crm._links_get, size=128),
'ref2': fields.reference('Reference 2', selection=crm._links_get, size=128),
'canal_id': fields.many2one('res.partner.canal', 'Channel', \
help="The channels represent the different communication \
modes available with the customer."),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
modes available with the customer."),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
}
_defaults = {
'active': lambda *a: 1,
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from': crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'section_id': crm.crm_case. _get_section,
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
'probability': lambda *a:0.0,
'planned_cost': lambda *a:0.0,
'planned_revenue': lambda *a:0.0,
'active': lambda *a: 1,
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from': crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'section_id': crm.crm_case. _get_section,
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
'probability': lambda *a:0.0,
'planned_cost': lambda *a:0.0,
'planned_revenue': lambda *a:0.0,
}
crm_fundraising()
class crm_stage_fundraising(osv.osv):
def _get_type_value(self, cr, user, context):
list = super(crm_stage_fundraising, self)._get_type_value(cr, user, context)
list.append(('fundraising','Fundraising'))
return list
_inherit = "crm.case.stage"
_columns = {
'type': fields.selection(_get_type_value, 'Type'),
}
crm_stage_fundraising()

View File

@ -166,11 +166,11 @@
<tree string="History">
<field name="display_text" string="History Information"/>
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.fundraising', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="History">
<group col="4" colspan="4">
@ -185,11 +185,10 @@
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.fundraising', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button colspan="4" string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
<field name="display_text" colspan="4" nolabel="1" height="250"/>
@ -205,10 +204,10 @@
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.fundraising'}"
icon="terp-mail-message-new" type="action" />
<button string="Send New Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model':'crm.fundraising', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
<page string="Extra Info" groups="base.group_extended">
<group col="2" colspan="2">

View File

@ -22,9 +22,11 @@
from crm import crm
from osv import fields, osv
import time
from crm import wizard
import binascii
import tools
wizard.email_compose_message.email_model.append('crm.helpdesk')
CRM_HELPDESK_STATES = (
crm.AVAILABLE_STATES[2][0], # Cancelled
crm.AVAILABLE_STATES[3][0], # Done
@ -37,61 +39,61 @@ class crm_helpdesk(crm.crm_case, osv.osv):
_name = "crm.helpdesk"
_description = "Helpdesk"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
_columns = {
'id': fields.integer('ID', readonly=True),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'description': fields.text('Description'),
'create_date': fields.datetime('Creation Date' , readonly=True),
'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'user_id': fields.many2one('res.users', 'Responsible'),
'id': fields.integer('ID', readonly=True),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'description': fields.text('Description'),
'create_date': fields.datetime('Creation Date' , readonly=True),
'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'user_id': fields.many2one('res.users', 'Responsible'),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
select=True, help='Sales team to which Case belongs to.\
Define Responsible user and Email account for mail gateway.'),
'company_id': fields.many2one('res.company', 'Company'),
'date_closed': fields.datetime('Closed', readonly=True),
'partner_id': fields.many2one('res.partner', 'Partner'),
Define Responsible user and Email account for mail gateway.'),
'company_id': fields.many2one('res.company', 'Company'),
'date_closed': fields.datetime('Closed', readonly=True),
'partner_id': fields.many2one('res.partner', 'Partner'),
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
domain="[('partner_id','=',partner_id)]"),
'email_cc': fields.text('Watchers Emails', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'date': fields.datetime('Date'),
'ref' : fields.reference('Reference', selection=crm._links_get, size=128),
'ref2' : fields.reference('Reference 2', selection=crm._links_get, size=128),
domain="[('partner_id','=',partner_id)]"),
'email_cc': fields.text('Watchers Emails', size=252 , help="These email addresses will be added to the CC field of all inbound and outbound emails for this record before being sent. Separate multiple email addresses with a comma"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'date': fields.datetime('Date'),
'ref' : fields.reference('Reference', selection=crm._links_get, size=128),
'ref2' : fields.reference('Reference 2', selection=crm._links_get, size=128),
'canal_id': fields.many2one('res.partner.canal', 'Channel', \
help="The channels represent the different communication \
modes available with the customer."),
'planned_revenue': fields.float('Planned Revenue'),
'planned_cost': fields.float('Planned Costs'),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'probability': fields.float('Probability (%)'),
modes available with the customer."),
'planned_revenue': fields.float('Planned Revenue'),
'planned_cost': fields.float('Planned Costs'),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'probability': fields.float('Probability (%)'),
'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.helpdesk')]"),
'duration': fields.float('Duration', states={'done': [('readonly', True)]}),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
('object_id.model', '=', 'crm.helpdesk')]"),
'duration': fields.float('Duration', states={'done': [('readonly', True)]}),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
}
_defaults = {
'active': lambda *a: 1,
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from': crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'active': lambda *a: 1,
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from': crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'section_id': crm.crm_case. _get_section,
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.helpdesk', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
'section_id': crm.crm_case. _get_section,
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.helpdesk', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
}
def message_new(self, cr, uid, msg, context=None):
@ -101,8 +103,9 @@ class crm_helpdesk(crm.crm_case, osv.osv):
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks
@param msg: dictionary object to contain email message data
"""
mailgate_pool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
@ -119,31 +122,18 @@ class crm_helpdesk(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from') or msg.get_unixfrom())
res = thread_pool.get_partner(cr, uid, msg.get('from', False))
if res:
vals.update(res)
res = self.create(cr, uid, vals, context)
attachents = msg.get('attachments', [])
for attactment in attachents or []:
data_attach = {
'name': attactment,
'datas':binascii.b2a_base64(str(attachents.get(attactment))),
'datas_fname': attactment,
'description': 'Mail attachment',
'res_model': self._name,
'res_id': res,
}
self.pool.get('ir.attachment').create(cr, uid, data_attach)
return self.create(cr, uid, vals, context)
return res
def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None):
def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None):
"""
@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 update mails IDs
@param ids: List of update mails IDs
"""
if isinstance(ids, (str, int, long)):
ids = [ids]
@ -175,18 +165,6 @@ class crm_helpdesk(crm.crm_case, osv.osv):
res = self.write(cr, uid, [case.id], values, context=context)
return res
def msg_send(self, cr, uid, id, *args, **argv):
""" Send The Message
@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 emails IDs
@param *args: Return Tuple Value
@param **args: Return Dictionary of Keyword Value
"""
return True
crm_helpdesk()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -100,11 +100,11 @@
<tree string="History">
<field name="display_text" string="History Information"/>
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.helpdesk', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="History">
<group col="4" colspan="4">
@ -119,11 +119,10 @@
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.helpdesk', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button colspan="4" string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
<field name="display_text" colspan="4" nolabel="1" height="250"/>
@ -139,10 +138,10 @@
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.helpdesk'}"
icon="terp-mail-message-new" type="action" />
<button string="Send New Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model':'crm.helpdesk', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
<page string="Extra Info" groups="base.group_extended">
<group colspan="2" col="2">

View File

@ -56,7 +56,7 @@ class crm_helpdesk_report(osv.osv):
'date_deadline': fields.date('Deadline', select=True),
'priority': fields.selection([('5', 'Lowest'), ('4', 'Low'), \
('3', 'Normal'), ('2', 'High'), ('1', 'Highest')], 'Priority'),
'canal_id': fields.many2one('res.partner.canal', 'Channel'),
'canal_id': fields.many2one('res.partner.canal', 'Channel'),
'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.helpdesk')]"),
@ -97,7 +97,7 @@ class crm_helpdesk_report(osv.osv):
c.planned_cost,
count(*) as nbr,
extract('epoch' from (c.date_closed-c.create_date))/(3600*24) as delay_close,
(SELECT count(id) FROM mailgate_message WHERE model='crm.helpdesk' AND res_id=c.id AND history=True) AS email,
(SELECT count(id) FROM email_message WHERE model='crm.helpdesk' AND res_id=c.id AND history=True) AS email,
abs(avg(extract('epoch' from (c.date_deadline - c.date_closed)))/(3600*24)) as delay_expected
from
crm_helpdesk c

View File

@ -1,43 +1,43 @@
-
In order to test Forward Partner functionality, I create an opportunity and forward it to partner.
-
-
I assign an email address to Administrator.
-
-
!record {model: res.users, id: base.user_root}:
user_email: admin@openerp.com
-
-
I create some partner grades.
-
I create a grade 'First'.
-
-
!record {model: res.partner.grade, id: res_partner_grade_first0}:
name: First
sequence: 1
-
-
I create another grade 'Second'.
-
-
!record {model: res.partner.grade, id: res_partner_grade_second0}:
name: Second
sequence: 2
-
-
I create one more grade 'Third'.
-
-
!record {model: res.partner.grade, id: res_partner_grade_third0}:
name: Third
sequence: 3
-
-
I assign grade 'First' to the partner 'Axelor'.
-
-
!record {model: res.partner, id: base.res_partner_desertic_hispafuentes}:
grade_id: res_partner_grade_first0
-
I assgin a reply-to email address to Sales Team.
-
-
!record {model: crm.case.section, id: crm.section_sales_department}:
reply_to: sales_openerp@openerp.com
-
-
I create an opportunity 'Questionnaire on OpenERP'.
-
-
!record {model: crm.lead, id: crm_lead_questionnaireonopenerp0}:
categ_id: crm.categ_oppor7
section_id: crm.section_sales_department
@ -62,7 +62,7 @@
!python {model: crm.lead.forward.to.partner}: |
import tools
vals = {
'name': 'email',
'subject': 'email',
'email_to': 'info@axelor.com',
'email_from': 'Administrator <admin@openerp.com>',
'reply_to': 'sales_openerp@openerp.com'
@ -70,4 +70,4 @@
ids = self.create(cr, uid, vals, context={'active_id': ref('crm_lead_questionnaireonopenerp0'), 'active_model': 'crm.lead'})
assert tools.config.get('smtp_user', False), 'SMTP not configured !'
self.action_forward(cr, uid, [ids], context={'active_id': ref('crm_lead_questionnaireonopenerp0'), 'active_model': 'crm.lead'})

View File

@ -30,10 +30,10 @@ from tools.translate import _
class crm_lead_forward_to_partner(osv.osv_memory):
"""Forwards lead history"""
_name = 'crm.lead.forward.to.partner'
_inherit = "crm.send.mail"
_inherit = "email.compose.message"
_columns = {
'name': fields.selection([('user', 'User'), ('partner', 'Partner'), \
'send_to': fields.selection([('user', 'User'), ('partner', 'Partner'), \
('email', 'Email Address')], 'Send to', required=True),
'user_id': fields.many2one('res.users', "User"),
'partner_id' : fields.many2one('res.partner', 'Partner'),
@ -42,7 +42,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
}
_defaults = {
'name' : 'email',
'send_to' : 'email',
'history': 'latest',
'email_from': lambda self, cr, uid, *a: self.pool.get('res.users')._get_email_from(cr, uid, uid)[uid],
}
@ -70,7 +70,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
@param hist_id: Id of latest history
@param context: A standard dictionary for contextual values
"""
log_pool = self.pool.get('mailgate.message')
log_pool = self.pool.get('email.message')
hist = log_pool.browse(cr, uid, hist_id, context=context)
header = '-------- Original Message --------'
sender = 'From: %s' %(hist.email_from or '')
@ -111,7 +111,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
res_id = context.get('active_id')
msg_val = self._get_case_history(cr, uid, history_type, res_id, context=context)
if msg_val:
res = {'value': {'body' : '\n\n' + msg_val}}
res = {'value': {'description' : '\n\n' + msg_val}}
return res
def _get_case_history(self, cr, uid, history_type, res_id, context=None):
@ -172,6 +172,20 @@ class crm_lead_forward_to_partner(osv.osv_memory):
email = self.pool.get('res.partner.address').browse(cr, uid, address_id).email
return {'value': {'email_to' : email}}
def save_to_drafts(self, cr, uid, ids, context=None):
if context is None:
context = {}
super(crm_lead_forward_to_partner, self).save_to_drafts(cr, uid, ids, context=context)
self.action_forward(cr, uid, ids, context)
return {'type': 'ir.actions.act_window_close'}
def send_mail(self, cr, uid, ids, context=None):
if context is None:
context = {}
super(crm_lead_forward_to_partner, self).send_mail(cr, uid, ids, context=context)
self.action_forward(cr, uid, ids, context)
return {'type': 'ir.actions.act_window_close'}
def action_forward(self, cr, uid, ids, context=None):
"""
Forward the lead to a partner
@ -182,15 +196,13 @@ class crm_lead_forward_to_partner(osv.osv_memory):
case_pool = self.pool.get(context.get('active_model'))
res_id = context and context.get('active_id', False) or False
case = case_pool.browse(cr, uid, res_id, context=context)
context.update({'mail': 'forward'})
super(crm_lead_forward_to_partner, self).action_send(cr, uid, ids, context=context)
to_write = {'date_assign': time.strftime('%Y-%m-%d')}
if (this.name == 'partner' and this.partner_id):
if (this.send_to == 'partner' and this.partner_id):
to_write['partner_assigned_id'] = this.partner_id.id
if this.name == 'user':
if this.send_to == 'user':
to_write.update({'user_id' : this.user_id.id})
email_re = r'([^ ,<@]+@[^> ,]+)'
email_cc = re.findall(email_re, case.email_cc or '')
@ -204,7 +216,6 @@ class crm_lead_forward_to_partner(osv.osv_memory):
new_cc.append(to)
to_write.update({'email_cc' : ', '.join(new_cc) })
case_pool.write(cr, uid, case.id, to_write, context=context)
return {'type': 'ir.actions.act_window_close'}
def get_lead_details(self, cr, uid, lead_id, context=None):
@ -237,7 +248,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
body.append("%s: %s" % (field_definition.string, value or ''))
elif lead.type == 'opportunity':
pa = lead.partner_address_id
body += [
body = [
"Partner: %s" % (lead.partner_id and lead.partner_id.name_get()[0][1]),
"Contact: %s" % (pa.name or ''),
"Title: %s" % (pa.title or ''),

View File

@ -1,41 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="crm_lead_forward_to_partner_form">
<field name="name">crm_lead_forward_to_partner</field>
<field name="model">crm.lead.forward.to.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_send_new_mail_view"/>
<field name="arch" type="xml">
<field name="email_from" position="before">
<form string="Send Mail">
<separator string="Forward to Partner" colspan="4" />
<group col="4" colspan="6">
<field name="history" colspan="2" on_change="on_change_history(history, context)"/>
<field name="name" colspan="2" />
<group col="2" colspan="2" attrs="{ 'invisible' : [('name','!=','user')]}">
<field name="send_to" colspan="2" />
<group col="2" colspan="2" attrs="{ 'invisible' : [('send_to','!=','user')]}">
<field name="user_id"
attrs="{ 'required' : [('name','=','user')]}"
attrs="{ 'required' : [('send_to','=','user')]}"
on_change="on_change_email(user_id)" />
</group>
<group col="4" colspan="4" attrs="{'invisible' : [('name','!=','partner')]}">
<field name="partner_id" attrs="{'required' : [('name','=','partner')]}" on_change="on_change_partner(partner_id)" colspan="2" />
<group col="4" colspan="4" attrs="{'invisible' : [('send_to','!=','partner')]}">
<field name="partner_id" attrs="{'required' : [('send_to','=','partner')]}" on_change="on_change_partner(partner_id)" colspan="2" />
<field name="address_id" string="Contact" on_change="on_change_address(address_id)" colspan="2" />
</group>
</group>
<separator string="" colspan="4" />
</field>
</field>
</record>
<record model="ir.ui.view" id="crm_lead_forward_to_partner_form1">
<field name="name">crm_lead_forward_to_partner1</field>
<field name="model">crm.lead.forward.to.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_send_new_mail_view"/>
<field name="arch" type="xml">
<button name="action_send" position="replace">
<button name="action_forward" string="Forward" icon="gtk-go-forward" type="object" />
</button>
<group col="6" colspan="4">
<field name="smtp_server_id" widget="selection" colspan="4"/>
<field name="email_from" colspan="4" required="1"/>
<field name="email_to" colspan="4" required="1"/>
<field name="email_cc" colspan="4"/>
<field name="email_bcc" colspan="4"/>
<field name="reply_to" colspan="4"/>
<field name="name" colspan="4" widget="char" size="512"/>
</group>
<separator string="" colspan="4"/>
<notebook colspan="4">
<page string="Body">
<field name="description" colspan="4" nolabel="1"/>
</page>
<page string="Attachments">
<label string="Add here all attachments of the current document you want to include in the Email." colspan="4"/>
<field name="attachment_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
<group col="4" colspan="4">
<label string="" colspan="1"/>
<button icon="gtk-close" special="cancel" string="Close"/>
<button icon="gtk-apply" name="save_to_drafts" string="Save in Drafts" type="object"/>
<button icon="gtk-ok" name="send_mail" string="Send now" type="object"/>
</group>
</form>
</field>
</record>

View File

@ -3,7 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# Copyright (C) 2010-2010 OpenERP SA (<http://www.openerp.com>)
# 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
@ -19,9 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
import email_template_account
import mako_template
import email_template
import email_template_mailbox
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -26,7 +26,7 @@
"author" : "Openlabs",
"website" : "http://openerp.com",
"category" : "Tools",
"depends" : ['marketing', 'base_tools'],
"depends" : ['mail'],
"description": """
Email Template is extraction of Power Email basically just to send emails.
==========================================================================
@ -38,14 +38,12 @@ For each email template, you can have OpenERP generate a Wizard Action / Button
that will be related to the object. So if you choose to do marketing campaigns
for leads, the action will be added to the right side panel of the Lead form.
""",
"init_xml": ['email_template_scheduler_data.xml'],
"init_xml": [],
"update_xml": [
'security/email_template_security.xml',
'email_template_workflow.xml',
'email_template_account_view.xml',
'wizard/email_template_preview_view.xml',
'email_template_view.xml',
'email_template_mailbox_view.xml',
'wizard/email_template_send_wizard_view.xml',
'wizard/email_compose_message_view.xml',
'security/ir.model.access.csv'
],
"installable": True,

File diff suppressed because it is too large Load Diff

View File

@ -1,470 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# Copyright (C) 2004-2010 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, fields
import re
import smtplib
import base64
from email import Encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import decode_header, Header
from email.utils import formatdate
import netsvc
import datetime
from tools.translate import _
import tools
import logging
EMAIL_PATTERN = re.compile(r'([^()\[\] ,<:\\>@";]+@[^()\[\] ,<:\\>@";]+)') # See RFC822
def extract_emails(emails_str):
"""
Returns a list of email addresses recognized in a string, ignoring the rest of the string.
extract_emails('a@b.com,c@bcom, "John Doe" <d@b.com> , e@b.com') -> ['a@b.com','c@bcom', 'd@b.com', 'e@b.com']"
"""
return EMAIL_PATTERN.findall(emails_str)
def extract_emails_from_dict(addresses={}):
"""
Extracts email addresses from a dictionary with comma-separated address string values, handling
separately the To, CC, BCC and Reply-To addresses.
:param addresses: a dictionary of addresses in the form {'To': 'a@b.com,c@bcom; d@b.com;e@b.com' , 'CC': 'e@b.com;f@b.com', ... }
:return: a dictionary with a list of separate addresses for each header (To, CC, BCC), with an additional key 'all-recipients'
containing all addresses for the 'To', 'CC', 'BCC' entries.
"""
result = {'all-recipients':[]}
keys = ['To', 'CC', 'BCC', 'Reply-To']
for each in keys:
emails = extract_emails(addresses.get(each, u''))
while u'' in emails:
emails.remove(u'')
result[each] = emails
if each != 'Reply-To':
result['all-recipients'].extend(emails)
return result
class email_template_account(osv.osv):
"""
Object to store email account settings
"""
_name = "email_template.account"
_known_content_types = ['multipart/mixed',
'multipart/alternative',
'multipart/related',
'text/plain',
'text/html'
]
_columns = {
'name': fields.char('Description',
size=64, required=True,
readonly=True, select=True,
help="The description is used as the Sender name along with the provided From Email, \
unless it is already specified in the From Email, e.g: John Doe <john@doe.com>",
states={'draft':[('readonly', False)]}),
'auto_delete': fields.boolean('Auto Delete', size=64, readonly=True,
help="Permanently delete emails after sending",
states={'draft':[('readonly', False)]}),
'user':fields.many2one('res.users',
'Related User', required=True,
readonly=True, states={'draft':[('readonly', False)]}),
'email_id': fields.char('From Email',
size=120, required=True,
readonly=True, states={'draft':[('readonly', False)]} ,
help="eg: 'john@doe.com' or 'John Doe <john@doe.com>'"),
'smtpserver': fields.char('Server',
size=120, required=True,
readonly=True, states={'draft':[('readonly', False)]},
help="Enter name of outgoing server, eg: smtp.yourdomain.com"),
'smtpport': fields.integer('SMTP Port',
size=64, required=True,
readonly=True, states={'draft':[('readonly', False)]},
help="Enter port number, eg: 25 or 587"),
'smtpuname': fields.char('User Name',
size=120, required=False,
readonly=True, states={'draft':[('readonly', False)]},
help="Specify the username if your SMTP server requires authentication, "
"otherwise leave it empty."),
'smtppass': fields.char('Password',
size=120, invisible=True,
required=False, readonly=True,
states={'draft':[('readonly', False)]}),
'smtptls':fields.boolean('TLS',
states={'draft':[('readonly', False)]}, readonly=True),
'smtpssl':fields.boolean('SSL/TLS (only in python 2.6)',
states={'draft':[('readonly', False)]}, readonly=True),
'send_pref':fields.selection([
('html', 'HTML, otherwise Text'),
('text', 'Text, otherwise HTML'),
('alternative', 'Both HTML & Text (Alternative)'),
('mixed', 'Both HTML & Text (Mixed)')
], 'Mail Format', required=True),
'company':fields.selection([
('yes', 'Yes'),
('no', 'No')
], 'Corporate',
readonly=True,
help="Select if this mail account does not belong " \
"to specific user but to the organization as a whole. " \
"eg: info@companydomain.com",
required=True, states={
'draft':[('readonly', False)]
}),
'state':fields.selection([
('draft', 'Initiated'),
('suspended', 'Suspended'),
('approved', 'Approved')
],
'State', required=True, readonly=True),
}
_defaults = {
'name':lambda self, cursor, user, context:self.pool.get(
'res.users'
).read(
cursor,
user,
user,
['name'],
context
)['name'],
'state':lambda * a:'draft',
'smtpport':lambda *a:25,
'smtpserver':lambda *a:'localhost',
'company':lambda *a:'yes',
'user':lambda self, cursor, user, context:user,
'send_pref':lambda *a: 'html',
'smtptls':lambda *a:True,
}
_sql_constraints = [
(
'email_uniq',
'unique (email_id)',
'Another setting already exists with this email ID !')
]
def name_get(self, cr, uid, ids, context=None):
return [(a["id"], "%s (%s)" % (a['email_id'], a['name'])) for a in self.read(cr, uid, ids, ['name', 'email_id'], context=context)]
def _constraint_unique(self, cursor, user, ids, context=None):
"""
This makes sure that you dont give personal
users two accounts with same ID (Validated in sql constaints)
However this constraint exempts company accounts.
Any no of co accounts for a user is allowed
"""
if self.read(cursor, user, ids, ['company'])[0]['company'] == 'no':
accounts = self.search(cursor, user, [
('user', '=', user),
('company', '=', 'no')
])
if len(accounts) > 1 :
return False
else :
return True
else:
return True
_constraints = [
(_constraint_unique,
'Error: You are not allowed to have more than 1 account.',
[])
]
def get_outgoing_server(self, cursor, user, ids, context=None):
"""
Returns the Out Going Connection (SMTP) object
@attention: DO NOT USE except_osv IN THIS METHOD
@param cursor: Database Cursor
@param user: ID of current user
@param ids: ID/list of ids of current object for
which connection is required
First ID will be chosen from lists
@param context: Context
@return: SMTP server object or Exception
"""
#Type cast ids to integer
if type(ids) == list:
ids = ids[0]
this_object = self.browse(cursor, user, ids, context=context)
if this_object:
if this_object.smtpserver and this_object.smtpport:
try:
if this_object.smtpssl:
serv = smtplib.SMTP_SSL(this_object.smtpserver, this_object.smtpport)
else:
serv = smtplib.SMTP(this_object.smtpserver, this_object.smtpport)
if this_object.smtptls:
serv.ehlo()
serv.starttls()
serv.ehlo()
except Exception, error:
raise error
try:
if serv.has_extn('AUTH') or this_object.smtpuname or this_object.smtppass:
serv.login(str(this_object.smtpuname), str(this_object.smtppass))
except Exception, error:
raise error
return serv
raise Exception(_("SMTP SERVER or PORT not specified"))
raise Exception(_("Core connection for the given ID does not exist"))
def check_outgoing_connection(self, cursor, user, ids, context=None):
"""
checks SMTP credentials and confirms if outgoing connection works
(Attached to button)
@param cursor: Database Cursor
@param user: ID of current user
@param ids: list of ids of current object for
which connection is required
@param context: Context
"""
try:
self.get_outgoing_server(cursor, user, ids, context)
raise osv.except_osv(_("SMTP Test Connection Was Successful"), '')
except osv.except_osv, success_message:
raise success_message
except Exception, error:
raise osv.except_osv(
_("Out going connection test failed"),
_("Reason: %s") % error
)
def do_approval(self, cr, uid, ids, context=None):
#TODO: Check if user has rights
self.write(cr, uid, ids, {'state':'approved'}, context=context)
# wf_service = netsvc.LocalService("workflow")
def smtp_connection(self, cursor, user, id, context=None):
"""
This method should now wrap smtp_connection
"""
#This function returns a SMTP server object
logger = netsvc.Logger()
core_obj = self.browse(cursor, user, id, context=context)
if core_obj.smtpserver and core_obj.smtpport and core_obj.state == 'approved':
try:
serv = self.get_outgoing_server(cursor, user, id, context)
except Exception, error:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed on login. Probable Reason:Could not login to server\nError: %s") % (id, error))
return False
#Everything is complete, now return the connection
return serv
else:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id)
return False
#**************************** MAIL SENDING FEATURES ***********************#
def send_mail(self, cr, uid, ids, addresses, subject='', body=None, payload=None, message_id=None, context=None):
#TODO: Replace all this with a single email object
if body is None:
body = {}
if payload is None:
payload = {}
if context is None:
context = {}
logger = netsvc.Logger()
for id in ids:
core_obj = self.browse(cr, uid, id, context)
serv = self.smtp_connection(cr, uid, id)
if serv:
try:
# Prepare multipart containers depending on data
text_subtype = (core_obj.send_pref == 'alternative') and 'alternative' or 'mixed'
# Need a multipart/mixed wrapper for attachments if content is alternative
if payload and text_subtype == 'alternative':
payload_part = MIMEMultipart(_subtype='mixed')
text_part = MIMEMultipart(_subtype=text_subtype)
payload_part.attach(text_part)
else:
# otherwise a single multipart/mixed will do the whole job
payload_part = text_part = MIMEMultipart(_subtype=text_subtype)
if subject:
payload_part['Subject'] = subject
from_email = core_obj.email_id
if '<' in from_email:
# We have a structured email address, keep it untouched
payload_part['From'] = Header(core_obj.email_id, 'utf-8').encode()
else:
# Plain email address, construct a structured one based on the name:
sender_name = Header(core_obj.name, 'utf-8').encode()
payload_part['From'] = sender_name + " <" + core_obj.email_id + ">"
payload_part['Organization'] = tools.ustr(core_obj.user.company_id.name)
payload_part['Date'] = formatdate()
addresses_l = extract_emails_from_dict(addresses)
if addresses_l['To']:
payload_part['To'] = u','.join(addresses_l['To'])
if addresses_l['CC']:
payload_part['CC'] = u','.join(addresses_l['CC'])
if addresses_l['Reply-To']:
payload_part['Reply-To'] = addresses_l['Reply-To'][0]
if message_id:
payload_part['Message-ID'] = message_id
if body.get('text', False):
temp_body_text = body.get('text', '')
l = len(temp_body_text.replace(' ', '').replace('\r', '').replace('\n', ''))
if l == 0:
body['text'] = u'No Mail Message'
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
if core_obj.send_pref in ('text', 'mixed', 'alternative'):
body_text = body.get('text', u'<Empty Message>')
body_text = tools.ustr(body_text)
text_part.attach(MIMEText(body_text.encode("utf-8"), _charset='UTF-8'))
if core_obj.send_pref in ('html', 'mixed', 'alternative'):
html_body = body.get('html', u'')
if len(html_body) == 0 or html_body == u'':
html_body = body.get('text', u'<p>&lt;Empty Message&gt;</p>').replace('\n', '<br/>').replace('\r', '<br/>')
html_body = tools.ustr(html_body)
text_part.attach(MIMEText(html_body.encode("utf-8"), _subtype='html', _charset='UTF-8'))
#Now add attachments if any, wrapping into a container multipart/mixed if needed
if payload:
for file in payload:
part = MIMEBase('application', "octet-stream")
part.set_payload(base64.decodestring(payload[file]))
part.add_header('Content-Disposition', 'attachment; filename="%s"' % file)
Encoders.encode_base64(part)
payload_part.attach(part)
except Exception, error:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:MIME Error\nDescription: %s") % (id, error))
return {'error_msg': _("Server Send Error\nDescription: %s")%error}
try:
serv.sendmail(payload_part['From'], addresses_l['all-recipients'], payload_part.as_string())
except Exception, error:
logging.getLogger('email_template').error(_("Mail from Account %s failed. Probable Reason: Server Send Error\n Description: %s"), id, error, exc_info=True)
return {'error_msg': _("Server Send Error\nDescription: %s")%error}
#The mail sending is complete
serv.close()
logger.notifyChannel(_("Email Template"), netsvc.LOG_INFO, _("Mail from Account %s successfully Sent.") % (id))
return True
else:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id)
return {'nodestroy':True,'error_msg': _("Mail from Account %s failed. Probable Reason:Account not approved")% id}
def extracttime(self, time_as_string):
"""
TODO: DOC THis
"""
logger = netsvc.Logger()
#The standard email dates are of format similar to:
#Thu, 8 Oct 2009 09:35:42 +0200
date_as_date = False
convertor = {'+':1, '-':-1}
try:
time_as_string = time_as_string.replace(',', '')
date_list = time_as_string.split(' ')
date_temp_str = ' '.join(date_list[1:5])
if len(date_list) >= 6:
sign = convertor.get(date_list[5][0], False)
else:
sign = False
try:
dt = datetime.datetime.strptime(
date_temp_str,
"%d %b %Y %H:%M:%S")
except:
try:
dt = datetime.datetime.strptime(
date_temp_str,
"%d %b %Y %H:%M")
except:
return False
if sign:
try:
offset = datetime.timedelta(
hours=sign * int(
date_list[5][1:3]
),
minutes=sign * int(
date_list[5][3:5]
)
)
except Exception, e2:
"""Looks like UT or GMT, just forget decoding"""
return False
else:
offset = datetime.timedelta(hours=0)
dt = dt + offset
date_as_date = dt.strftime('%Y-%m-%d %H:%M:%S')
except Exception, e:
logger.notifyChannel(
_("Email Template"),
netsvc.LOG_WARNING,
_(
"Datetime Extraction failed.Date:%s \
\tError:%s") % (
time_as_string,
e)
)
return date_as_date
def send_receive(self, cr, uid, ids, context=None):
for id in ids:
ctx = context.copy()
ctx['filters'] = [('account_id', '=', id)]
self.pool.get('email_template.mailbox').send_all_mail(cr, uid, [], context=ctx)
return True
def decode_header_text(self, text):
""" Decode internationalized headers RFC2822.
To, CC, BCC, Subject fields can contain
text slices with different encodes, like:
=?iso-8859-1?Q?Enric_Mart=ED?= <enricmarti@company.com>,
=?Windows-1252?Q?David_G=F3mez?= <david@company.com>
Sometimes they include extra " character at the beginning/
end of the contact name, like:
"=?iso-8859-1?Q?Enric_Mart=ED?=" <enricmarti@company.com>
and decode_header() does not work well, so we use regular
expressions (?= ? ? ?=) to split the text slices
"""
if not text:
return text
p = re.compile("(=\?.*?\?.\?.*?\?=)")
text2 = ''
try:
for t2 in p.split(text):
text2 += ''.join(
[s.decode(
t or 'ascii'
) for (s, t) in decode_header(t2)]
).encode('utf-8')
except:
return text
return text2
email_template_account()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,124 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<menuitem name="Marketing" icon="terp-crm" id="base.marketing_menu" sequence="17"
groups="marketing.group_marketing_user,marketing.group_marketing_manager"/>
<menuitem name="Emails" id="base.menu_emails" parent="base.marketing_menu" sequence="5"/>
<menuitem name="Email Template" id="menu_email_template" parent="base.menu_emails"/>
<record model="ir.ui.view" id="email_template_account_form">
<field name="name">email_template.account.form</field>
<field name="model">email_template.account</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Account Configuration">
<group colspan="2">
<field name="name" select="1" />
</group>
<notebook colspan="4">
<page string="Outgoing">
<separator string="Server Information" colspan="4" />
<group colspan="4" col="4">
<field name="smtpserver" select="1"/>
<button name="check_outgoing_connection" type="object" string="Test Outgoing Connection" icon="gtk-network" colspan="2"/>
<field name="smtpport" select="2" />
<field name="smtpssl" select="2" />
<field name="smtptls" select="2" />
<field name="auto_delete" />
</group>
<separator string="User Information" colspan="4" />
<group col="2" colspan="2">
<field name="email_id" select="1" colspan="2" />
<field name="smtppass" password="True" colspan="2" />
<field name="company" select="2" colspan="2" />
</group>
<group col="2" colspan="2">
<field name="smtpuname" select="1" colspan="2" />
<field name="user" select="2" colspan="2" />
<field name="send_pref" colspan="2" />
</group>
</page>
</notebook>
<group colspan="4" col="10">
<field name="state" select="1"/>
<button string="Approve Account" name="button_approval" states="draft" type="workflow" icon="terp-camera_test"/>
<button string="Suspend Account" name="button_suspended" states="approved" type="workflow" icon="gtk-cancel"/>
<button string="Request Re-activation" name="get_reapprove" states="suspended" type="workflow" icon="gtk-convert"/>
<button string="Send/Receive" name="send_receive" states="approved" type="object" icon="terp-check"/>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="email_template_account_tree">
<field name="name">email_template.account.tree</field>
<field name="model">email_template.account</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree colors="blue:state in ('draft');black:state in ('suspended','approved')" string="Email Accounts">
<field name="name" />
<field name="email_id" />
<field name="smtpuname" />
<field name="user" />
<field name="smtpserver" />
<field name="smtpport" />
<field name="auto_delete" />
<field name="state" />
</tree>
</field>
</record>
<record id="view_email_template_account_search" model="ir.ui.view">
<field name="name">email_template.account.search</field>
<field name="model">email_template.account</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Email Accounts">
<filter icon="terp-document-new" string="Draft" name="draft" domain="[('state','=','draft')]"/>
<filter icon="terp-camera_test" string="Approved" domain="[('state','=','approved')]"/>
<filter icon="terp-emblem-important" string="Suspended" domain="[('state','=','suspended')]"/>
<separator orientation="vertical"/>
<filter icon="terp-go-home" string="Company Accounts" domain="[('company','=','yes')]"/>
<separator orientation="vertical"/>
<field name="user" select="1">
<filter icon="terp-personal" help="My Accounts" name="my" domain="[('user','=',uid)]"/>
</field>
<field name="name" select="1"/>
<field name="email_id" select="1"/>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_email_template_account_tree_all">
<field name="name">Accounts</field>
<field name="res_model">email_template.account</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="email_template_account_tree" />
<field name="context">{'search_default_draft': 1, 'search_default_my': 1}</field>
<field name="search_view_id" ref="view_email_template_account_search"/>
</record>
<menuitem name="Configuration" parent="base.marketing_menu"
id="base.menu_marketing_config_root" sequence="20" groups="base.group_system"/>
<menuitem name="Email Template" id="menu_email_template_configuration" parent="base.menu_marketing_config_root" />
<menuitem name="Email Accounts" id="menu_email_template_account_all" parent="menu_email_template_configuration" action="action_email_template_account_tree_all"/>
<menuitem name="Configuration" parent="base.menu_tools"
id="base.menu_lunch_survey_root" sequence="20" />
<menuitem name="Email Template" id="menu_email_template_config_tools"
parent="base.menu_lunch_survey_root" />
<menuitem name="Email Accounts" id="menu_email_account_all_tools"
parent="menu_email_template_config_tools" action="action_email_template_account_tree_all" />
</data>
</openerp>

View File

@ -1,214 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# Copyright (C) 2004-2010 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, fields
import time
import netsvc
from tools.translate import _
import tools
LOGGER = netsvc.Logger()
class email_template_mailbox(osv.osv):
_name = "email_template.mailbox"
_description = 'Email Mailbox'
_rec_name = "subject"
_order = "date_mail desc"
def run_mail_scheduler(self, cursor, user, context=None):
"""
This method is called by OpenERP Scheduler
to periodically send emails
"""
try:
self.send_all_mail(cursor, user, context=context)
except Exception, e:
LOGGER.notifyChannel(
"Email Template",
netsvc.LOG_ERROR,
_("Error sending mail: %s") % e)
def send_all_mail(self, cr, uid, ids=None, context=None):
if ids is None:
ids = []
if context is None:
context = {}
filters = [('folder', '=', 'outbox'), ('state', '!=', 'sending')]
if 'filters' in context.keys():
for each_filter in context['filters']:
filters.append(each_filter)
ids = self.search(cr, uid, filters, context=context)
self.write(cr, uid, ids, {'state':'sending'}, context)
self.send_this_mail(cr, uid, ids, context)
return True
def send_this_mail(self, cr, uid, ids=None, context=None):
#previous method to send email (link with email account can be found at the revision 4172 and below
result = True
attachment_pool = self.pool.get('ir.attachment')
for id in (ids or []):
try:
account_obj = self.pool.get('email_template.account')
values = self.read(cr, uid, id, [], context)
payload = {}
if values['attachments_ids']:
for attid in values['attachments_ids']:
attachment = attachment_pool.browse(cr, uid, attid, context)#,['datas_fname','datas'])
payload[attachment.datas_fname] = attachment.datas
result = account_obj.send_mail(cr, uid,
[values['account_id'][0]],
{'To':values.get('email_to') or u'',
'CC':values.get('email_cc') or u'',
'BCC':values.get('email_bcc') or u'',
'Reply-To':values.get('reply_to') or u''},
values['subject'] or u'',
{'text':values.get('body_text') or u'', 'html':values.get('body_html') or u''},
payload=payload,
message_id=values['message_id'],
context=context)
if result == True:
account = account_obj.browse(cr, uid, values['account_id'][0], context=context)
if account.auto_delete:
self.write(cr, uid, id, {'folder': 'trash'}, context=context)
self.unlink(cr, uid, [id], context=context)
# Remove attachments for this mail
attachment_pool.unlink(cr, uid, values['attachments_ids'], context=context)
return result
else:
self.write(cr, uid, id, {'folder':'sent', 'state':'na', 'date_mail':time.strftime("%Y-%m-%d %H:%M:%S")}, context)
self.historise(cr, uid, [id], "Email sent successfully", context)
else:
error = result['error_msg']
self.historise(cr, uid, [id], error, context)
except Exception, error:
logger = netsvc.Logger()
logger.notifyChannel("email-template", netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (id, error))
self.historise(cr, uid, [id], error, context)
self.write(cr, uid, id, {'state':'na'}, context)
return result
def historise(self, cr, uid, ids, message='', context=None):
for id in ids:
history = self.read(cr, uid, id, ['history'], context).get('history', '')
self.write(cr, uid, id, {'history': (history or '' )+ "\n" + time.strftime("%Y-%m-%d %H:%M:%S") + ": " + tools.ustr(message)}, context)
_columns = {
'email_from':fields.char(
'From',
size=64),
'email_to':fields.char(
'Recipient (To)',
size=250,),
'email_cc':fields.char(
'CC',
size=250),
'email_bcc':fields.char(
'BCC',
size=250),
'reply_to':fields.char(
'Reply-To',
size=250),
'message_id':fields.char(
'Message-ID',
size=250),
'subject':fields.char(
'Subject',
size=200,),
'body_text':fields.text(
'Standard Body (Text)'),
'body_html':fields.text(
'Body (Rich Text Clients Only)'),
'attachments_ids':fields.many2many(
'ir.attachment',
'mail_attachments_rel',
'mail_id',
'att_id',
'Attachments'),
'account_id' :fields.many2one(
'email_template.account',
'User account',
required=True),
'user':fields.related(
'account_id',
'user',
type="many2one",
relation="res.users",
string="User"),
'server_ref':fields.integer(
'Server Reference of mail',
help="Applicable for inward items only"),
'mail_type':fields.selection([
('multipart/mixed',
'Has Attachments'),
('multipart/alternative',
'Plain Text & HTML with no attachments'),
('multipart/related',
'Intermixed content'),
('text/plain',
'Plain Text'),
('text/html',
'HTML Body'),
], 'Mail Contents'),
#I like GMAIL which allows putting same mail in many folders
#Lets plan it for 0.9
'folder':fields.selection([
('drafts', 'Drafts'),
('outbox', 'Outbox'),
('trash', 'Trash'),
('sent', 'Sent Items'),
], 'Folder', required=True),
'state':fields.selection([
('na', 'Not Applicable'),
('sending', 'Sending'),
], 'Status', required=True),
'date_mail':fields.datetime('Rec/Sent Date', help="Date on which Email Sent or Received"),
'history':fields.text(
'History',
readonly=True,
store=True)
}
_defaults = {
'state': lambda * a: 'na',
'folder': lambda * a: 'outbox',
}
def unlink(self, cr, uid, ids, context=None):
"""
It just changes the folder of the item to "Trash", if it is no in Trash folder yet,
or completely deletes it if it is already in Trash.
"""
to_update = []
to_remove = []
for mail in self.browse(cr, uid, ids, context=context):
if mail.folder == 'trash':
to_remove.append(mail.id)
else:
to_update.append(mail.id)
# Changes the folder to trash
self.write(cr, uid, to_update, {'folder': 'trash'}, context=context)
return super(email_template_mailbox, self).unlink(cr, uid, to_remove, context=context)
email_template_mailbox()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,134 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- Email Template-->
<record model="ir.ui.view" id="email_template_mailbox_form">
<field name="name">email_template.mailbox.form</field>
<field name="model">email_template.mailbox</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Emails">
<group col="4" colspan="4" name="headers">
<field name="email_from" select="1"/>
<field name="email_to" required="1" select="1" />
<field name="reply_to" select="2"/>
<field name="email_cc" select="1"/>
<field name="email_bcc" select="2"/>
<field name="date_mail" select="2"/>
<field name="subject" colspan="4" select="1"/>
</group>
<notebook colspan="4">
<page string="Standard Body">
<separator colspan="4" string="Standard Body" />
<notebook colspan="4">
<page string="Standard Body (Text)">
<field name="body_text" nolabel="1" colspan="4" select="1"/>
</page>
<page string="Body (HTML-Web Client Only)">
<field name="body_html" nolabel="1" colspan="4" />
</page>
</notebook>
<separator colspan="4" string="" />
<group col="4" colspan="4">
<field name="state" readonly="1" string="State"/>
<button name="send_this_mail" type="object" string="Send Mail" icon="terp-mail-message-new"/>
</group>
</page>
<page string="Attachments">
<separator colspan="4" string="Attachments" />
<field name="attachments_ids" colspan="4" nolabel="1" />
</page>
<page string="Advanced">
<field name="account_id" colspan="2" />
<field name="server_ref" colspan="2" />
<field name="mail_type" colspan="2" />
<field name="folder" colspan="2" select="2"/>
<field name="message_id" select="2"/>
<separator string="History" colspan="4" />
<field name="history" nolabel="1" colspan="4"/>
</page>
</notebook>
</form>
</field>
</record>
<!--============================================= TREE VIEWS =============================================-->
<record id="view_email_template_mailbox_tree" model="ir.ui.view">
<field name="name">email_template.mailbox.tree</field>
<field name="model">email_template.mailbox</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Emails" colors="blue:folder=='drafts';grey:folder=='trash'">
<field name="subject" select="1" />
<field name="user" />
<field name="email_from" select="1" />
<field name="email_to"/>
<field name="date_mail" select="2" />
<field name="attachments_ids" select="2" />
<field name="folder" invisible="1"/>
</tree>
</field>
</record>
<record id="view_email_template_mailbox_search" model="ir.ui.view">
<field name="name">email_template.mailbox.search</field>
<field name="model">email_template.mailbox</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Emails">
<filter icon="terp-document-new" string="Drafts" name="draft" domain="[('folder','=','drafts')]"/>
<filter icon="terp-mail-" string="Outbox" name="outbox" domain="[('folder','=','outbox')]"/>
<filter icon="terp-camera_test" string="Sent" domain="[('folder','=','sent')]"/>
<filter icon="terp-mail_delete" string="Trash" domain="[('folder','=','trash')]"/>
<separator orientation="vertical"/>
<filter icon="terp-personal+" string="Personal Emails" name="personal" domain="[('account_id.company','=','no')]"/>
<filter icon="terp-go-home" string="Company Emails" name="company" domain="[('account_id.company','=','yes')]"/>
<separator orientation="vertical"/>
<field name="subject"/>
<field name="email_from"/>
<field name="user">
<filter icon="terp-personal"
string="My Emails" help="My Emails" name="myemails"
domain="[('account_id.user','=', uid)]" />
</field>
<newline/>
<field name="email_to"/>
<field name="date_mail"/>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_email_template_mailbox">
<field name="name">Emails</field>
<field name="res_model">email_template.mailbox</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_email_template_mailbox_tree" />
<field name="context">{'search_default_outbox': 1}</field>
<field name="help">An email template is an email document that will be sent as part of a marketing campaign. You can personalize it according to specific customer profile fields, so that a partner name or other partner related information may be inserted automatically.</field>
<field name="search_view_id" ref="view_email_template_mailbox_search"/>
</record>
<!--======================================== MENUS ========================================-->
<menuitem name="Emails"
id="menu_email_template_personal_mails"
parent="menu_email_template"
action="action_email_template_mailbox" />
<!-- Mailbox menu in Tools -->
<menuitem name="Email Template" id="menu_email_template_tools"
parent="base.menu_tools" />
<menuitem name="Emails"
id="menu_email_template_mails_tools"
parent="menu_email_template_tools"
action="action_email_template_mailbox" />
</data>
</openerp>

View File

@ -1,115 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- Email Template Preview -->
<record model="ir.ui.view" id="email_template_preview_form">
<field name="name">email_template.preview.form</field>
<field name="model">email_template.preview</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Preview">
<group col="4" colspan="4">
<field name="rel_model" />
<field name="rel_model_ref" on_change="on_change_ref(rel_model_ref, context)"/>
</group>
<group col="8" colspan="4">
<field name="to" />
<field name="cc" />
<field name="bcc" />
<field name="reply_to" />
<field name="message_id" attrs="{'invisible':[('message_id','=',False)]}" groups="base.group_extended"/>
<field name="subject" colspan="8"/>
</group>
<group col="4" colspan="4">
<separator string= "Body(Text)" colspan="2"/>
<separator string= "Body(Html)" colspan="2"/>
<newline/>
<field name="body_text" nolabel="1" colspan="2"/>
<field name="body_html" nolabel="1" colspan="2"/>
</group>
<field name="report" colspan="2"/>
<button icon="gtk-ok" special="cancel" string="OK" colspan="1"/>
</form>
</field>
</record>
<record id="wizard_email_template_preview" model="ir.actions.act_window">
<field name="name">Template Preview</field>
<field name="res_model">email_template.preview</field>
<field name="src_model">email_template.preview</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="auto_refresh" eval="1" />
<field name="target">new</field>
<field name="context">{'template_id':active_id}</field>
</record>
<!--EMail client Form view -->
<record model="ir.ui.view" id="email_template_form">
<field name="name">email.template.form</field>
<field name="model">email.template</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Templates">
<field name="name" />
<field name="object_name" required="1"
on_change="change_model(object_name)" />
<field name="model_int_name" invisible="1" />
<form string="Templates">
<field name="name" required="1"/>
<field name="model_id" required="1"
on_change="onchange_model_id(model_id)"/>
<field name="model" invisible="1"/>
<notebook colspan="4">
<page string="Mail Details">
<page string="Email Details">
<group col="2" colspan="2">
<separator string="Addresses" colspan="2"/>
<field name="from_account" required="1"/>
<field name="def_to" required="1"/>
<field name="def_cc"/>
<field name="def_bcc"/>
<field name="smtp_server_id"/>
<field name="email_to" required="1"/>
<field name="email_cc"/>
<field name="email_bcc"/>
<field name="reply_to"/>
</group>
<group col="2" colspan="2">
<separator string="Options" colspan="2"/>
<field name="lang" colspan="4" />
<field name="use_sign" colspan="4" />
<field name="user_signature" colspan="4" />
<field name="track_campaign_item" colspan="4"/>
</group>
<group col="2" colspan="2">
<separator colspan="2" string="Email Content " />
<field name="def_subject" colspan="4" required="1" />
<separator colspan="2" string="Email Content"/>
<field name="subject" colspan="4" required="1"/>
<notebook>
<page string="Body (Text)">
<field name="def_body_text" colspan="4" nolabel="1" />
</page>
<page string="Body (Raw HTML)">
<field name="def_body_html" colspan="4" nolabel="1" />
<label string="Note: This is Raw HTML." colspan="4" />
<page string="Body">
<field name="body" colspan="4" nolabel="1"/>
</page>
<!-- <page string="Body (Raw HTML)">
<field name="def_body_html" colspan="4" nolabel="1"/>
<label string="Note: This is Raw HTML." colspan="4"/>
</page> -->
</notebook>
</group>
<group col="4" colspan="2">
<separator colspan="4" string="Expression Builder" />
<field name="template_language"
on_change="onchange_null_value(model_object_field,sub_model_object_field,null_value,template_language,context)" />
<notebook>
<page string="Insert Simple Field">
<field name="model_object_field"
domain="[('model_id','=',object_name),('ttype','!=','one2many'),('ttype','!=','many2many')]"
on_change="onchange_model_object_field(model_object_field, template_language,context)"
colspan="4" />
<field name="sub_object" readonly="1" colspan="4" />
domain="[('model_id','=',model_id),('ttype','!=','one2many'),('ttype','!=','many2many')]"
on_change="onchange_sub_model_object_value_field(model_object_field)"
colspan="4"/>
<field name="sub_object" readonly="1" colspan="4"/>
<field name="sub_model_object_field"
domain="[('model_id','=',sub_object),('ttype','!=','one2many'),('ttype','!=','many2many')]"
colspan="4"
attrs="{'readonly':[('sub_object','=',False)],'required':[('sub_object','!=',False)]}"
on_change="onchange_sub_model_object_field(model_object_field,sub_model_object_field,template_language,context)" />
on_change="onchange_sub_model_object_value_field(model_object_field,sub_model_object_field)"/>
<field name="null_value" colspan="4"
on_change="onchange_null_value(model_object_field,sub_model_object_field,null_value,template_language,context)" />
<field name="copyvalue" colspan="4" />
on_change="onchange_sub_model_object_value_field(model_object_field,sub_model_object_field,null_value)" />
<field name="copyvalue" colspan="4"/>
</page>
</notebook>
<button name="%(wizard_email_template_preview)d" string="Preview Template"
type="action" colspan="4" target="new" icon="gtk-zoom-fit"/>
type="action" colspan="4" target="new" icon="gtk-zoom-fit" context="{'template_id':active_id}"/>
</group>
</page>
<page string="Advanced">
@ -119,11 +70,12 @@
<button name="create_action" string="Create Action" type="object" icon="gtk-execute" colspan="2" attrs="{'invisible':[('ref_ir_act_window','!=',False), ('ref_ir_value','!=',False)]}"/>
<field name="ref_ir_act_window"/>
<field name="ref_ir_value"/>
<button name="delete_action" string="Delete Action" type="object" icon="gtk-delete" colspan="2" attrs="{'invisible':[('ref_ir_act_window','=',False), ('ref_ir_value','=',False)]}"/>
<button name="unlink_action" string="Delete Action" type="object" icon="gtk-delete" colspan="2" attrs="{'invisible':[('ref_ir_act_window','=',False), ('ref_ir_value','=',False)]}"/>
</group>
<group colspan="2" col="2">
<separator string="Advanced Options" colspan="2"/>
<field name="message_id"/>
<field name="auto_delete"/>
</group>
</group>
<group colspan="2" col="2">
@ -134,8 +86,8 @@
</page>
<page string="Report">
<field name="report_template" colspan="4"
domain="[('model','=',model_int_name)]" />
<field name="file_name" colspan="4" />
domain="[('model','=',model)]"/>
<field name="report_name" colspan="4" />
</page>
</notebook>
</group>
@ -150,16 +102,16 @@
<field name="model">email.template</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Email Templates">
<tree string="Templates">
<field name="name"/>
<field name="from_account"/>
<field name="object_name"/>
<field name="def_to"/>
<field name="def_cc"/>
<field name="def_bcc"/>
<field name="def_subject"/>
<field name="use_sign"/>
<field name="file_name"/>
<field name="smtp_server_id"/>
<field name="model_id"/>
<field name="email_to"/>
<field name="email_cc"/>
<field name="email_bcc"/>
<field name="subject"/>
<field name="user_signature"/>
<field name="report_name"/>
<button name="%(wizard_email_template_preview)d" string="Preview Template"
type="action" target="new" icon="gtk-zoom-fit"/>
</tree>
@ -173,26 +125,26 @@
<field name="arch" type="xml">
<search string="Templates">
<group col="13" colspan="4">
<field name="name" select="1"/>
<field name="object_name" select="1"/>
<field name="def_to" select="1"/>
<field name="name"/>
<field name="model_id"/>
<field name="email_to"/>
<separator orientation="vertical"/>
<field name="lang" select="1"/>
<field name="def_subject" select="1"/>
<field name="file_name" select="1"/>
<field name="lang"/>
<field name="subject"/>
<field name="report_name"/>
</group>
<newline/>
<group expand="0" string="Group by..." colspan="4" col="10">
<filter string="Account" domain="[]" context="{'group_by':'from_account'}" icon="terp-folder-orange"/>
<filter string="SMTP Server" domain="[]" context="{'group_by':'smtp_server_id'}" icon="terp-folder-orange"/>
<separator orientation="vertical"/>
<filter string="Resource" domain="[]" context="{'group_by':'object_name'}" icon="terp-accessories-archiver"/>
<filter string="Model" domain="[]" context="{'group_by':'model_id'}" icon="terp-accessories-archiver"/>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_email_template_tree_all">
<field name="name">Email Templates</field>
<field name="name">Templates</field>
<field name="res_model">email.template</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
@ -200,16 +152,8 @@
<field name="search_view_id" ref="view_email_template_search"/>
</record>
<menuitem name="Email Templates" id="menu_email_template_all"
parent="menu_email_template" action="action_email_template_tree_all" />
<menuitem name="Templates" id="menu_email_template_all_tools"
parent="mail.menu_email_message_tools" action="action_email_template_tree_all" />
<!-- Email Template menu in Tools -->
<menuitem name="Email Templates" id="menu_email_template_all_tools"
parent="menu_email_template_config_tools" action="action_email_template_tree_all" />
</data>
</openerp>

View File

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="wkf_email_template_setting" model="workflow">
<field name="name">Email Template Workflow</field>
<field name="osv">email_template.account</field>
<field name="on_create">True</field>
</record>
<!--Activity -->
<record id="act_draft" model="workflow.activity">
<field name="wkf_id" ref="wkf_email_template_setting"/>
<field name="flow_start">True</field>
<field name="name">draft</field>
<field name="kind">function</field>
<field name="action">write({'state':'draft'})</field>
</record>
<record id="act_approved" model="workflow.activity">
<field name="name">approval</field>
<field name="wkf_id" ref="wkf_email_template_setting"/>
<field name="kind">function</field>
<field name="action">do_approval()</field>
</record>
<record id="act_suspended" model="workflow.activity">
<field name="name">suspended</field>
<field name="wkf_id" ref="wkf_email_template_setting"/>
<field name="kind">function</field>
<field name="action">write({'state':'suspended'})</field>
</record>
<record id="act_dummy" model="workflow.activity">
<field name="name">dummy</field>
<field name="wkf_id" ref="wkf_email_template_setting"/>
<field name="flow_stop">True</field>
</record>
<!-- Transition -->
<record id="trans_awaiting_approved" model="workflow.transition">
<field name="act_from" ref="act_draft"/>
<field name="act_to" ref="act_approved"/>
<field name="signal">button_approval</field>
</record>
<record id="trans_approved_suspended" model="workflow.transition">
<field name="act_from" ref="act_approved"/>
<field name="act_to" ref="act_suspended"/>
<field name="signal">button_suspended</field>
</record>
<record id="trans_suspended_reapproved" model="workflow.transition">
<field name="act_from" ref="act_suspended"/>
<field name="act_to" ref="act_draft"/>
<field name="signal">get_reapprove</field>
</record>
<record id="trans_suspended_dummy" model="workflow.transition">
<field name="act_from" ref="act_suspended"/>
<field name="act_to" ref="act_dummy"/>
<field name="signal">get_never</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# 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/>
#
##############################################################################
import tools
from tools.translate import _
import pooler
import logging
try:
from mako.template import Template as MakoTemplate
except ImportError:
logging.getLogger('init').warning("module email_template: Mako templates not installed")
def get_value(cr, uid, message=None, model=None, record_id=False, context=None):
"""
returns Messages in Mako Template
"""
pool = pooler.get_pool(cr.dbname)
if message is None:
message = {}
#Returns the computed expression
if message:
try:
message = tools.ustr(message)
record = pool.get(model).browse(cr, uid, record_id, context=context)
env = {
'user': pool.get('res.users').browse(cr, uid, uid, context=context),
'db': cr.dbname
}
templ = MakoTemplate(message, input_encoding='utf-8')
reply = MakoTemplate(message).render_unicode(object=record, peobject=record, env=env, format_exceptions=True)
return reply or False
except Exception:
logging.exception("can't render %r", message)
return u""
else:
return message
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
</data>
</openerp>

View File

@ -1,10 +1,4 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_email_template_account","email_template.account","model_email_template_account","marketing.group_marketing_user",1,0,0,0
"access_email_template","email.template","model_email_template","marketing.group_marketing_user",1,0,0,0
"access_email_template_mailbox","email_template.mailbox","model_email_template_mailbox","marketing.group_marketing_user",1,1,1,1
"access_email_template_account_system","email_template.account system","model_email_template_account","base.group_system",1,1,1,1
"access_email_template","email.template","model_email_template",,1,0,0,0
"access_email_template_system","email.template system","model_email_template","base.group_system",1,1,1,1
"access_email_template_mailbox_system","email_template.mailbox system","model_email_template_mailbox","base.group_system",1,0,0,0
"access_email_template_account_manager","email_template.account","model_email_template_account","marketing.group_marketing_manager",1,1,1,1
"access_email_template_manager","email.template","model_email_template","marketing.group_marketing_manager",1,1,1,1
"access_email_template_mailbox_manager","email_template.mailbox","model_email_template_mailbox","marketing.group_marketing_manager",1,1,1,1
"access_email_template_manager","email.template","model_email_template",,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_email_template_account access_email_template email_template.account email.template model_email_template_account model_email_template marketing.group_marketing_user 1 0 0 0
access_email_template email.template model_email_template marketing.group_marketing_user 1 0 0 0
access_email_template_mailbox email_template.mailbox model_email_template_mailbox marketing.group_marketing_user 1 1 1 1
access_email_template_account_system email_template.account system model_email_template_account base.group_system 1 1 1 1
3 access_email_template_system email.template system model_email_template base.group_system 1 1 1 1
4 access_email_template_mailbox_system access_email_template_manager email_template.mailbox system email.template model_email_template_mailbox model_email_template base.group_system 1 0 1 0 1 0 1
access_email_template_account_manager email_template.account model_email_template_account marketing.group_marketing_manager 1 1 1 1
access_email_template_manager email.template model_email_template marketing.group_marketing_manager 1 1 1 1
access_email_template_mailbox_manager email_template.mailbox model_email_template_mailbox marketing.group_marketing_manager 1 1 1 1

View File

@ -3,7 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# Copyright (C) 2010-2010 OpenERP SA (<http://www.openerp.com>)
# 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
@ -19,5 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
import email_template_preview
import email_template_send_wizard
import email_compose_message

View File

@ -0,0 +1,145 @@
# -*- 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
class email_compose_message(osv.osv_memory):
_name = 'email.compose.message'
_inherit = 'email.compose.message'
def get_template_data(self, cr, uid, res_id, template_id, context=None):
if context is None:
context = {}
result = {}
template_pool = self.pool.get('email.template')
if template_id:
template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context)
def _get_template_value(field):
if not template:
return False
if len(context.get('src_rec_ids',[])) > 1: # Multiple Mail: Gets original template values for multiple email change
return getattr(template, field)
else: # Simple Mail: Gets computed template values
return template_pool.get_template_value(cr, uid, getattr(template, field), template.model, context.get('email_res_id'), context)
result.update({
'template_id' : template.id,
'smtp_server_id' : template.smtp_server_id.id,
'body' : _get_template_value('body') or False,
'subject' : _get_template_value('subject') or False,
'attachment_ids' : template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] or [],
'res_id' : res_id or False,
'email_to' : _get_template_value('email_to') or False,
'email_cc' : _get_template_value('email_cc') or False,
'email_bcc' : _get_template_value('email_bcc') or False,
'reply_to' : _get_template_value('reply_to') or False,
'model' : template.model or False,
})
return result
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
result = super(email_compose_message, self).default_get(cr, uid, fields, context=context)
template_id = context.get('template_id', False)
vals = {}
if template_id and context.get('email_model') and context.get('email_res_id'):
vals = self.get_template_data(cr, uid, context.get('email_res_id'), template_id, context)
if not vals:
return result
if 'template_id' in fields:
result.update({'template_id' : vals.get('template_id', False)})
if 'smtp_server_id' in fields:
result.update({'smtp_server_id' : vals.get('smtp_server_id', False)})
if 'attachment_ids' in fields:
result.update({'attachment_ids' : vals.get('attachment_ids', False)})
if 'model' in fields:
result.update({'model' : vals.get('model', False)})
if 'res_id' in fields:
result.update({'res_id' : vals.get('res_id', False)})
if 'email_to' in fields:
result.update({'email_to' : vals.get('email_to', False)})
if 'email_cc' in fields:
result.update({'email_cc' : vals.get('email_cc', False)})
if 'email_bcc' in fields:
result.update({'email_bcc' : vals.get('email_bcc', False)})
if 'subject' in fields:
result.update({'subject' : vals.get('name', False)})
if 'body' in fields:
result.update({'body' : vals.get('body', False)})
if 'reply_to' in fields:
result.update({'reply_to' : vals.get('reply_to', False)})
return result
def _get_templates(self, cr, uid, context=None):
"""
Return Email Template of particular Model.
"""
if context is None:
context = {}
record_ids = []
email_temp_pool = self.pool.get('email.template')
model = False
if context.get('message_id'):
message_pool = self.pool.get('email.message')
message_data = message_pool.browse(cr, uid, int(context.get('message_id')), context)
model = message_data.model
elif context.get('email_model',False):
model = context.get('email_model')
if model:
record_ids = email_temp_pool.search(cr, uid, [('model','=',model)])
return email_temp_pool.name_get(cr, uid, record_ids, context) + [(False,'')]
return []
_columns = {
'template_id': fields.selection(_get_templates, 'Template'),
}
def on_change_template(self, cr, uid, ids, model, resource_id, template_id, context=None):
if context is None:
context = {}
if context.get('mail') == 'reply':
return {'value':{}}
result = self.on_change_referred_doc(cr, uid, [], model, resource_id, context=context)
vals = result.get('value',{})
if template_id and resource_id:
vals.update(self.get_template_data(cr, uid, resource_id, template_id, context))
else:
vals.update({'attachment_ids' : []})
return {'value': vals}
email_compose_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="email_compose_message_wizard_inherit_form">
<field name="name">email.compose.message.form</field>
<field name="model">email.compose.message</field>
<field name="type">form</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<field name="res_id" position="replace">
<field name="template_id" colspan="4"
on_change="on_change_template(model, res_id, template_id, context)"/>
<field name="res_id"
invisible="context.get('active_model','') != 'ir.ui.menu'"
colspan="4" on_change="on_change_template(model, res_id, template_id, context)"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,108 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# 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, fields
from tools.translate import _
import tools
class email_template_preview(osv.osv_memory):
_inherit = "email.template"
_name = "email_template.preview"
_description = "Email Template Preview"
_rec_name = "subject"
def _get_records(self, cr, uid, context=None):
"""
Return Records of particular Email Template's Model
"""
if context is None:
context = {}
template_id = context.get('template_id', False)
if not template_id:
return []
template_pool = self.pool.get('email.template')
model_pool = self.pool.get('ir.model')
template = template_pool.browse(cr, uid, int(template_id), context=context)
template_object = template.model_id
model = self.pool.get(template_object.model)
record_ids = model.search(cr, uid, [], 0, 20, 'id', context=context)
default_id = context.get('default_res_id')
if default_id and default_id not in record_ids:
record_ids.insert(0, default_id)
return model.name_get(cr, uid, record_ids, context)
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
result = super(email_template_preview, self).default_get(cr, uid, fields, context=context)
template_pool = self.pool.get('email.template')
template_id = context.get('template_id',False)
if 'res_id' in fields:
records = self._get_records(cr, uid, context=context)
result['res_id'] = records and records[0][0] or False # select first record as a Default
if template_id and 'model_id' in fields:
result['model_id'] = template_pool.read(cr, uid, int(template_id), ['model_id'], context).get('model_id', False)
return result
_columns = {
'res_id':fields.selection(_get_records, 'Referred Document'),
}
_defaults = {
}
def on_change_ref(self, cr, uid, ids, res_id, context=None):
if context is None:
context = {}
if not res_id:
return {}
vals = {}
if context == {}:
context = self.context
template_pool = self.pool.get('email.template')
template_id = context.get('template_id', False)
template = template_pool.get_email_template(cr, uid, template_id=template_id, record_id=res_id, context=context)
model = template.model
vals['email_to'] = self.get_template_value(cr, uid, template.email_to, model, res_id, context)
vals['email_cc'] = self.get_template_value(cr, uid, template.email_cc, model, res_id, context)
vals['email_bcc'] = self.get_template_value(cr, uid, template.email_bcc, model, res_id, context)
vals['reply_to'] = self.get_template_value(cr, uid, template.reply_to, model, res_id, context)
if template.message_id:
vals['message_id'] = self.get_template_value(cr, uid, message_id, model, res_id, context)
elif template.track_campaign_item:
vals['message_id'] = tools.generate_tracking_message_id(res_id)
vals['subject'] = self.get_template_value(cr, uid, template.subject, model, res_id, context)
description = self.get_template_value(cr, uid, template.body, model, res_id, context) or ''
if template.user_signature:
signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
description += '\n' + signature
vals['body'] = description
vals['report_name'] = self.get_template_value(cr, uid, template.report_name, model, res_id, context)
return {'value':vals}
email_template_preview()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Email Template Preview -->
<record model="ir.ui.view" id="email_template_preview_form">
<field name="name">email_template.preview.form</field>
<field name="model">email_template.preview</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Preview">
<group col="4" colspan="4">
<field name="model_id" readonly="1"/>
<field name="res_id" on_change="on_change_ref(res_id, context)"/>
</group>
<group col="8" colspan="4">
<field name="email_to" readonly="1"/>
<field name="email_cc" readonly="1"/>
<field name="email_bcc" readonly="1"/>
<field name="reply_to" readonly="1"/>
<field name="message_id" readonly="1" attrs="{'invisible':[('message_id','=',False)]}" groups="base.group_extended"/>
<field name="subject" colspan="8" readonly="1"/>
</group>
<group col="4" colspan="4">
<separator string= "Body" colspan="2" />
<!--<separator string= "Body(Html)" colspan="2" />-->
<newline/>
<field name="body" nolabel="1" colspan="2" readonly="1"/>
<!-- <field name="body_html" nolabel="1" colspan="2" readonly="1"/>-->
</group>
<field name="report_name" colspan="2" readonly="1"/>
<button icon="gtk-ok" special="cancel" string="OK" colspan="1"/>
</form>
</field>
</record>
<record id="wizard_email_template_preview" model="ir.actions.act_window">
<field name="name">Template Preview</field>
<field name="res_model">email_template.preview</field>
<field name="src_model">email_template.preview</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="auto_refresh" eval="1" />
<field name="target">new</field>
<field name="context">{'template_id':active_id}</field>
</record>
</data>
</openerp>

View File

@ -3,7 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009 Sharoon Thomas
# Copyright (C) 2010-2010 OpenERP SA (<http://www.openerp.com>)
# 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
@ -21,165 +21,125 @@
##############################################################################
from osv import osv, fields
from mako.template import Template
from mako import exceptions
import netsvc
import base64
from tools.translate import _
import tools
from email_template.email_template import get_value
## FIXME: this wizard duplicates a lot of features of the email template preview,
## one of the 2 should inherit from the other!
class email_template_send_wizard(osv.osv_memory):
_name = 'email_template.send.wizard'
_inherit = 'email.template'
_description = 'This is the wizard for sending mail'
_rec_name = "subject"
def _get_accounts(self, cr, uid, context=None):
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
result = super(email_template_send_wizard, self).default_get(cr, uid, fields, context=context)
template = self._get_template(cr, uid, context)
if not template:
return []
template_pool = self.pool.get('email.template')
model_pool = self.pool.get('ir.model')
template_id=context.get('template_id', False)
template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context)
def _get_template_value(field):
if not template:
return False
if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets original template values for multiple email change
return getattr(template, field)
else: # Simple Mail: Gets computed template values
return self.get_template_value(cr, uid, getattr(template, field), template.model, context.get('active_id'), context)
logger = netsvc.Logger()
if 'user_signature' in fields:
result['user_signature'] = template.user_signature
if template.from_account:
return [(template.from_account.id, '%s (%s)' % (template.from_account.name, template.from_account.email_id))]
else:
account_id = self.pool.get('email_template.account').search(cr,uid,[('company','=','no'),('user','=',uid)], context=context)
if account_id:
account = self.pool.get('email_template.account').browse(cr,uid,account_id, context)
return [(r.id,r.name + " (" + r.email_id + ")") for r in account]
else:
logger.notifyChannel(_("email-template"), netsvc.LOG_ERROR, _("No personal email accounts are configured for you. \nEither ask admin to enforce an account for this template or get yourself a personal email account."))
raise osv.except_osv(_("Missing mail account"),_("No personal email accounts are configured for you. \nEither ask admin to enforce an account for this template or get yourself a personal email account."))
if 'report_template' in fields:
result['report_template'] = template.report_template and template.report_template.id or False
def get_value(self, cursor, user, template, message, context=None, id=None):
"""Gets the value of the message parsed with the content of object id (or the first 'src_rec_ids' if id is not given)"""
if not message:
return ''
if not id:
id = context['src_rec_ids'][0]
return get_value(cursor, user, id, message, template, context)
def _get_template(self, cr, uid, context=None):
if context is None:
context = {}
if not 'template' in context and not 'template_id' in context:
return None
if 'template_id' in context.keys():
template_ids = self.pool.get('email.template').search(cr, uid, [('id','=',context['template_id'])], context=context)
elif 'template' in context.keys():
# Old versions of email_template used the name of the template. This caused
# problems when the user changed the name of the template, but we keep the code
# for compatibility with those versions.
template_ids = self.pool.get('email.template').search(cr, uid, [('name','=',context['template'])], context=context)
if not template_ids:
return None
if 'template_id' in fields:
result['template_id'] = template.id
template = self.pool.get('email.template').browse(cr, uid, template_ids[0], context)
if 'smtp_server_id' in fields:
result['smtp_server_id'] = template.smtp_server_id.id
lang = self.get_value(cr, uid, template, template.lang, context)
if lang:
# Use translated template if necessary
ctx = context.copy()
ctx['lang'] = lang
template = self.pool.get('email.template').browse(cr, uid, template.id, ctx)
return template
if 'message_id' in fields:
result['message_id'] = template.message_id
def _get_template_value(self, cr, uid, field, context=None):
if context is None:
context = {}
template = self._get_template(cr, uid, context)
if not template:
return False
if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets original template values for multiple email change
return getattr(template, field)
else: # Simple Mail: Gets computed template values
return self.get_value(cr, uid, template, getattr(template, field), context)
if 'track_campaign_item' in fields:
result['track_campaign_item'] = template.track_campaign_item
if 'attachment_ids' in fields:
result['attachment_ids'] = template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids']
if 'requested' in fields:
result['requested'] = len(context.get('src_rec_ids',''))
if 'state' in fields:
result['state'] = len(context.get('src_rec_ids','')) > 1 and 'multi' or 'single'
if 'model_id' in fields:
result['model_id'] = model_pool.search(cr, uid, [('model','=',context.get('src_model'))],context=context)[0]
if 'res_id' in fields:
result['res_id'] = context['active_id']
if 'email_to' in fields:
result['email_to'] = _get_template_value('email_to')
if 'email_cc' in fields:
result['email_cc'] = _get_template_value('email_cc')
if 'email_bcc' in fields:
result['email_bcc'] = _get_template_value('email_bcc')
if 'subject' in fields:
result['subject'] = _get_template_value('subject')
if 'body' in fields:
result['body'] = _get_template_value('description')
#if 'body_html' in fields:
# result['body_html'] = _get_template_value('body_html')
if 'reply_to' in fields:
result['reply_to'] = _get_template_value('reply_to')
if 'report_name' in fields:
result['report_name'] = _get_template_value('report_name')
return result
_columns = {
'requested':fields.integer('No of requested Mails',readonly=True),
'generated':fields.integer('No of generated Mails',readonly=True),
'full_success':fields.boolean('Complete Success',readonly=True),
'attachment_ids': fields.many2many('ir.attachment','send_wizard_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'),
'state':fields.selection([
('single','Simple Mail Wizard Step 1'),
('multi','Multiple Mail Wizard Step 1'),
('done','Wizard Complete')
],'Status',readonly=True),
'ref_template':fields.many2one('email.template','Template',readonly=True),
'rel_model':fields.many2one('ir.model','Model',readonly=True),
'rel_model_ref':fields.integer('Referred Document',readonly=True),
'from':fields.selection(_get_accounts,'From Account',select=True),
'to':fields.char('To',size=250,required=True),
'cc':fields.char('CC',size=250,),
'bcc':fields.char('BCC',size=250,),
'reply_to':fields.char('Reply-To',
size=250,
help="The address recipients should reply to,"
" if different from the From address."
" Placeholders can be used here."),
'message_id':fields.char('Message-ID',
size=250,
help="The Message-ID header value, if you need to"
"specify it, for example to automatically recognize the replies later."
" Placeholders can be used here."),
'subject':fields.char('Subject',size=200),
'body_text':fields.text('Body',),
'body_html':fields.text('Body',),
'report':fields.char('Report File Name',size=100,),
'signature':fields.boolean('Attach my signature to mail'),
#'filename':fields.text('File Name'),
'requested':fields.integer('No of requested Mails',readonly=True),
'generated':fields.integer('No of generated Mails',readonly=True),
'full_success':fields.boolean('Complete Success',readonly=True),
'attachment_ids': fields.many2many('ir.attachment','send_wizard_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'),
],'State',readonly=True),
}
#FIXME: probably better by overriding default_get directly
_defaults = {
'state': lambda self,cr,uid,ctx: len(ctx['src_rec_ids']) > 1 and 'multi' or 'single',
'rel_model': lambda self,cr,uid,ctx: self.pool.get('ir.model').search(cr,uid,[('model','=',ctx['src_model'])],context=ctx)[0],
'rel_model_ref': lambda self,cr,uid,ctx: ctx['active_id'],
'to': lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'def_to', ctx),
'cc': lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'def_cc', ctx),
'bcc': lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'def_bcc', ctx),
'subject':lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'def_subject', ctx),
'body_text':lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'def_body_text', ctx),
'body_html':lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'def_body_html', ctx),
'report': lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'file_name', ctx),
'signature': lambda self,cr,uid,ctx: self._get_template(cr, uid, ctx).use_sign,
'ref_template':lambda self,cr,uid,ctx: self._get_template(cr, uid, ctx).id,
'reply_to': lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'reply_to', ctx),
'reply_to': lambda self,cr,uid,ctx: self._get_template_value(cr, uid, 'reply_to', ctx),
'requested':lambda self,cr,uid,ctx: len(ctx['src_rec_ids']),
'full_success': False,
'attachment_ids': [],
}
def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
if context is None:
context = {}
result = super(email_template_send_wizard, self).fields_get(cr, uid, fields, context, write_access)
if 'attachment_ids' in result and 'src_model' in context:
result['attachment_ids']['domain'] = [('res_model','=',context['src_model']),('res_id','=',context['active_id'])]
return result
#def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
# if context is None:
# context = {}
# result = super(email_template_send_wizard, self).fields_get(cr, uid, fields, context, write_access)
# if 'attachment_ids' in result and 'src_model' in context:
# result['attachment_ids']['domain'] = [('res_model','=',context['src_model']),('res_id','=',context['active_id'])]
# return result
def sav_to_drafts(self, cr, uid, ids, context=None):
def save_to_drafts(self, cr, uid, ids, context=None):
if context is None:
context = {}
mailid = self.save_to_mailbox(cr, uid, ids, context=context)
if self.pool.get('email_template.mailbox').write(cr, uid, mailid, {'folder':'drafts'}, context):
return {'type':'ir.actions.act_window_close' }
self.pool.get('email.message').write(cr, uid, mailid, {'state': 'outgoing'}, context)
return {'type': 'ir.actions.act_window_close'}
def send_mail(self, cr, uid, ids, context=None):
if context is None:
context = {}
mailid = self.save_to_mailbox(cr, uid, ids, context)
if self.pool.get('email_template.mailbox').write(cr, uid, mailid, {'folder':'outbox'}, context):
return {'type':'ir.actions.act_window_close' }
return {'type': 'ir.actions.act_window_close'}
def get_generated(self, cr, uid, ids=None, context=None):
if ids is None:
@ -187,11 +147,10 @@ class email_template_send_wizard(osv.osv_memory):
if context is None:
context = {}
logger = netsvc.Logger()
if context['src_rec_ids'] and len(context['src_rec_ids'])>1:
if context.get('src_rec_ids'):
#Means there are multiple items selected for email.
mail_ids = self.save_to_mailbox(cr, uid, ids, context)
if mail_ids:
self.pool.get('email_template.mailbox').write(cr, uid, mail_ids, {'folder':'outbox'}, context)
logger.notifyChannel("email-template", netsvc.LOG_INFO, _("Emails for multiple items saved in outbox."))
self.write(cr, uid, ids, {
'generated':len(mail_ids),
@ -200,80 +159,21 @@ class email_template_send_wizard(osv.osv_memory):
else:
raise osv.except_osv(_("Email Template"),_("Email sending failed for one or more objects."))
return True
def save_to_mailbox(self, cr, uid, ids, context=None):
def get_end_value(id, value):
if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets value from the template
return self.get_value(cr, uid, template, value, context, id)
else:
return value
#def get_end_value(id, value):
# if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets value from the template
# return self.get_value(cr, uid, template, value, context, id)
# else:
# return value
if context is None:
context = {}
mail_ids = []
template = self._get_template(cr, uid, context)
for id in context['src_rec_ids']:
screen_vals = self.read(cr, uid, ids[0], [],context)
account = self.pool.get('email_template.account').read(cr, uid, screen_vals['from'], context=context)
vals = {
'email_from': tools.ustr(account['name']) + "<" + tools.ustr(account['email_id']) + ">",
'email_to': get_end_value(id, screen_vals['to']),
'email_cc': get_end_value(id, screen_vals['cc']),
'email_bcc': get_end_value(id, screen_vals['bcc']),
'subject': get_end_value(id, screen_vals['subject']),
'body_text': get_end_value(id, screen_vals['body_text']),
'body_html': get_end_value(id, screen_vals['body_html']),
'account_id': screen_vals['from'],
'state':'na',
'mail_type':'multipart/alternative' #Options:'multipart/mixed','multipart/alternative','text/plain','text/html'
}
if screen_vals['signature']:
signature = self.pool.get('res.users').read(cr, uid, uid, ['signature'], context)['signature']
if signature:
vals['body_text'] = tools.ustr(vals['body_text'] or '') + signature
vals['body_html'] = tools.ustr(vals['body_html'] or '') + signature
email_ids = []
for template in self.browse(cr, uid, ids, context=context):
for record_id in context.get('src_rec_ids',[]):
email_id = self.generate_email(cr, uid, template.id, record_id, context)
email_ids.append(email_id)
return email_ids
attachment_ids = []
#Create partly the mail and later update attachments
mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
mail_ids.append(mail_id)
if template.report_template:
reportname = 'report.' + self.pool.get('ir.actions.report.xml').read(cr, uid, template.report_template.id, ['report_name'], context)['report_name']
data = {}
data['model'] = self.pool.get('ir.model').browse(cr, uid, screen_vals['rel_model'], context).model
# Ensure report is rendered using template's language
ctx = context.copy()
if template.lang:
ctx['lang'] = self.get_value(cr, uid, template, template.lang, context, id)
service = netsvc.LocalService(reportname)
(result, format) = service.create(cr, uid, [id], data, ctx)
attachment_id = self.pool.get('ir.attachment').create(cr, uid, {
'name': _('%s (Email Attachment)') % tools.ustr(vals['subject']),
'datas': base64.b64encode(result),
'datas_fname': tools.ustr(get_end_value(id, screen_vals['report']) or _('Report')) + "." + format,
'description': vals['body_text'] or _("No Description"),
'res_model': 'email_template.mailbox',
'res_id': mail_id
}, context)
attachment_ids.append( attachment_id )
# Add document attachments
for attachment_id in screen_vals.get('attachment_ids',[]):
new_id = self.pool.get('ir.attachment').copy(cr, uid, attachment_id, {
'res_model': 'email_template.mailbox',
'res_id': mail_id,
}, context)
attachment_ids.append( new_id )
if attachment_ids:
self.pool.get('email_template.mailbox').write(cr, uid, mail_id, {
'attachments_ids': [[6, 0, attachment_ids]],
'mail_type': 'multipart/mixed'
}, context)
return mail_ids
email_template_send_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -2,62 +2,65 @@
<openerp>
<data>
<record model="ir.ui.view" id="email_template_send_wizard_form">
<field name="name">email_template.send.wizard.form</field>
<field name="model">email_template.send.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Send mail Wizard">
<group col="4" colspan="4">
<field name="rel_model" colspan="2" />
<field name="from" required="1" colspan="2" />
</group>
<group col="4" colspan="4">
<group col="6" colspan="4">
<field name="to" select="1" colspan="4" />
<newline />
<field name="cc" select="2" colspan="4" />
<newline />
<field name="bcc" select="2" colspan="4" />
<newline />
<field name="subject" select="2" colspan="4" attrs="{'required':[('state','=','single')]}" />
<newline />
<field name="report" colspan="4" />
</group>
<separator string="" colspan="4" />
<notebook colspan="4">
<page string="Body (Plain Text)">
<field name="body_text" select="2" colspan="4" nolabel="1" />
</page>
<page string="Body (HTML)">
<field name="body_html" select="2" colspan="4" nolabel="1" />
</page>
<page string="Attachments">
<label string="Add here all attachments of the current document you want to include in the Email." colspan="4"/>
<field name="attachment_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
<field name="signature" colspan="4" />
</group>
<group col="4" colspan="4" attrs="{'invisible':[('state','!=','single')]}">
<button icon="gtk-apply" name="sav_to_drafts" string="Save in Drafts" type="object" />
<button icon="gtk-ok" name="send_mail" string="Send now" type="object" />
<button icon="gtk-cancel" special="cancel" string="Discard Mail" />
</group>
<group col="4" colspan="4" attrs="{'invisible':[('state','=','single')]}">
<label string="Tip: Multiple emails are sent in the same language (the first one is proposed). We suggest you send emails in groups according to language." colspan="4"/>
<field name="requested" />
<field name="generated" />
<button icon="gtk-ok" name="get_generated" string="Send all mails" type="object" states="multi" colspan="2" />
<button icon="gtk-cancel" special="cancel" string="Discard Mail" colspan="2" states="multi" />
</group>
<button icon="gtk-ok" special="cancel" string="Close" colspan="4" states="done" />
<field name="state" />
<newline />
<label string="After clicking send all mails, mails will be sent to outbox and cleared in next Send/Recieve" colspan="4"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="email_template_send_wizard_form">
<field name="name">email_template.send.wizard.form</field>
<field name="model">email_template.send.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Send Email Wizard">
<group col="4" colspan="4">
<field name="smtp_server_id" widget="selection" required="1" colspan="4"/>
</group>
<group col="4" colspan="4">
<group col="6" colspan="4">
<field name="email_to" colspan="4"/>
<field name="email_cc" colspan="4"/>
<field name="email_bcc" colspan="4"/>
<field name="subject" colspan="4" attrs="{'required':[('state','=','single')]}"/>
<field name="report_name" colspan="4"/>
<field name="user_signature" colspan="4"/>
</group>
<separator string="" colspan="4"/>
<notebook colspan="4">
<page string="Body">
<field name="description" colspan="4" nolabel="1"/>
</page>
<!-- <page string="Body (HTML)">
<field name="body_html" colspan="4" nolabel="1"/>
</page> -->
<page string="Attachments">
<label string="Add here all attachments of the current document you want to include in the Email." colspan="4"/>
<field name="attachment_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
</group>
<field name="state" invisible="1"/>
<group col="4" colspan="4" attrs="{'invisible':[('state','=','single')]}">
<field name="requested"/>
<field name="generated"/>
<newline/>
<label string="After clicking Send All, emails will be sent to outbox and cleared in next Send/Recieve" colspan="4"/>
<label string="Tip: Multiple emails are sent in the same language (the first one is proposed). We suggest you send emails in groups according to language." colspan="4"/>
<newline/>
</group>
<label string="" colspan="2"/>
<group col="4" colspan="2" attrs="{'invisible':[('state','=','single')]}">
<button icon="gtk-cancel" special="cancel" string="Discard" states="multi"/>
<button icon="gtk-ok" name="get_generated" string="Send All" type="object" states="multi"/>
<button icon="gtk-ok" special="cancel" string="Close" states="done"/>
</group>
<group col="4" colspan="2" attrs="{'invisible':[('state','!=','single')]}">
<button icon="gtk-cancel" special="cancel" string="Discard"/>
<button icon="gtk-apply" name="save_to_drafts" string="Save in Drafts" type="object"/>
<button icon="gtk-ok" name="send_mail" string="Send now" type="object"/>
</group>
</form>
</field>
</record>
</data>
</openerp>

View File

@ -38,7 +38,7 @@ Note that:
Association / Configuration / Types of Events
""",
'author': 'OpenERP SA',
'depends': ['crm', 'base_contact', 'account', 'marketing'],
'depends': ['crm', 'base_contact', 'account', 'marketing', 'mail'],
'init_xml': [],
'update_xml': [
'security/event_security.xml',

View File

@ -24,8 +24,10 @@ import time
from crm import crm
from osv import fields, osv
from tools.translate import _
import tools
import decimal_precision as dp
from crm import wizard
wizard.email_compose_message.email_model.append('event.registration')
class event_type(osv.osv):
""" Event Type """
@ -280,7 +282,7 @@ class event_registration(osv.osv):
"""Event Registration"""
_name= 'event.registration'
_description = __doc__
_inherit = 'mailgate.thread'
_inherit = 'email.thread'
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
@ -313,8 +315,8 @@ class event_registration(osv.osv):
'create_date': fields.datetime('Creation Date', readonly=True),
'write_date': fields.datetime('Write Date', readonly=True),
'description': fields.text('Description', states={'done': [('readonly', True)]}),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'log_ids': fields.one2many('email.message', 'res_id', 'Logs', domain=[('history', '=', False),('model','=',_name)]),
'date_deadline': fields.related('event_id','date_end', type='datetime', string="End Date", readonly=True),
'date': fields.related('event_id', 'date_begin', type='datetime', string="Start Date", readonly=True),
'user_id': fields.many2one('res.users', 'Responsible', states={'done': [('readonly', True)]}),
@ -521,7 +523,7 @@ class event_registration(osv.osv):
"""
Send email to user
"""
email_message_obj = self.pool.get('email.message')
for regestration in self.browse(cr, uid, ids, context=context):
src = regestration.event_id.reply_to or False
email_to = []
@ -545,7 +547,7 @@ class event_registration(osv.osv):
subject = _('Auto Confirmation: [%s] %s') %(regestration.id, regestration.name)
body = regestration.event_id.mail_confirm
if subject or body:
tools.email_send(src, email_to, subject, body, email_cc=email_cc, openobject_id=regestration.id)
email_message_obj.schedule_with_attach(cr, uid, src, email_to, subject, body, model='event.registration', email_cc=email_cc, openobject_id=regestration.id)
self.history(cr, uid, [regestration], subject, history = True, \
email=email_to, details=body, \
subject=subject, email_from=src, \

View File

@ -391,11 +391,11 @@
<tree string="History">
<field name="display_text" string="History Information"/>
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'event.registration', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="History">
<group col="4" colspan="4">
@ -410,11 +410,10 @@
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'event.registration', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button colspan="4" string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
<field name="display_text" colspan="4" nolabel="1" height="250"/>
@ -426,14 +425,14 @@
</notebook>
</form>
</field>
<button string="Add Internal Note"
<button string="Add Internal Note"
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'event.registration'}"
icon="terp-mail-message-new" type="action" />
<button string="Send New Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model':'event.registration', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
</notebook>
</form>

View File

@ -24,7 +24,7 @@
{
"name" : "Fetchmail Server",
"version" : "1.0",
"depends" : ["base", 'mail_gateway'],
"depends" : ["base", 'mail'],
"author" : "OpenERP SA",
"category": 'Tools',
"description": """

View File

@ -62,7 +62,7 @@ class email_server(osv.osv):
'object_id': fields.many2one('ir.model', "Model", required=True, help="OpenObject Model. Generates a record of this model.\nSelect Object with message_new attrbutes."),
'priority': fields.integer('Server Priority', readonly=True, states={'draft':[('readonly', False)]}, help="Priority between 0 to 10, select define the order of Processing"),
'user_id':fields.many2one('res.users', 'User', required=False),
'message_ids': fields.one2many('mailgate.message', 'server_id', 'Messages', readonly=True),
'message_ids': fields.one2many('email.message', 'server_id', 'Messages', readonly=True),
}
_defaults = {
'state': lambda *a: "draft",
@ -82,21 +82,9 @@ class email_server(osv.osv):
return False
return True
def check_model(self, cr, uid, ids, context = None):
if context is None:
context = {}
current_rec = self.read(cr, uid, ids, context)
if current_rec:
current_rec = current_rec[0]
model_name = self.pool.get('ir.model').browse(cr, uid, current_rec.get('object_id')[0]).model
model = self.pool.get(model_name)
if hasattr(model, 'message_new'):
return True
return False
_constraints = [
(check_duplicate, 'Warning! Can\'t have duplicate server configuration!', ['user', 'password']),
(check_model, 'Warning! Record for selected Model can not be created\nPlease choose valid Model', ['object_id'])
]
def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False):
@ -111,13 +99,13 @@ class email_server(osv.osv):
def set_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids , {'state':'draft'})
return True
def button_confirm_login(self, cr, uid, ids, context=None):
if context is None:
context = {}
for server in self.browse(cr, uid, ids, context=context):
logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail start checking for new emails on %s' % (server.name))
context.update({'server_id': server.id, 'server_type': server.type})
logger.notifyChannel(server.type, netsvc.LOG_INFO, 'fetchmail start checking for new emails on %s' % (server.name))
context.update({'server_id': server.id})
try:
if server.type == 'imap':
imap_server = None
@ -128,7 +116,7 @@ class email_server(osv.osv):
imap_server.login(server.user, server.password)
ret_server = imap_server
elif server.type == 'pop':
pop_server = None
if server.is_ssl:
@ -141,12 +129,12 @@ class email_server(osv.osv):
pop_server.user(server.user)
pop_server.pass_(server.password)
ret_server = pop_server
self.write(cr, uid, [server.id], {'state':'done'})
if context.get('get_server',False):
return ret_server
except Exception, e:
logger.notifyChannel(server.type, netsvc.LOG_WARNING, '%s' % (e))
logger.notifyChannel(server.type, netsvc.LOG_ERROR, '%s' % (e))
return True
def button_fetch_mail(self, cr, uid, ids, context=None):
@ -161,90 +149,82 @@ class email_server(osv.osv):
def fetch_mail(self, cr, uid, ids, context=None):
if context is None:
context = {}
email_tool = self.pool.get('email.server.tools')
thread_pool = self.pool.get('email.thread')
action_pool = self.pool.get('ir.actions.server')
context.update({'get_server': True})
for server in self.browse(cr, uid, ids, context=context):
count = 0
user = server.user_id.id or uid
try:
if server.type == 'imap':
if server.type == 'imap':
try:
imap_server = self.button_confirm_login(cr, uid, [server.id], context=context)
imap_server.select()
result, data = imap_server.search(None, '(UNSEEN)')
for num in data[0].split():
result, data = imap_server.fetch(num, '(RFC822)')
res_id = email_tool.process_email(cr, user, server.object_id.model, data[0][1], attach=server.attach, context=context)
res_id = thread_pool.process_email(cr, user, server.object_id.model, data[0][1], attach=server.attach, context=context)
if res_id and server.action_id:
action_pool.run(cr, user, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]})
imap_server.store(num, '+FLAGS', '\\Seen')
count += 1
logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail fetch/process %s email(s) from %s' % (count, server.name))
logger.notifyChannel(server.type, netsvc.LOG_INFO, 'fetchmail fetch/process %s email(s) from %s' % (count, server.name))
imap_server.close()
imap_server.logout()
elif server.type == 'pop':
except Exception, e:
logger.notifyChannel(server.type, netsvc.LOG_ERROR, '%s' % (tools.ustr(e)))
finally:
if imap_server:
imap_server.close()
imap_server.logout()
elif server.type == 'pop':
try:
pop_server = self.button_confirm_login(cr, uid, [server.id], context=context)
pop_server.list()
(numMsgs, totalSize) = pop_server.stat()
pop_server.list()
for num in range(1, numMsgs + 1):
(header, msges, octets) = pop_server.retr(num)
msg = '\n'.join(msges)
res_id = email_tool.process_email(cr, user, server.object_id.model, msg, attach=server.attach, context=context)
res_id = thread_pool.process_email(cr, user, server.object_id.model, msg, attach=server.attach, context=context)
if res_id and server.action_id:
action_pool.run(cr, user, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]})
pop_server.dele(num)
pop_server.quit()
logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail fetch %s email(s) from %s' % (numMsgs, server.name))
except Exception, e:
logger.notifyChannel(server.type, netsvc.LOG_WARNING, '%s' % (tools.ustr(e)))
logger.notifyChannel(server.type, netsvc.LOG_INFO, 'fetchmail fetch %s email(s) from %s' % (numMsgs, server.name))
except Exception, e:
logger.notifyChannel(server.type, netsvc.LOG_ERROR, '%s' % (tools.ustr(e)))
finally:
if pop_server:
pop_server.quit()
return True
email_server()
class mailgate_message(osv.osv):
class email_message(osv.osv):
_inherit = "mailgate.message"
_inherit = "email.message"
_columns = {
'server_id': fields.many2one('email.server', "Mail Server", readonly=True, select=True),
'server_type':fields.selection([
('pop', 'POP Server'),
('imap', 'IMAP Server'),
], 'Server Type', select=True, readonly=True),
}
_order = 'id desc'
def create(self, cr, uid, values, context=None):
if context is None:
context={}
server_id = context.get('server_id',False)
server_type = context.get('server_type',False)
if server_id:
values['server_id'] = server_id
if server_type:
values['server_type'] = server_type
res = super(mailgate_message,self).create(cr, uid, values, context=context)
res = super(email_message,self).create(cr, uid, values, context=context)
return res
def write(self, cr, uid, ids, values, context=None):
if context is None:
context={}
server_id = context.get('server_id',False)
server_type = context.get('server_type',False)
if server_id:
values['server_id'] = server_id
if server_type:
values['server_type'] = server_type
res = super(mailgate_message,self).write(cr, uid, ids, values, context=context)
res = super(email_message,self).write(cr, uid, ids, values, context=context)
return res
mailgate_message()
email_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_email_server_tree">
<field name="name">email.server.tree</field>
<field name="model">email.server</field>
@ -18,7 +18,7 @@
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_email_server_form">
<field name="name">email.server.form</field>
<field name="model">email.server</field>
@ -68,7 +68,7 @@
</form>
</field>
</record>
<record model="ir.ui.view" id="view_email_server_search">
<field name="name">email.server.search</field>
<field name="model">email.server</field>
@ -91,9 +91,9 @@
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_email_server_tree">
<field name="name">Email Servers</field>
<field name="name">Incomming Servers</field>
<field name="res_model">email.server</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
@ -101,58 +101,50 @@
<field name="search_view_id" ref="view_email_server_search"/>
</record>
<menuitem
parent="base.menu_mail_gateway"
<menuitem
parent="mail.menu_config_email"
id="menu_action_fetchmail_server_tree"
action="action_email_server_tree"
name="Email Servers"
action="action_email_server_tree"
name="Incomming Servers"
/>
<record model="ir.ui.view" id="mailgate_message_tree_view">
<field name="name">mailgate.message.tree</field>
<field name="model">mailgate.message</field>
<record model="ir.ui.view" id="email_message_tree_view">
<field name="name">email.message.tree</field>
<field name="model">email.message</field>
<field name="type">tree</field>
<field name="inherit_id" ref="mail_gateway.view_mailgate_message_tree"/>
<field name="inherit_id" ref="mail.view_email_message_tree"/>
<field name="arch" type="xml">
<field name="user_id" position="after">
<field name="server_id" select="1"/>
<field name="ref_id"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="mailgate_message_search_view">
<field name="name">mailgate.message.inherit.search</field>
<field name="model">mailgate.message</field>
<record model="ir.ui.view" id="email_message_search_view">
<field name="name">email.message.inherit.search</field>
<field name="model">email.message</field>
<field name="type">search</field>
<field name="inherit_id" ref="mail_gateway.view_mailgate_message_search"/>
<field name="inherit_id" ref="mail.view_email_message_search"/>
<field name="arch" type="xml">
<xpath expr="/search/field[@name='name']" position="before">
<filter string="Emails" name="emails" domain="[('server_id','!=',False)]" icon="terp-mail-message-new"/>
<separator orientation="vertical"/>
</xpath>
<xpath expr="/search/group/filter[@string='Thread']" position="before">
<filter string="Mail Server" icon="terp-accessories-archiver" domain="[]" context="{'group_by':'server_id'}"/>
</xpath>
</field>
</record>
<record id="action_view_mail_message_emails" model="ir.actions.act_window">
<field name="name">Messages</field>
<field name="res_model">mailgate.message</field>
<field name="res_model">email.message</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_emails': 1}</field>
<field name="search_view_id" ref="mailgate_message_search_view"/>
<field name="search_view_id" ref="email_message_search_view"/>
</record>
<menuitem id="base.menu_email_gateway_form"
parent="base.menu_mail_gateway" action="action_view_mail_message_emails" />
<act_window
<act_window
context="{'search_default_server_id': [active_id], 'default_server_id': active_id}"
id="act_server_history" name="Emails"
res_model="mailgate.message" src_model="email.server"/>
id="act_server_history" name="Messages" domain="[('history', '=', True), ('server_id', '=', active_id)]"
res_model="email.message" src_model="email.server"/>
</data>
</openerp>

View File

@ -44,7 +44,7 @@ in the form of pdf file. Implements a dashboard for My Current Evaluations
"update_xml": [
"security/ir.model.access.csv",
"security/hr_evaluation_security.xml",
"wizard/hr_evaluation_mail_view.xml",
# "wizard/hr_evaluation_mail_view.xml",
"hr_evaluation_view.xml",
"report/hr_evaluation_report_view.xml",
"board_hr_evaluation_view.xml"

View File

@ -24,7 +24,6 @@ from datetime import datetime
from dateutil.relativedelta import relativedelta
from dateutil import parser
from osv import fields, osv
import tools
from tools.translate import _
class hr_evaluation_plan(osv.osv):
@ -193,6 +192,7 @@ class hr_evaluation(osv.osv):
return {'value': {'plan_id':evaluation_plan_id}}
def button_plan_in_progress(self, cr, uid, ids, context=None):
email_message_obj = self.pool.get('email.message')
hr_eval_inter_obj = self.pool.get('hr.evaluation.interview')
if context is None:
context = {}
@ -229,7 +229,7 @@ class hr_evaluation(osv.osv):
sub = phase.email_subject
dest = [child.work_email]
if dest:
tools.email_send(evaluation.employee_id.work_email, dest, sub, body)
email_message_obj.schedule_with_attach(cr, uid, evaluation.employee_id.work_email, dest, sub, body, model='hr_evaluation.evaluation')
self.write(cr, uid, ids, {'state':'wait'}, context=context)
return True

View File

@ -401,10 +401,23 @@
<field name="act_window_id" ref="action_hr_evaluation_interview_tree"/>
</record>
<!-- Email Compose message Action-->
<record id="action_email_compose_message_menu_wizard" model="ir.actions.act_window">
<field name="name">Send E-mail</field>
<field name="res_model">email.compose.message</field>
<field name="src_model">email.compose.message</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="context">{'email_model':'hr.evaluation.interview'}</field>
<field name="target">new</field>
</record>
<menuitem name="Interview Requests" parent="menu_eval_hr" id="menu_open_hr_evaluation_interview_requests"
action="action_hr_evaluation_interview_tree"/>
<menuitem name="Evaluation Reminders" parent="menu_eval_hr" id="menu_eval_send_mail"
action="action_hr_evaluation_send_mail" sequence="45" groups="base.group_hr_manager"/>
action="action_email_compose_message_menu_wizard" sequence="45" groups="base.group_hr_manager"/>
<!-- Evaluation Interviews Button on Employee Form -->
<act_window

View File

@ -19,6 +19,7 @@
#
##############################################################################
import hr_evaluation_mail
#import hr_evaluation_mail
import email_compose_message
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,71 @@
# -*- 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
from tools.translate import _
class email_compose_message(osv.osv_memory):
_inherit = 'email.compose.message'
def _get_records(self, cr, uid, context=None):
"""
Return Records of particular Model
"""
if context is None:
context = {}
record_ids = []
if context.get('email_model',False) and context.get('email_model') == 'hr.evaluation.interview':
model_pool = self.pool.get(context.get('email_model'))
record_ids = model_pool.search(cr, uid, [('state','=','waiting_answer')])
return model_pool.name_get(cr, uid, record_ids, context)
else:
return super(email_compose_message, self)._get_records(cr, uid, context=context)
_columns = {
'res_id':fields.selection(_get_records, 'Referred Document'),
}
def get_value(self, cr, uid, model, resource_id, context=None):
if context is None:
context = {}
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
if model == 'hr.evaluation.interview' and resource_id:
model_pool = self.pool.get(model)
record_data = model_pool.browse(cr, uid, resource_id, context)
if record_data.state == "waiting_answer":
msg = _("Hello %s, \n\n Kindly post your response for '%s' survey interview. \n\n Thanks,") %(record_data.user_to_review_id.name, record_data.survey_id.title)
result.update({
'email_from': tools.config.get('email_from',''),
'email_to': record_data.user_to_review_id.work_email or False,
'name': _("Reminder to fill up Survey"),
'description': msg,
'res_id': resource_id,
'email_cc': False,
'email_bcc': False,
'reply_to': False,
})
return result
email_compose_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -29,13 +29,14 @@ class hr_evaluation_reminder(osv.osv_memory):
}
def send_mail(self, cr, uid, ids, context=None):
email_message_obj = self.pool.get('email.message')
hr_evaluation_interview_obj = self.pool.get('hr.evaluation.interview')
evaluation_data = self.read(cr, uid, ids, context=context)[0]
current_interview = hr_evaluation_interview_obj.browse(cr, uid, evaluation_data.get('evaluation_id'))
if current_interview.state == "waiting_answer" and current_interview.user_to_review_id.work_email :
msg = " Hello %s, \n\n Kindly post your response for '%s' survey interview. \n\n Thanks," %(current_interview.user_to_review_id.name, current_interview.survey_id.title)
tools.email_send(tools.config['email_from'], [current_interview.user_to_review_id.work_email],\
'Reminder to fill up Survey', msg)
email_message_obj.schedule_with_attach(cr, uid, tools.config['email_from'], [current_interview.user_to_review_id.work_email],\
'Reminder to fill up Survey', msg, model='hr.evaluation.reminder')
return {'type': 'ir.actions.act_window_close'}
hr_evaluation_reminder()

View File

@ -29,6 +29,9 @@ import collections
import binascii
import tools
from tools.translate import _
from crm import wizard
wizard.email_compose_message.email_model.append('hr.applicant')
AVAILABLE_STATES = [
('draft', 'New'),
@ -79,7 +82,7 @@ class hr_applicant(crm.crm_case, osv.osv):
_name = "hr.applicant"
_description = "Applicant"
_order = "id desc"
_inherit = ['mailgate.thread']
_inherit = ['email.thread']
def _compute_day(self, cr, uid, ids, fields, args, context=None):
"""
@ -117,7 +120,7 @@ class hr_applicant(crm.crm_case, osv.osv):
_columns = {
'name': fields.char('Name', size=128, required=True),
'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', domain=[('model','=',_name)]),
'active': fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the case without removing it."),
'description': fields.text('Description'),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
@ -305,9 +308,7 @@ class hr_applicant(crm.crm_case, osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks
"""
mailgate_pool = self.pool.get('email.server.tools')
attach_obj = self.pool.get('ir.attachment')
thread_pool = self.pool.get('email.thread')
subject = msg.get('subject')
body = msg.get('body')
msg_from = msg.get('from')
@ -323,26 +324,12 @@ class hr_applicant(crm.crm_case, osv.osv):
if msg.get('priority', False):
vals['priority'] = priority
res = mailgate_pool.get_partner(cr, uid, msg.get('from'))
res = thread_pool.get_partner(cr, uid, msg.get('from'))
if res:
vals.update(res)
res = self.create(cr, uid, vals, context=context)
return self.create(cr, uid, vals, context=context)
attachents = msg.get('attachments', [])
for attactment in attachents or []:
data_attach = {
'name': attactment,
'datas':binascii.b2a_base64(str(attachents.get(attactment))),
'datas_fname': attactment,
'description': 'Mail attachment',
'res_model': self._name,
'res_id': res,
}
attach_obj.create(cr, uid, data_attach, context=context)
return res
def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context=None):
def message_update(self, cr, uid, ids, msg, vals={}, default_act='pending', context=None):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@ -377,17 +364,6 @@ class hr_applicant(crm.crm_case, osv.osv):
res = self.write(cr, uid, ids, vals, context=context)
return res
def msg_send(self, cr, uid, id, *args, **argv):
""" Send The Message
@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 emails IDs
@param *args: Return Tuple Value
@param **args: Return Dictionary of Keyword Value
"""
return True
def case_open(self, cr, uid, ids, *args):
"""
@param self: The object pointer

View File

@ -145,11 +145,11 @@
<tree string="History">
<field name="display_text" string="History Information"/>
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'hr.applicant', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="History">
<group col="4" colspan="4">
@ -164,11 +164,10 @@
<page string="Details">
<group attrs="{'invisible': [('history', '!=', True)]}">
<field name="description" colspan="4" nolabel="1" height="250"/>
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'hr.applicant', 'include_original' : True}"
icon="terp-mail-replied" type="action" />
<button colspan="4" string="Reply"
name="%(mail.action_email_compose_message_wizard)d"
context="{'mail':'reply', 'message_id':active_id}"
icon="terp-mail-replied" type="action"/>
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
<field name="display_text" colspan="4" nolabel="1" height="250"/>
@ -180,14 +179,14 @@
</notebook>
</form>
</field>
<button string="Add Internal Note"
<button string="Add Internal Note"
name="%(crm.action_crm_add_note)d"
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'hr.applicant'}"
icon="terp-mail-message-new" type="action" />
<button string="Send New Email"
name="%(mail.action_email_compose_message_wizard)d"
context="{'email_model': 'hr.applicant', 'email_res_id': active_id}"
icon="terp-mail-message-new" type="action"/>
</page>
<page string="Notes">
<field name="description" nolabel="1" colspan="4"/>

View File

@ -3,7 +3,7 @@
"access_hr_recruitment_report","hr.recruitment.report","model_hr_recruitment_report","base.group_hr_manager",1,1,1,1
"access_hr_recruitment_stage_user","hr.recruitment.stage.user","model_hr_recruitment_stage","base.group_hr_user",1,1,1,1
"access_hr_recruitment_degree","hr.recruitment.degree","model_hr_recruitment_degree","base.group_hr_user",1,1,1,1
"access_mailgate_message_user","mailgate.message.user","mail_gateway.model_mailgate_message","base.group_hr_user",1,1,1,1
"access_email_message_user","email.message.user","mail.model_email_message","base.group_hr_user",1,1,1,1
"access_res_partner_hr_user","res.partner.user","base.model_res_partner","base.group_hr_user",1,1,1,1
"access_res_partner_address_hr_user","res.partner.address.user","base.model_res_partner_address","base.group_hr_user",1,1,1,1
"access_survey_hr_user","survey.hr.user","survey.model_survey","base.group_hr_user",1,1,1,0

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
3 access_hr_recruitment_report hr.recruitment.report model_hr_recruitment_report base.group_hr_manager 1 1 1 1
4 access_hr_recruitment_stage_user hr.recruitment.stage.user model_hr_recruitment_stage base.group_hr_user 1 1 1 1
5 access_hr_recruitment_degree hr.recruitment.degree model_hr_recruitment_degree base.group_hr_user 1 1 1 1
6 access_mailgate_message_user access_email_message_user mailgate.message.user email.message.user mail_gateway.model_mailgate_message mail.model_email_message base.group_hr_user 1 1 1 1
7 access_res_partner_hr_user res.partner.user base.model_res_partner base.group_hr_user 1 1 1 1
8 access_res_partner_address_hr_user res.partner.address.user base.model_res_partner_address base.group_hr_user 1 1 1 1
9 access_survey_hr_user survey.hr.user survey.model_survey base.group_hr_user 1 1 1 0

View File

@ -32,7 +32,7 @@ class job2phonecall(osv.osv_memory):
'deadline': fields.datetime('Planned Date'),
'note': fields.text('Goals'),
'category_id': fields.many2one('crm.case.categ', 'Category', required=True),
}
}
def _date_user(self, cr, uid, context=None):
case_obj = self.pool.get('hr.applicant')
@ -50,7 +50,7 @@ class job2phonecall(osv.osv_memory):
return categ_id and categ_id[0] or case.categ_id and case.categ_id.id or False
def _get_note(self, cr, uid, context=None):
msg_obj = self.pool.get('mailgate.message')
msg_obj = self.pool.get('email.message')
if context is None:
context = {}
if context.get('active_id'):

View File

@ -19,8 +19,10 @@
#
##############################################################################
import mail_gateway
import email_message
import email_thread
import res_partner
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -20,24 +20,27 @@
##############################################################################
{
'name': 'Email Gateway System',
'name': 'Email System',
'version': '1.0',
'category': 'Tools',
'description': """
The generic email gateway system allows to send and receive emails.
The generic email system allows to send and receive emails.
===================================================================
* History of emails
* Easy integration with any module""",
* SMTP Server Configuration
* Provide API for Sending Messages
* Store all emails releated messages""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
'depends': ['base'],
'depends': ['base', 'base_tools'],
'init_xml': [],
'update_xml': [
"mail_gateway_view.xml",
"wizard/email_compose_message_view.xml",
"email_view.xml",
"email_thread_view.xml",
"res_partner_view.xml",
'security/ir.model.access.csv'
'security/ir.model.access.csv',
'email_data.xml',
],
'demo_xml': [],
'installable': True,

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record forcecreate="True" id="ir_cron_mail_scheduler_action" model="ir.cron">
<field name="name">Email Template scheduler</field>
<record forcecreate="True" id="ir_cron_mail_scheduler_action" model="ir.cron">
<field name="name">Email scheduler</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'email_template.mailbox'" name="model"/>
<field eval="'run_mail_scheduler'" name="function"/>
<field eval="'email.message'" name="model"/>
<field eval="'process_email_queue'" name="function"/>
<field eval="'()'" name="args"/>
</record>
</data>

View File

@ -0,0 +1,524 @@
# -*- 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 osv import osv
from osv import fields
from tools.translate import _
import tools
import netsvc
import base64
import time
import logging
import re
import email
from email.header import decode_header
#import binascii
#import email
#from email.header import decode_header
#from email.utils import parsedate
#import base64
#import re
#import logging
#import xmlrpclib
#import re
#import smtplib
#import base64
#from email import Encoders
#from email.mime.base import MIMEBase
#from email.mime.multipart import MIMEMultipart
#from email.mime.text import MIMEText
#from email.header import decode_header, Header
#from email.utils import formatdate
#import netsvc
#import datetime
#import tools
#import logging
#email_content_types = [
# 'multipart/mixed',
# 'multipart/alternative',
# 'multipart/related',
# 'text/plain',
# 'text/html'
#]
LOGGER = netsvc.Logger()
_logger = logging.getLogger('mail')
def format_date_tz(date, tz=None):
if not date:
return 'n/a'
format = tools.DEFAULT_SERVER_DATETIME_FORMAT
return tools.server_to_local_timestamp(date, format, format, tz)
class email_message_common(osv.osv_memory):
_name = 'email.message.common'
_columns = {
'subject':fields.text('Subject', translate=True),
'model': fields.char('Object Name', size=128, select=1),
'res_id': fields.integer('Resource ID', select=1),
'date': fields.datetime('Date'),
'user_id': fields.many2one('res.users', 'User Responsible'),
'email_from': fields.char('From', size=128, help="Email From"),
'email_to': fields.char('To', help="Email Recipients", size=256),
'email_cc': fields.char('Cc', help="Carbon Copy Email Recipients", size=256),
'email_bcc': fields.char('Bcc', help='Blind Carbon Copy Email Recipients', size=256),
'message_id': fields.char('Message Id', size=1024, help="Message Id on Email.", select=1),
'references': fields.text('References', help="References emails."),
'reply_to':fields.char('Reply-To', size=250),
'sub_type': fields.char('Sub Type', size=32),
'headers': fields.text('x_headers'),
'priority':fields.integer('Priority'),
'body': fields.text('Description', translate=True),
'body_html': fields.text('HTML', help="Contains HTML version of email"),
'smtp_server_id':fields.many2one('ir.mail_server', 'SMTP Server'),
}
_rec_name = 'subject'
_sql_constraints = []
email_message_common()
class email_message(osv.osv):
'''
Email Message
'''
_inherit = 'email.message.common'
_name = 'email.message'
_description = 'Email Message'
_order = 'date desc'
def open_document(self, cr, uid, ids, context=None):
""" To Open Document
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: the ID of messages
@param context: A standard dictionary
"""
action_data = False
if ids:
message_id = ids[0]
mailgate_data = self.browse(cr, uid, message_id, context=context)
model = mailgate_data.model
res_id = mailgate_data.res_id
action_pool = self.pool.get('ir.actions.act_window')
action_ids = action_pool.search(cr, uid, [('res_model', '=', model)])
if action_ids:
action_data = action_pool.read(cr, uid, action_ids[0], context=context)
action_data.update({
'domain' : "[('id','=',%d)]"%(res_id),
'nodestroy': True,
'context': {}
})
return action_data
def open_attachment(self, cr, uid, ids, context=None):
""" To Open attachments
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: the ID of messages
@param context: A standard dictionary
"""
action_data = False
action_pool = self.pool.get('ir.actions.act_window')
message_pool = self.browse(cr ,uid, ids, context=context)[0]
att_ids = [x.id for x in message_pool.attachment_ids]
action_ids = action_pool.search(cr, uid, [('res_model', '=', 'ir.attachment')])
if action_ids:
action_data = action_pool.read(cr, uid, action_ids[0], context=context)
action_data.update({
'domain': [('id','in',att_ids)],
'nodestroy': True
})
return action_data
def truncate_data(self, cr, uid, data, context=None):
data_list = data and data.split('\n') or []
if len(data_list) > 3:
res = '\n\t'.join(data_list[:3]) + '...'
else:
res = '\n\t'.join(data_list)
return res
def _get_display_text(self, cr, uid, ids, name, arg, context=None):
if context is None:
context = {}
tz = context.get('tz')
result = {}
for message in self.browse(cr, uid, ids, context=context):
msg_txt = ''
if message.history:
msg_txt += (message.email_from or '/') + _(' wrote on ') + format_date_tz(message.date, tz) + ':\n\t'
if message.body:
msg_txt += self.truncate_data(cr, uid, message.body, context=context)
else:
msg_txt = (message.user_id.name or '/') + _(' on ') + format_date_tz(message.date, tz) + ':\n\t'
msg_txt += message.subject
result[message.id] = msg_txt
return result
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner'),
'attachment_ids': fields.many2many('ir.attachment', 'message_attachment_rel', 'message_id', 'attachment_id', 'Attachments'),
'display_text': fields.function(_get_display_text, method=True, type='text', size="512", string='Display Text'),
'debug':fields.boolean('Debug', readonly=True),
'history': fields.boolean('History', readonly=True),
'state':fields.selection([
('outgoing', 'Outgoing'),
('sent', 'Sent'),
('received', 'Received'),
('exception', 'Exception'),
('cancel', 'Cancelled'),
], 'State', readonly=True),
'auto_delete': fields.boolean('Auto Delete', help="Permanently delete emails after sending"),
}
_defaults = {
}
def init(self, cr):
cr.execute("""SELECT indexname
FROM pg_indexes
WHERE indexname = 'email_message_res_id_model_idx'""")
if not cr.fetchone():
cr.execute("""CREATE INDEX email_message_res_id_model_idx
ON email_message (model, res_id)""")
def schedule_with_attach(self, cr, uid, email_from, email_to, subject, body, model=False, email_cc=None, email_bcc=None, reply_to=False, attach=None,
message_id=False, references=False, openobject_id=False, debug=False, subtype='plain', x_headers={}, priority='3', smtp_server_id=False, context=None, auto_delete=False):
attachment_obj = self.pool.get('ir.attachment')
if email_to and type(email_to) != list:
email_to = [email_to]
if email_cc and type(email_cc) != list:
email_cc = [email_cc]
if email_bcc and type(email_bcc) != list:
email_bcc = [email_bcc]
msg_vals = {
'subject': subject,
'model': model or '',
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'user_id': uid,
'body': body,
'email_from': email_from,
'email_to': email_to and ','.join(email_to) or '',
'email_cc': email_cc and ','.join(email_cc) or '',
'email_bcc': email_bcc and ','.join(email_bcc) or '',
'reply_to': reply_to,
'res_id': openobject_id,
'message_id': message_id,
'references': references or '',
'sub_type': subtype or '',
'headers': x_headers or False,
'priority': priority,
'debug': debug,
'history': True,
'smtp_server_id': smtp_server_id,
'state': 'outgoing',
'auto_delete': auto_delete
}
email_msg_id = self.create(cr, uid, msg_vals, context)
if attach:
attachment_ids = []
for attachment in attach:
attachment_data = {
'name': attachment[0],
'subject': (subject or '') + _(' (Email Attachment)'),
'datas': attachment[1],
'datas_fname': attachment[0],
'body': subject or _('No Description'),
'res_model':'email.message',
'res_id': email_msg_id,
}
if context.has_key('default_type'):
del context['default_type']
attachment_ids.append(attachment_obj.create(cr, uid, attachment_data, context))
self.write(cr, uid, email_msg_id,
{ 'attachment_ids': [[6, 0, attachment_ids]] }, context)
return email_msg_id
def process_retry(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state':'outgoing'}, context)
def process_email_queue(self, cr, uid, ids=None, context=None):
if ids is None:
ids = []
if context is None:
context = {}
if not ids:
filters = [('state', '=', 'outgoing')]
if 'filters' in context:
filters.extend(context['filters'])
ids = self.search(cr, uid, filters, context=context)
try:
res = self.send_email(cr, uid, ids, auto_commit=True, context=context)
except Exception, error:
logger = netsvc.Logger()
msg = _("Sending of Mail failed. Error: %s") % (error)
logger.notifyChannel("email", netsvc.LOG_ERROR, msg)
return False
return res
def _decode_header(self, text):
"""Returns unicode() string conversion of the the given encoded smtp header"""
if text:
text = decode_header(text.replace('\r', ''))
return ''.join([tools.ustr(x[0], x[1]) for x in text])
def to_email(self,text):
return re.findall(r'([^ ,<@]+@[^> ,]+)',text)
def parse_message(self, message):
"""Return Dictionary Object after parse EML Message String
@param message: email.message.Message object or string or unicode object
"""
if isinstance(message, str):
msg_txt = email.message_from_string(message)
# Warning: message_from_string doesn't always work correctly on unicode,
# we must use utf-8 strings here :-(
if isinstance(message, unicode):
message = message.encode('utf-8')
msg_txt = email.message_from_string(message)
msg_txt = message
message_id = msg_txt.get('message-id', False)
msg = {}
if not message_id:
# Very unusual situation, be we should be fault-tolerant here
message_id = time.time()
msg_txt['message-id'] = message_id
_logger.info('Parsing Message without message-id, generating a random one: %s', message_id)
fields = msg_txt.keys()
msg['id'] = message_id
msg['message-id'] = message_id
if 'Subject' in fields:
msg['subject'] = self._decode_header(msg_txt.get('Subject'))
if 'Content-Type' in fields:
msg['content-type'] = msg_txt.get('Content-Type')
if 'From' in fields:
msg['from'] = self._decode_header(msg_txt.get('From') or msg_txt.get_unixfrom())
if 'Delivered-To' in fields:
msg['to'] = self._decode_header(msg_txt.get('Delivered-To'))
if 'CC' in fields:
msg['cc'] = self._decode_header(msg_txt.get('CC'))
if 'Reply-to' in fields:
msg['reply'] = self._decode_header(msg_txt.get('Reply-To'))
if 'Date' in fields:
msg['date'] = self._decode_header(msg_txt.get('Date'))
if 'Content-Transfer-Encoding' in fields:
msg['encoding'] = msg_txt.get('Content-Transfer-Encoding')
if 'References' in fields:
msg['references'] = msg_txt.get('References')
if 'In-Reply-To' in fields:
msg['in-reply-to'] = msg_txt.get('In-Reply-To')
if 'X-Priority' in fields:
msg['priority'] = msg_txt.get('X-Priority', '3 (Normal)').split(' ')[0] #TOFIX:
if not msg_txt.is_multipart() or 'text/plain' in msg.get('content-type', ''):
encoding = msg_txt.get_content_charset()
body = msg_txt.get_payload(decode=True)
if 'text/html' in msg.get('content-type', ''):
body = tools.html2plaintext(body)
msg['body'] = tools.ustr(body, encoding)
attachments = {}
has_plain_text = False
if msg_txt.is_multipart() or 'multipart/alternative' in msg.get('content-type', ''):
body = ""
for part in msg_txt.walk():
if part.get_content_maintype() == 'multipart':
continue
encoding = part.get_content_charset()
filename = part.get_filename()
if part.get_content_maintype()=='text':
content = part.get_payload(decode=True)
if filename:
attachments[filename] = content
elif not has_plain_text:
# main content parts should have 'text' maintype
# and no filename. we ignore the html part if
# there is already a plaintext part without filename,
# because presumably these are alternatives.
content = tools.ustr(content, encoding)
if part.get_content_subtype() == 'html':
body = tools.ustr(tools.html2plaintext(content))
elif part.get_content_subtype() == 'plain':
body = content
has_plain_text = True
elif part.get_content_maintype() in ('application', 'image'):
if filename :
attachments[filename] = part.get_payload(decode=True)
else:
res = part.get_payload(decode=True)
body += tools.ustr(res, encoding)
msg['body'] = body
msg['attachments'] = attachments
return msg
def send_email(self, cr, uid, ids, auto_commit=False, context=None):
"""
send email message
"""
if context is None:
context = {}
smtp_server_obj = self.pool.get('ir.mail_server')
attachment_pool = self.pool.get('ir.attachment')
self.write(cr, uid, ids, {'state':'outgoing'}, context)
for message in self.browse(cr, uid, ids, context):
try:
smtp_server = message.smtp_server_id
if not smtp_server:
smtp_ids = smtp_server_obj.search(cr, uid, [])
if smtp_ids:
smtp_server = smtp_server_obj.browse(cr, uid, smtp_ids, context)[0]
attachments = []
for attach in message.attachment_ids:
attachments.append((attach.datas_fname, base64.b64decode(attach.datas)))
if message.state in ['outgoing', 'exception']:
msg = smtp_server_obj.pack_message(cr, uid, message.email_from,
message.email_to and message.email_to.split(',') or [], message.subject, message.body,
email_cc=message.email_cc and message.email_cc.split(',') or [],
email_bcc=message.email_bcc and message.email_bcc.split(',') or [],
reply_to=message.reply_to,
attach=attachments, message_id=message.message_id, references = message.references,
openobject_id=message.res_id,
subtype=message.sub_type,
x_headers=message.headers and eval(message.headers) or {},
priority=message.priority)
res = smtp_server_obj.send_email(cr, uid,
msg,
mail_server_id = message.smtp_server_id.id or None,
smtp_server=smtp_server and smtp_server.smtp_host or None,
smtp_port=smtp_server and smtp_server.smtp_port or None,
smtp_user=smtp_server and smtp_server.smtp_user or None,
smtp_password=smtp_server and smtp_server.smtp_pass or None,
ssl=smtp_server and smtp_server.smtp_ssl or False,
tls=smtp_server and smtp_server.smtp_tls,
debug=message.debug)
if res:
self.write(cr, uid, [message.id], {'state':'sent', 'message_id': res}, context)
else:
self.write(cr, uid, [message.id], {'state':'exception'}, context)
else:
raise osv.except_osv(_('Error !'), _('No messages in outgoing or exception state!'))
#if auto_delete=True then delete that sent messages as well as attachments
message_data = self.read(cr, uid, message.id, ['state', 'auto_delete', 'attachment_ids'])
if message_data['state'] == 'sent' and message_data['auto_delete'] == True:
self.unlink(cr, uid, [message.id], context=context)
if message_data['attachment_ids']:
attachment_pool.unlink(cr, uid, message_data['attachment_ids'], context=context)
if auto_commit == True:
cr.commit()
except Exception, error:
logger = netsvc.Logger()
logger.notifyChannel("email-template", netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (message.id, error))
self.write(cr, uid, [message.id], {'state':'exception'}, context)
return False
return True
def do_cancel(self, cr, uid, ids, context=None):
'''
Cancel the email to be send
'''
self.write(cr, uid, ids, {'state':'cancel'}, context)
return True
# OLD Code.
# def send_all_mail(self, cr, uid, ids=None, context=None):
# if ids is None:
# ids = []
# if context is None:
# context = {}
# filters = [('folder', '=', 'outbox'), ('state', '!=', 'sending')]
# if 'filters' in context.keys():
# for each_filter in context['filters']:
# filters.append(each_filter)
# ids = self.search(cr, uid, filters, context=context)
# self.write(cr, uid, ids, {'state':'sending'}, context)
# self.send_this_mail(cr, uid, ids, context)
# return True
#
# def send_this_mail(self, cr, uid, ids=None, context=None):
# #previous method to send email (link with email account can be found at the revision 4172 and below
# result = True
# attachment_pool = self.pool.get('ir.attachment')
# for id in (ids or []):
# try:
# account_obj = self.pool.get('email.smtp_server')
# values = self.read(cr, uid, id, [], context)
# payload = {}
# if values['attachments_ids']:
# for attid in values['attachments_ids']:
# attachment = attachment_pool.browse(cr, uid, attid, context)#,['datas_fname','datas'])
# payload[attachment.datas_fname] = attachment.datas
# result = account_obj.send_email(cr, uid,
# [values['account_id'][0]],
# {'To':values.get('email_to') or u'',
# 'CC':values.get('email_cc') or u'',
# 'BCC':values.get('email_bcc') or u'',
# 'Reply-To':values.get('reply_to') or u''},
# values['subject'] or u'',
# {'text':values.get('body_text') or u'', 'html':values.get('body_html') or u''},
# payload=payload,
# message_id=values['message_id'],
# context=context)
# if result == True:
# account = account_obj.browse(cr, uid, values['account_id'][0], context=context)
# if account.auto_delete:
# self.write(cr, uid, id, {'folder': 'trash'}, context=context)
# self.unlink(cr, uid, [id], context=context)
# # Remove attachments for this mail
# attachment_pool.unlink(cr, uid, values['attachments_ids'], context=context)
# else:
# self.write(cr, uid, id, {'folder':'sent', 'state':'na', 'date_mail':time.strftime("%Y-%m-%d %H:%M:%S")}, context)
# else:
# error = result['error_msg']
#
# except Exception, error:
# logger = netsvc.Logger()
# logger.notifyChannel("email-template", netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (id, error))
# self.write(cr, uid, id, {'state':'na'}, context)
# return result
email_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

375
addons/mail/email_thread.py Normal file
View File

@ -0,0 +1,375 @@
# -*- 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 osv import osv, fields
import time
import tools
import binascii
import email
from email.utils import parsedate
import base64
from tools.translate import _
import logging
import xmlrpclib
_logger = logging.getLogger('mail')
class email_thread(osv.osv):
'''
Email Thread
'''
_name = 'email.thread'
_description = 'Email Thread'
_columns = {
'message_ids': fields.one2many('email.message', 'res_id', 'Messages', readonly=True),
}
def copy(self, cr, uid, id, default=None, context=None):
"""
Overrides orm copy method.
@param self: the object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param id: Id of mailgate thread
@param default: Dictionary of default values for copy.
@param context: A standard dictionary for contextual values
"""
if default is None:
default = {}
default.update({
'message_ids': [],
})
return super(email_thread, self).copy(cr, uid, id, default, context=context)
def message_new(self, cr, uid, msg, context=None):
"""
Called by process_email() to create a new record
corresponding to an incoming message for a new thread.
@param msg: Dictionary Object to contain email message data
"""
if context is None:
context = {}
model = context.get('thread_model', False)
if not model:
model = self._name
model_pool = self.pool.get(model)
if hasattr(model_pool, 'message_new'):
res_id = model_pool.message_new(cr, uid, msg, context)
else:
fields = model_pool.fields_get(cr, uid, context=context)
data = model_pool.default_get(cr, uid, fields, context=context)
if 'name' in fields and not data.get('name',False):
data['name'] = msg.get('from','')
res_id = model_pool.create(cr, uid, data, context=context)
attachments = msg.get('attachments', {})
self.history(cr, uid, [res_id], _('receive'), history=True,
subject = msg.get('subject'),
email = msg.get('to'),
details = msg.get('body'),
email_from = msg.get('from'),
email_cc = msg.get('cc'),
message_id = msg.get('message-id'),
references = msg.get('references', False) or msg.get('in-reply-to', False),
attach = attachments.items(),
email_date = msg.get('date'),
context = context)
return res_id
def message_update(self, cr, uid, ids, msg, vals={}, default_act=None, context=None):
"""
Called by process_email() to add a new incoming message for an existing thread
@param msg: Dictionary Object to contain email message data
"""
if context is None:
context = {}
model = context.get('thread_model', False)
if not model:
model = self._name
model_pool = self.pool.get(model)
if hasattr(model_pool, 'message_update'):
model_pool.message_update(cr, uid, ids, msg, vals=vals, default_act=default_act, context=context)
attachments = msg.get('attachments', {})
self.history(cr, uid, ids, _('receive'), history=True,
subject = msg.get('subject'),
email = msg.get('to'),
details = msg.get('body'),
email_from = msg.get('from'),
email_cc = msg.get('cc'),
message_id = msg.get('message-id'),
references = msg.get('references', False) or msg.get('in-reply-to', False),
attach = attachments.items(),
email_date = msg.get('date'),
context = context)
return True
def thread_followers(self, cr, uid, ids, context=None):
""" Get a list of emails of the people following this thread
"""
res = {}
if isinstance(ids, (str, int, long)):
ids = [long(ids)]
for thread in self.browse(cr, uid, ids, context=context):
l=[]
for message in thread.message_ids:
l.append((message.user_id and message.user_id.email) or '')
l.append(message.email_from or '')
l.append(message.email_cc or '')
res[thread.id] = l
return res
def history(self, cr, uid, threads, keyword, history=False, subject=None, email=False, details=None, \
email_from=False, message_id=False, references=None, attach=None, email_cc=None, \
email_bcc=None, email_date=None, context=None):
"""
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param threads: a browse record list
@param keyword: Thread action keyword e.g.: If thread is closed "Close" keyword is used
@param history: Value True/False, If True it makes entry as a Emails Messages otherwise Log Messages
@param email: Email-To / Recipient address
@param email_from: Email From / Sender address if any
@param email_cc: Comma-Separated list of Carbon Copy Emails To addresse if any
@param email_bcc: Comma-Separated list of Blind Carbon Copy Emails To addresses if any
@param email_date: Email Date string if different from now, in server Timezone
@param details: Description, Details of thread history if any
@param attach: Attachment sent in email
@param context: A standard dictionary for contextual values"""
if context is None:
context = {}
if attach is None:
attach = []
model = context.get('thread_model', False)
if not model:
model = self._name
model_pool = self.pool.get(model)
if email_date:
edate = parsedate(email_date)
if edate is not None:
email_date = time.strftime('%Y-%m-%d %H:%M:%S', edate)
# The script sends the ids of the threads and not the object list
if all(isinstance(thread_id, (int, long)) for thread_id in threads):
threads = model_pool.browse(cr, uid, threads, context=context)
att_obj = self.pool.get('ir.attachment')
obj = self.pool.get('email.message')
for thread in threads:
attachments = []
for attachment in attach:
data_attach = {
'name': attachment[0],
'datas': binascii.b2a_base64(str(attachment[1])),
'datas_fname': attachment[0],
'description': _('Mail attachment'),
'res_model': thread._name,
'res_id': thread.id,
}
attachments.append(att_obj.create(cr, uid, data_attach))
partner_id = hasattr(thread, 'partner_id') and (thread.partner_id and thread.partner_id.id or False) or False
if not partner_id and thread._name == 'res.partner':
partner_id = thread.id
data = {
'subject': keyword,
'user_id': uid,
'model' : thread._name,
'partner_id': partner_id,
'res_id': thread.id,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'message_id': message_id,
'body': details or (hasattr(thread, 'description') and thread.description or False),
'attachment_ids': [(6, 0, attachments)]
}
if history:
for param in (email, email_cc, email_bcc):
if isinstance(param, list):
param = ", ".join(param)
data = {
'subject': subject or _('History'),
'history': True,
'user_id': uid,
'model' : thread._name,
'res_id': thread.id,
'date': email_date or time.strftime('%Y-%m-%d %H:%M:%S'),
'body': details,
'email_to': email,
'email_from': email_from or \
(hasattr(thread, 'user_id') and thread.user_id and thread.user_id.address_id and \
thread.user_id.address_id.email),
'email_cc': email_cc,
'email_bcc': email_bcc,
'partner_id': partner_id,
'references': references,
'message_id': message_id,
'attachment_ids': [(6, 0, attachments)],
'state' : 'received',
}
obj.create(cr, uid, data, context=context)
return True
def email_forward(self, cr, uid, model, res_ids, msg, email_error=False, context=None):
"""Sends an email to all people following the thread
@param res_id: Id of the record of OpenObject model created from the email message
@param msg: email.message.Message object to forward
@param email_error: Default Email address in case of any Problem
"""
model_pool = self.pool.get(model)
smtp_server_obj = self.pool.get('ir.mail_server')
email_message_obj = self.pool.get('email.message')
_decode_header = email_message_obj._decode_header
for res in model_pool.browse(cr, uid, res_ids, context=context):
if hasattr(model_pool, 'thread_followers'):
self.thread_followers = model_pool.thread_followers
thread_followers = self.thread_followers(cr, uid, [res.id])[res.id]
message_followers_emails = email_message_obj.to_email(','.join(filter(None, thread_followers)))
message_recipients = email_message_obj.to_email(','.join(filter(None,
[_decode_header(msg['from']),
_decode_header(msg['to']),
_decode_header(msg['cc'])])))
message_forward = [i for i in message_followers_emails if (i and (i not in message_recipients))]
if message_forward:
# TODO: we need an interface for this for all types of objects, not just leads
if hasattr(res, 'section_id'):
del msg['reply-to']
msg['reply-to'] = res.section_id.reply_to
smtp_from = email_message_obj.to_email(msg['from'])
msg['from'] = smtp_from
msg['to'] = message_forward
msg['message-id'] = tools.generate_tracking_message_id(res.id)
if not smtp_server_obj.send_email(cr, uid, msg) and email_error:
subj = msg['subject']
del msg['subject'], msg['to'], msg['cc'], msg['bcc']
msg['subject'] = _('[OpenERP-Forward-Failed] %s') % subj
msg['to'] = email_error
smtp_server_obj.send_email(cr, uid, msg)
return True
def process_email(self, cr, uid, model, message, custom_values=None, attach=True, context=None):
"""This function Processes email and create record for given OpenERP model
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param model: OpenObject Model
@param message: Email details, passed as a string or an xmlrpclib.Binary
@param attach: Email attachments
@param context: A standard dictionary for contextual values"""
# extract message bytes, we are forced to pass the message as binary because
# we don't know its encoding until we parse its headers and hence can't
# convert it to utf-8 for transport between the mailgate script and here.
if isinstance(message, xmlrpclib.Binary):
message = str(message.data)
if context is None:
context = {}
if custom_values is None or not isinstance(custom_values, dict):
custom_values = {}
model_pool = self.pool.get(model)
if self._name != model:
context.update({'thread_model':model})
email_message_pool = self.pool.get('email.message')
res_id = False
# Parse Message
# Warning: message_from_string doesn't always work correctly on unicode,
# we must use utf-8 strings here :-(
if isinstance(message, unicode):
message = message.encode('utf-8')
msg_txt = email.message_from_string(message)
msg = email_message_pool.parse_message(msg_txt)
# Create New Record into particular model
def create_record(msg):
new_res_id = self.message_new(cr, uid, msg, context=context)
if custom_values:
model_pool.write(cr, uid, [res_id], custom_values, context=context)
return new_res_id
res_id = False
if msg.get('references') or msg.get('in-reply-to'):
references = msg.get('references') or msg.get('in-reply-to')
if '\r\n' in references:
references = references.split('\r\n')
else:
references = references.split(' ')
for ref in references:
ref = ref.strip()
res_id = tools.reference_re.search(ref)
if res_id:
res_id = res_id.group(1)
else:
res_id = tools.res_re.search(msg['subject'])
if res_id:
res_id = res_id.group(1)
if res_id:
res_id = int(res_id)
if model_pool.exists(cr, uid, res_id):
self.message_update(cr, uid, [res_id], msg, {}, context=context)
if not res_id:
res_id = create_record(msg)
#To forward the email to other followers
self.email_forward(cr, uid, model, [res_id], msg_txt)
return res_id
def get_partner(self, cr, uid, from_email, context=None):
"""This function returns partner Id based on email passed
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks
@param from_email: email address based on that function will search for the correct
"""
address_pool = self.pool.get('res.partner.address')
email_message_pool = self.pool.get('email.message')
res = {
'partner_address_id': False,
'partner_id': False
}
from_email = email_message_pool.to_email(from_email)[0]
address_ids = address_pool.search(cr, uid, [('email', 'like', from_email)])
if address_ids:
address = address_pool.browse(cr, uid, address_ids[0])
res['partner_address_id'] = address_ids[0]
res['partner_id'] = address.partner_id.id
return res
email_thread()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,90 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_mailgate_thread_form">
<field name="name">email.thread.form</field>
<field name="model">email.thread</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Mailgateway Thread">
<separator string="History" colspan="4"/>
<field name="message_ids" nolabel="1" colspan="4" mode="tree,form">
<tree string="Mailgateway History">
<field name="display_text"/>
</tree>
<form string="Mailgate History">
<field name="subject" widget="char"/>
<field name="date"/>
<field name="user_id"/>
<field name="message_id"/>
<field name="history"/>
<notebook colspan="4">
<page string="Email Details">
<group col="4" colspan="4">
<separator string="Email Details" colspan="4"/>
<field name="email_from"/>
<field name="email_to"/>
<field name="email_cc"/>
<field name="email_bcc"/>
</group>
</page>
<page string="Attachments">
<separator string="Attachments" colspan="4"/>
<field name="attachment_ids" nolabel="1" colspan="4" />
</page>
</notebook>
</form>
</field>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_mailgate_thread_tree">
<field name="name">email.thread.tree</field>
<field name="model">email.thread</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Mailgateway Thread">
<field name="message_ids" />
</tree>
</field>
</record>
<!-- Emails action-->
<record model="ir.actions.act_window" id="action_view_mailgate_thread">
<field name="name">Mailgateway Threads</field>
<field name="res_model">email.thread</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_mailgate_thread_tree"/>
</record>
<record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view1">
<field name="sequence" eval="1"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_mailgate_thread_tree"/>
<field name="act_window_id" ref="action_view_mailgate_thread"/>
</record>
<record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view2">
<field name="sequence" eval="2"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_mailgate_thread_form"/>
<field name="act_window_id" ref="action_view_mailgate_thread"/>
</record>
<record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view1">
<field name="sequence" eval="1"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_mailgate_thread_tree"/>
<field name="act_window_id" ref="action_view_mailgate_thread"/>
</record>
<record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view2">
<field name="sequence" eval="2"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_mailgate_thread_form"/>
<field name="act_window_id" ref="action_view_mailgate_thread"/>
</record>
</data>
</openerp>

151
addons/mail/email_view.xml Normal file
View File

@ -0,0 +1,151 @@
<?xml version="1.0"?>
<openerp>
<data>
<menuitem name="Configuration" parent="base.menu_tools"
id="base.menu_lunch_survey_root" sequence="20"/>
<record model="ir.ui.view" id="view_email_message_form">
<field name="name">email.message.form</field>
<field name="model">email.message</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email message">
<group colspan="4" col="6">
<field name="subject" widget="char" size="512"/>
<field name="date"/>
<field name="user_id" string="User"/>
<field name="partner_id" readonly="1" />
<field name="priority"/>
</group>
<notebook colspan="4">
<page string="Details">
<group col="2" colspan="2">
<separator string="Email Followers" colspan="4"/>
<field name="email_from"/>
<field name="email_to"/>
<field name="email_cc"/>
<field name="email_bcc" groups="base.group_extended"/>
<field name="reply_to"/>
</group>
<group col="2" colspan="2">
<separator string="Message Details" colspan="4"/>
<field name="model" readonly="1"/>
<group col="3" colspan="2">
<field name="res_id" readonly="1" groups="base.group_extended"/>
<button name="open_document" string="Open Document" type="object" icon="gtk-jump-to"/>
<field name="message_id" groups="base.group_extended" colspan="4"/>
</group>
<field name="references" widget="char" size="4096" groups="base.group_extended"/>
</group>
<separator string="Description" colspan="4"/>
<field name="body" nolabel="1" colspan="4"/>
<separator string="" colspan="4"/>
<group col="6" colspan="4">
<field name="state" colspan="2"/>
<group col="4" colspan="2">
<button name="%(action_email_compose_message_wizard)d" string="Reply" type="action" icon="terp-mail-replied"
context="{'mail':'reply', 'message_id':active_id}" states='received,outgoing,sent,exception,cancel'/>
<button name="send_email" string="Force Send" type="object" icon="gtk-execute" states='outgoing'/>
<button name="process_retry" string="Send Again" type="object" icon="gtk-execute" states='exception,cancel'/>
<button name="do_cancel" string="Cancel" type="object" icon="terp-gtk-stop" states='outgoing'/>
</group>
</group>
</page>
<page string="Attachments">
<separator string="Attachments" colspan="4"/>
<field name="attachment_ids" nolabel="1" colspan="4" readonly="1"/>
</page>
<page string="Advanced">
<group col="4" colspan="4">
<field name="smtp_server_id"/>
<field name="sub_type"/>
<field name="debug" groups="base.group_extended"/>
<field name="history"/>
<field name="auto_delete"/>
<separator string="xheaders" colspan="4"/>
<field name="headers" colspan="4" nolabel="1" groups="base.group_extended"/>
</group>
</page>
</notebook>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_email_message_tree">
<field name="name">email.message.tree</field>
<field name="model">email.message</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Emails" colors="grey:state in ('sent', 'cancel');blue:state=='outgoing';red:state=='exception';black:state=='received'">
<field name="date"/>
<field name="subject"/>
<field name="email_from"/>
<field name="user_id" string="User"/>
<field name="message_id" string="Message" invisible="1"/>
<field name="partner_id" invisible="1"/>
<field name="state"/>
<button name="open_document" string="Open Document" type="object" icon="gtk-jump-to"/>
<button name="open_attachment" string="Open Attachments" type="object" icon="gtk-jump-to"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_email_message_search">
<field name="name">email.message.search</field>
<field name="model">email.message</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Email Search">
<separator orientation="vertical"/>
<filter icon="terp-camera_test" string="Received" domain="[('state','=','received')]"/>
<filter icon="terp-call-start" name="outgoing" string="Outgoing" domain="[('state','=','outgoing')]"/>
<filter icon="terp-gtk-stop" string="Exception" domain="[('state','=','exception')]"/>
<field name="email_from"/>
<field name="subject"/>
<field name="date"/>
<field name="user_id" string="User"/>
<field name="partner_id" string="Partner Name"/>
<newline/>
<group expand="0" string="Group By..." groups="base.group_extended">
<filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
<filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="User" name="User" icon="terp-personal" context="{'group_by':'user_id'}"/>
<separator orientation="vertical"/>
<filter string="Thread" icon="terp-mail-" domain="[]" context="{'group_by':'message_id'}"/>
<separator orientation="vertical"/>
<filter string="Month" help="Creation Month" icon="terp-go-month" domain="[]" context="{'group_by':'date'}"/>
</group>
</search>
</field>
</record>
<record id="action_view_mail_message" model="ir.actions.act_window">
<field name="name">Messages</field>
<field name="res_model">email.message</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('history', '=', True)]</field>
<field name="context">{'search_default_outgoing':1}</field>
<field name="search_view_id" ref="view_email_message_search"/>
</record>
<act_window domain="[('partner_id', '=', active_id), ('history', '=', True)]"
id="act_res_partner_emails" name="Emails"
res_model="email.message"
src_model="res.partner"
view_id="view_email_message_tree"/>
<menuitem name="Email" id="menu_email_message_tools"
parent="base.menu_tools" />
<menuitem name="Messages"
id="menu_email_message"
parent="menu_email_message_tools"
action="action_view_mail_message" />
<menuitem name="Email" id="menu_config_email" parent="base.menu_lunch_survey_root" sequence="20"/>
</data>
</openerp>

View File

@ -19,17 +19,16 @@
#
##############################################################################
from osv import fields,osv
from osv import osv
from osv import fields
class res_partner(osv.osv):
""" Inherits partner and adds CRM information in the partner form """
_inherit = 'res.partner'
_columns = {
'emails': fields.one2many('mailgate.message', 'partner_id',\
'Emails', readonly=True, domain=[('history','=',True)]),
'emails': fields.one2many('email.message', 'partner_id', 'Emails', readonly=True, domain=[('history','=',True)]),
}
res_partner()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Partners inherited form -->
<record id="base.view_crm_partner_info_History" model="ir.ui.view">
<field name="name">res.partner.crm.history.inherit1</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="/form/notebook/page[@string='History']" position="attributes">
<attribute name="invisible">False</attribute>
</xpath>
</field>
</record>
<record id="view_emails_partner_info_form" model="ir.ui.view">
<field name="name">res.partner.emails.info.inherit</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<page string="History" position="inside">
<field name="emails" colspan="4" nolabel="1"/>
</page>
</field>
</record>
</data>
</openerp>

Some files were not shown because too many files have changed in this diff Show More