[IMP] mail, mass_mailing: using a _mail_mass_mailing class attribute

it is now possible to compute models allowing mass mailing using mass_mailing_campaign
module. This allows to completely remove the bridges modules, using a more generic
controller for unsubscription.

bzr revid: tde@openerp.com-20140416082851-8duo6yrwr5hwd8c2
This commit is contained in:
Thibault Delavallée 2014-04-16 10:28:51 +02:00
parent c5627c4d3f
commit 4336c64a7c
18 changed files with 23 additions and 162 deletions

View File

@ -79,6 +79,7 @@ class crm_lead(format_address, osv.osv):
'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj.probability == 0 and obj.stage_id and obj.stage_id.fold and obj.stage_id.sequence > 1,
},
}
_mail_mass_mailing = _('Leads / Opportunities')
def get_empty_list_help(self, cr, uid, help, context=None):
if context.get('default_type') == 'lead':

View File

@ -80,6 +80,7 @@ class hr_applicant(osv.Model):
_description = "Applicant"
_order = "id desc"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_track = {
'stage_id': {
# this is only an heuristics; depending on your particular stage configuration it may not match all 'new' stages
@ -87,6 +88,7 @@ class hr_applicant(osv.Model):
'hr_recruitment.mt_applicant_stage_changed': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.sequence > 1,
},
}
_mail_mass_mailing = _('Applicants')
def _get_default_department_id(self, cr, uid, context=None):
""" Gives default department by checking if present in the context """

View File

@ -96,6 +96,9 @@ class mail_thread(osv.AbstractModel):
# :param function lambda: returns whether the tracking should record using this subtype
_track = {}
# Mass mailing feature
_mail_mass_mailing = False
def get_empty_list_help(self, cr, uid, help, context=None):
""" Override of BaseModel.get_empty_list_help() to generate an help message
that adds alias information. """

View File

@ -28,6 +28,7 @@ class res_partner_mail(osv.Model):
_name = "res.partner"
_inherit = ['res.partner', 'mail.thread']
_mail_flat_thread = False
_mail_mass_mailing = _('Customers')
_columns = {
'notification_email_send': fields.selection([

View File

@ -30,6 +30,13 @@ class MassMailController(http.Controller):
record_ids = request.registry[mailing.mailing_model].search(cr, SUPERUSER_ID, [('list_id', 'in', list_ids), ('id', '=', res_id), ('email', 'ilike', email)], context=context)
request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
else:
record_ids = request.registry[mailing.mailing_model].search(cr, SUPERUSER_ID, [('id', '=', res_id), ('email', 'ilike', email)], context=context)
request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
email_fname = None
if 'email_from' in request.registry[mailing.mailing_model]._all_columns:
email_fname = 'email_from'
elif 'email' in request.registry[mailing.mailing_model]._all_columns:
email_fname = 'email'
if email_fname:
record_ids = request.registry[mailing.mailing_model].search(cr, SUPERUSER_ID, [('id', '=', res_id), (email_fname, 'ilike', email)], context=context)
if 'opt_out' in request.registry[mailing.mailing_model]._all_columns:
request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
return 'OK'

View File

@ -299,10 +299,13 @@ class MassMailing(osv.Model):
return results
def _get_mailing_model(self, cr, uid, context=None):
return [
('res.partner', _('Customers')),
('mail.mass_mailing.contact', _('Mailing List'))
]
res = []
for model_name in self.pool:
model = self.pool[model_name]
if hasattr(model, '_mail_mass_mailing') and getattr(model, '_mail_mass_mailing'):
res.append((model._name, getattr(model, '_mail_mass_mailing')))
res.append(('mail.mass_mailing.contact', _('Mailing List')))
return res
# indirections for inheritance
_mailing_model = lambda self, *args, **kwargs: self._get_mailing_model(*args, **kwargs)

View File

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014-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 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/>.
#
##############################################################################
import models
import controllers

View File

@ -1,17 +0,0 @@
# -*- coding: utf-8 -*-
{
'name': 'Mass Mailing with Recruitment',
'version': '1.0',
'depends': ['mass_mailing', 'hr_recruitment'],
'author': 'OpenERP SA',
'category': 'Hidden/Dependency',
'description': """
Bridge module between Mass Mailing and HR Recruitment
""",
'website': 'http://www.openerp.com',
'data': [],
'demo': [],
'installable': True,
'auto_install': True,
}

View File

@ -1 +0,0 @@
import main

View File

@ -1,21 +0,0 @@
from openerp import http, SUPERUSER_ID
from openerp.addons.mass_mailing.controllers import main
from openerp.http import request
class MassMailController(main.MassMailController):
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', auth='none')
def mailing(self, mailing_id, email=None, res_id=None, **post):
cr, uid, context = request.cr, request.uid, request.context
MassMailing = request.registry['mail.mass_mailing']
mailing_ids = MassMailing.exists(cr, SUPERUSER_ID, [mailing_id], context=context)
if not mailing_ids:
return super(MassMailController, self).mailing(mailing_id, email=email, res_id=res_id, **post)
mailing = MassMailing.browse(cr, SUPERUSER_ID, mailing_ids[0], context=context)
if mailing.mailing_model == 'hr.applicant':
record_ids = request.registry[mailing.mailing_model].search(cr, SUPERUSER_ID, [('id', '=', res_id), ('email_from', 'ilike', email)], context=context)
# request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
return 'OK'
return super(MassMailController, self).mailing(mailing_id, email=email, res_id=res_id, **post)

View File

@ -1 +0,0 @@
import mass_mailing

View File

@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
from openerp.osv import osv
class MassMailing(osv.Model):
"""Inherit to add hr.applicant objects available for mass mailing """
_name = 'mail.mass_mailing'
_inherit = 'mail.mass_mailing'
def _get_mailing_model(self, cr, uid, context=None):
res = super(MassMailing, self)._get_mailing_model(cr, uid, context=context)
res.append(('hr.applicant', 'Applicants'))
return res

View File

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014-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 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/>.
#
##############################################################################
import models
import controllers

View File

@ -1,17 +0,0 @@
# -*- coding: utf-8 -*-
{
'name': 'Mass Mailing with CRM',
'version': '1.0',
'depends': ['mass_mailing', 'crm'],
'author': 'OpenERP SA',
'category': 'Hidden/Dependency',
'description': """
Bridge module between Mass Mailing and CRM
""",
'website': 'http://www.openerp.com',
'data': [],
'demo': [],
'installable': True,
'auto_install': True,
}

View File

@ -1 +0,0 @@
import main

View File

@ -1,21 +0,0 @@
from openerp import http, SUPERUSER_ID
from openerp.addons.mass_mailing.controllers import main
from openerp.http import request
class MassMailController(main.MassMailController):
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', auth='none')
def mailing(self, mailing_id, email=None, res_id=None, **post):
cr, uid, context = request.cr, request.uid, request.context
MassMailing = request.registry['mail.mass_mailing']
mailing_ids = MassMailing.exists(cr, SUPERUSER_ID, [mailing_id], context=context)
if not mailing_ids:
return super(MassMailController, self).mailing(mailing_id, email=email, res_id=res_id, **post)
mailing = MassMailing.browse(cr, SUPERUSER_ID, mailing_ids[0], context=context)
if mailing.mailing_model == 'crm.lead':
record_ids = request.registry[mailing.mailing_model].search(cr, SUPERUSER_ID, [('id', '=', res_id), ('email_from', 'ilike', email)], context=context)
request.registry[mailing.mailing_model].write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
return 'OK'
return super(MassMailController, self).mailing(mailing_id, email=email, res_id=res_id, **post)

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
import mass_mailing

View File

@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
from openerp.osv import osv
class MassMailing(osv.Model):
"""Inherit to add crm.lead objects available for mass mailing """
_name = 'mail.mass_mailing'
_inherit = 'mail.mass_mailing'
def _get_mailing_model(self, cr, uid, context=None):
res = super(MassMailing, self)._get_mailing_model(cr, uid, context=context)
res.append(('crm.lead', 'Leads / Opportunities'))
return res