2013-09-13 11:54:08 +00:00
|
|
|
|
2014-03-28 13:20:07 +00:00
|
|
|
import werkzeug
|
|
|
|
|
2014-01-29 17:15:20 +00:00
|
|
|
from openerp import http, SUPERUSER_ID
|
2013-10-22 17:06:59 +00:00
|
|
|
from openerp.http import request
|
2013-09-13 11:54:08 +00:00
|
|
|
|
2014-03-21 17:21:39 +00:00
|
|
|
|
2013-09-13 11:54:08 +00:00
|
|
|
class MassMailController(http.Controller):
|
2014-03-21 17:21:39 +00:00
|
|
|
|
2014-01-29 17:15:20 +00:00
|
|
|
@http.route('/mail/track/<int:mail_id>/blank.gif', type='http', auth='none')
|
2014-03-28 13:20:07 +00:00
|
|
|
def track_mail_open(self, mail_id, **post):
|
2013-09-13 11:54:08 +00:00
|
|
|
""" Email tracking. """
|
|
|
|
mail_mail_stats = request.registry.get('mail.mail.statistics')
|
2014-01-29 17:15:20 +00:00
|
|
|
mail_mail_stats.set_opened(request.cr, SUPERUSER_ID, mail_mail_ids=[mail_id])
|
2014-03-28 13:20:07 +00:00
|
|
|
response = werkzeug.wrappers.Response()
|
|
|
|
response.mimetype = 'image/gif'
|
2014-04-24 13:14:51 +00:00
|
|
|
response.data = 'R0lGODlhAQABAIAAANvf7wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='.decode('base64')
|
2014-03-28 13:20:07 +00:00
|
|
|
return response
|
2014-03-21 17:21:39 +00:00
|
|
|
|
|
|
|
@http.route(['/mail/mailing/<int:mailing_id>/unsubscribe'], type='http', auth='none')
|
2014-03-25 15:41:14 +00:00
|
|
|
def mailing(self, mailing_id, email=None, res_id=None, **post):
|
2014-03-21 17:21:39 +00:00
|
|
|
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:
|
2014-03-25 15:41:14 +00:00
|
|
|
return 'KO'
|
|
|
|
mailing = MassMailing.browse(cr, SUPERUSER_ID, mailing_ids[0], context=context)
|
|
|
|
if mailing.mailing_model == 'mail.mass_mailing.contact':
|
2014-03-21 17:21:39 +00:00
|
|
|
list_ids = [l.id for l in mailing.contact_list_ids]
|
2014-03-25 15:41:14 +00:00
|
|
|
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:
|
2014-04-16 08:28:51 +00:00
|
|
|
email_fname = None
|
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
|
|
|
model = request.registry[mailing.mailing_model]
|
|
|
|
if 'email_from' in model._fields:
|
2014-04-16 08:28:51 +00:00
|
|
|
email_fname = 'email_from'
|
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
|
|
|
elif 'email' in model._fields:
|
2014-04-16 08:28:51 +00:00
|
|
|
email_fname = 'email'
|
|
|
|
if email_fname:
|
2017-05-10 17:05:48 +00:00
|
|
|
ctx = dict(context or {}, active_test=False)
|
|
|
|
record_ids = model.search(cr, SUPERUSER_ID, [('id', '=', res_id), (email_fname, 'ilike', email)], context=ctx)
|
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
|
|
|
if 'opt_out' in model._fields:
|
|
|
|
model.write(cr, SUPERUSER_ID, record_ids, {'opt_out': True}, context=context)
|
2014-03-25 15:41:14 +00:00
|
|
|
return 'OK'
|
2014-05-06 14:51:45 +00:00
|
|
|
|
|
|
|
@http.route(['/website_mass_mailing/is_subscriber'], type='json', auth="public", website=True)
|
|
|
|
def is_subscriber(self, list_id, **post):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Contacts = request.registry['mail.mass_mailing.contact']
|
|
|
|
Users = request.registry['res.users']
|
|
|
|
|
|
|
|
is_subscriber = False
|
|
|
|
email = None
|
2014-05-12 10:39:35 +00:00
|
|
|
if uid != request.website.user_id.id:
|
2014-05-06 14:51:45 +00:00
|
|
|
email = Users.browse(cr, SUPERUSER_ID, uid, context).email
|
|
|
|
elif request.session.get('mass_mailing_email'):
|
|
|
|
email = request.session['mass_mailing_email']
|
|
|
|
|
|
|
|
if email:
|
2014-08-01 12:20:55 +00:00
|
|
|
contact_ids = Contacts.search(cr, SUPERUSER_ID, [('list_id', '=', int(list_id)), ('email', '=', email), ('opt_out', '=', False)], context=context)
|
2014-05-06 14:51:45 +00:00
|
|
|
is_subscriber = len(contact_ids) > 0
|
|
|
|
|
|
|
|
return {'is_subscriber': is_subscriber, 'email': email}
|
|
|
|
|
|
|
|
@http.route(['/website_mass_mailing/subscribe'], type='json', auth="public", website=True)
|
|
|
|
def subscribe(self, list_id, email, **post):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Contacts = request.registry['mail.mass_mailing.contact']
|
2016-06-02 08:14:54 +00:00
|
|
|
parsed_email = Contacts.get_name_email(email, context=context)[1]
|
2014-05-06 14:51:45 +00:00
|
|
|
|
2016-06-02 08:14:54 +00:00
|
|
|
contact_ids = Contacts.search_read(
|
|
|
|
cr, SUPERUSER_ID,
|
|
|
|
[('list_id', '=', int(list_id)), ('email', '=', parsed_email)],
|
|
|
|
['opt_out'], context=context)
|
2014-05-06 14:51:45 +00:00
|
|
|
if not contact_ids:
|
2014-08-01 09:25:41 +00:00
|
|
|
Contacts.add_to_list(cr, SUPERUSER_ID, email, int(list_id), context=context)
|
2014-08-01 12:20:55 +00:00
|
|
|
else:
|
|
|
|
if contact_ids[0]['opt_out']:
|
|
|
|
Contacts.write(cr, SUPERUSER_ID, [contact_ids[0]['id']], {'opt_out': False}, context=context)
|
2014-05-06 14:51:45 +00:00
|
|
|
# add email to session
|
|
|
|
request.session['mass_mailing_email'] = email
|
|
|
|
return True
|