[IMP] mass_mailing: mailing_type -> mailing_model, because
this is basically a model. yay. bzr revid: tde@openerp.com-20140317171612-lgnaojfadbkwowcw
This commit is contained in:
parent
b4a5960e14
commit
9845285781
|
@ -82,10 +82,7 @@ class MassMailingList(osv.Model):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _get_model_list(self, cr, uid, context=None):
|
def _get_model_list(self, cr, uid, context=None):
|
||||||
return [
|
return self.pool['mail.mass_mailing']._get_mailing_model(cr, uid, context=context)
|
||||||
('res.partner', 'Customers'),
|
|
||||||
('mail.mass_mailing.contact', 'Mailing Contacts')
|
|
||||||
]
|
|
||||||
|
|
||||||
# indirections for inheritance
|
# indirections for inheritance
|
||||||
_model_list = lambda self, *args, **kwargs: self._get_model_list(*args, **kwargs)
|
_model_list = lambda self, *args, **kwargs: self._get_model_list(*args, **kwargs)
|
||||||
|
@ -361,7 +358,7 @@ class MassMailing(osv.Model):
|
||||||
results[mid]['delivered'] = results[mid]['sent'] - results[mid]['bounced']
|
results[mid]['delivered'] = results[mid]['sent'] - results[mid]['bounced']
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _get_mailing_type(self, cr, uid, context=None):
|
def _get_mailing_model(self, cr, uid, context=None):
|
||||||
return [
|
return [
|
||||||
('res.partner', 'Customers'),
|
('res.partner', 'Customers'),
|
||||||
('mail.mass_mailing.contact', 'Contacts')
|
('mail.mass_mailing.contact', 'Contacts')
|
||||||
|
@ -371,7 +368,7 @@ class MassMailing(osv.Model):
|
||||||
return [('draft', 'Schedule'), ('test', 'Tested'), ('done', 'Sent')]
|
return [('draft', 'Schedule'), ('test', 'Tested'), ('done', 'Sent')]
|
||||||
|
|
||||||
# indirections for inheritance
|
# indirections for inheritance
|
||||||
_mailing_type = lambda self, *args, **kwargs: self._get_mailing_type(*args, **kwargs)
|
_mailing_model = lambda self, *args, **kwargs: self._get_mailing_model(*args, **kwargs)
|
||||||
_state = lambda self, *args, **kwargs: self._get_state_list(*args, **kwargs)
|
_state = lambda self, *args, **kwargs: self._get_state_list(*args, **kwargs)
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
@ -402,11 +399,11 @@ class MassMailing(osv.Model):
|
||||||
'email_from': fields.char('From'),
|
'email_from': fields.char('From'),
|
||||||
'email_to': fields.char('Send to Emails'),
|
'email_to': fields.char('Send to Emails'),
|
||||||
'reply_to': fields.char('Reply To'),
|
'reply_to': fields.char('Reply To'),
|
||||||
'mailing_type': fields.selection(_mailing_type, string='Type', required=True),
|
'mailing_model': fields.selection(_mailing_model, string='Type', required=True),
|
||||||
'contact_list_ids': fields.many2many(
|
'contact_list_ids': fields.many2many(
|
||||||
'mail.mass_mailing.list', 'mail_mass_mailing_list_rel',
|
'mail.mass_mailing.list', 'mail_mass_mailing_list_rel',
|
||||||
string='Mailing Lists',
|
string='Mailing Lists',
|
||||||
domain="[('model', '=', mailing_type)]",
|
domain="[('model', '=', mailing_model)]",
|
||||||
),
|
),
|
||||||
'contact_nbr': fields.integer('Contact Number'),
|
'contact_nbr': fields.integer('Contact Number'),
|
||||||
# statistics data
|
# statistics data
|
||||||
|
@ -455,7 +452,7 @@ class MassMailing(osv.Model):
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
'date': fields.datetime.now,
|
'date': fields.datetime.now,
|
||||||
'email_from': lambda self, cr, uid, ctx=None: self.pool['mail.message']._get_default_from(cr, uid, context=ctx),
|
'email_from': lambda self, cr, uid, ctx=None: self.pool['mail.message']._get_default_from(cr, uid, context=ctx),
|
||||||
'mailing_type': 'res.partner',
|
'mailing_model': 'res.partner',
|
||||||
}
|
}
|
||||||
|
|
||||||
#------------------------------------------------------
|
#------------------------------------------------------
|
||||||
|
@ -491,7 +488,7 @@ class MassMailing(osv.Model):
|
||||||
# Views & Actions
|
# Views & Actions
|
||||||
#------------------------------------------------------
|
#------------------------------------------------------
|
||||||
|
|
||||||
def on_change_mailing_type(self, cr, uid, ids, mailing_type, context=None):
|
def on_change_mailing_model(self, cr, uid, ids, mailing_model, context=None):
|
||||||
return {'value': {'contact_list_ids': []}}
|
return {'value': {'contact_list_ids': []}}
|
||||||
|
|
||||||
def on_change_template_id(self, cr, uid, ids, template_id, context=None):
|
def on_change_template_id(self, cr, uid, ids, template_id, context=None):
|
||||||
|
@ -509,19 +506,41 @@ class MassMailing(osv.Model):
|
||||||
values['body_html'] = False
|
values['body_html'] = False
|
||||||
return {'value': values}
|
return {'value': values}
|
||||||
|
|
||||||
|
def select_customers(self, cr, uid, ids, context=None):
|
||||||
|
wizard = self.browse(cr, uid, ids[0], context=context)
|
||||||
|
aid = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'mass_mailing.action_partner_to_mailing_list')
|
||||||
|
ctx = dict(context, view_manager_highlight=[aid])
|
||||||
|
return {
|
||||||
|
'name': _('Choose Recipients'),
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'view_type': 'form',
|
||||||
|
'view_mode': 'tree,form',
|
||||||
|
'res_model': wizard.mailing_model,
|
||||||
|
'context': ctx,
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------
|
||||||
|
# Email Sending
|
||||||
|
#------------------------------------------------------
|
||||||
|
|
||||||
|
def send_get_recipients(self, cr, uid, ids, context=None):
|
||||||
|
recipients = dict.fromkeys(ids, list())
|
||||||
|
for mailing in self.browse(cr, uid, ids, context=context):
|
||||||
|
list_ids = [contact_list.id for contact_list in mailing.contact_list_ids]
|
||||||
|
# contact-based list: aggregate all contacts
|
||||||
|
if mailing.mailing_model == 'mail.mass_mailing.list':
|
||||||
|
res_ids = [contact.id for contact in contact_list.contact_ids for contact_list in mailing.contact_list_ids]
|
||||||
|
else:
|
||||||
|
domain = self.pool['mail.mass_mailing.list'].compute_domain(cr, uid, list_ids, context=context)
|
||||||
|
res_ids = self.pool[contact_list.model].search(cr, uid, domain, context=context)
|
||||||
|
recipients[mailing.id] = res_ids
|
||||||
|
return recipients
|
||||||
|
|
||||||
def send_mail(self, cr, uid, ids, context=None):
|
def send_mail(self, cr, uid, ids, context=None):
|
||||||
Mail = self.pool['mail.mail']
|
Mail = self.pool['mail.mail']
|
||||||
|
recipients = self.send_get_recipients(cr, uid, ids, context=context)
|
||||||
for mailing in self.browse(cr, uid, ids, context=context):
|
for mailing in self.browse(cr, uid, ids, context=context):
|
||||||
contact_list_ids = [contact_list.id for contact_list in mailing.contact_list_ids]
|
res_ids = recipients.get(mailing.id, list())
|
||||||
|
|
||||||
# contact-based list: aggregate all contacts
|
|
||||||
if mailing.mailing_type == 'mail.mass_mailing.list':
|
|
||||||
res_ids = [contact.id for contact in contact_list.contact_ids for contact_list in mailing.contact_list_ids]
|
|
||||||
elif mailing.mailing_type == 'res.partner':
|
|
||||||
domain = self.pool['mail.mass_mailing.list'].compute_domain(cr, uid, contact_list_ids, context=context)
|
|
||||||
print domain
|
|
||||||
res_ids = self.pool[contact_list.model].search(cr, uid, domain, context=context)
|
|
||||||
|
|
||||||
all_mail_values = self.pool['mail.compose.message'].generate_email_for_composer_batch(
|
all_mail_values = self.pool['mail.compose.message'].generate_email_for_composer_batch(
|
||||||
cr, uid, mailing.template_id.id, res_ids,
|
cr, uid, mailing.template_id.id, res_ids,
|
||||||
context=context,
|
context=context,
|
||||||
|
@ -535,7 +554,7 @@ class MassMailing(osv.Model):
|
||||||
'body_html': mail_values.get('body'),
|
'body_html': mail_values.get('body'),
|
||||||
'auto_delete': True,
|
'auto_delete': True,
|
||||||
'statistics_ids': [(0, 0, {
|
'statistics_ids': [(0, 0, {
|
||||||
'model': mailing.mailing_type,
|
'model': mailing.mailing_model,
|
||||||
'res_id': res_id,
|
'res_id': res_id,
|
||||||
'mass_mailing_id': mailing.id,
|
'mass_mailing_id': mailing.id,
|
||||||
})]
|
})]
|
||||||
|
@ -546,10 +565,10 @@ class MassMailing(osv.Model):
|
||||||
'mail.message', 0,
|
'mail.message', 0,
|
||||||
context=context)
|
context=context)
|
||||||
mail_values['attachment_ids'] = m2m_attachment_ids
|
mail_values['attachment_ids'] = m2m_attachment_ids
|
||||||
if mailing.mailing_type == 'mail.mass_mailing.list':
|
if mailing.mailing_model == 'mail.mass_mailing.list':
|
||||||
contact = self.pool['mail.mass_mailing.contact'].browse(cr, uid, res_id, context=context)
|
contact = self.pool['mail.mass_mailing.contact'].browse(cr, uid, res_id, context=context)
|
||||||
mail_values['email_to'] = '"%s" <%s>' % (contact.name, contact.email)
|
mail_values['email_to'] = '"%s" <%s>' % (contact.name, contact.email)
|
||||||
elif mailing.mailing_type == 'res.partner':
|
elif mailing.mailing_model == 'res.partner':
|
||||||
mail_values['recipient_ids'] = [(4, res_id)]
|
mail_values['recipient_ids'] = [(4, res_id)]
|
||||||
Mail.create(cr, uid, mail_values, context=context)
|
Mail.create(cr, uid, mail_values, context=context)
|
||||||
# todo: handle email_to
|
# todo: handle email_to
|
||||||
|
@ -570,26 +589,6 @@ class MassMailing(osv.Model):
|
||||||
Mail.send(cr, uid, [mail_id], context=context)
|
Mail.send(cr, uid, [mail_id], context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def select_customers(self, cr, uid, ids, context=None):
|
|
||||||
sid = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'base.view_res_partner_filter')
|
|
||||||
|
|
||||||
aid = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'mass_mailing.action_partner_to_mailing_list')
|
|
||||||
print sid, aid
|
|
||||||
ctx = dict(context)
|
|
||||||
ctx['view_manager_highlight'] = [aid]
|
|
||||||
return {
|
|
||||||
'name': _('Choose Customers'),
|
|
||||||
'type': 'ir.actions.act_window',
|
|
||||||
'view_type': 'form',
|
|
||||||
'view_mode': 'tree,form',
|
|
||||||
'res_model': 'res.partner',
|
|
||||||
# 'views': [(False, 'tree'), (False, 'form')],
|
|
||||||
'view_id': False,
|
|
||||||
'search_view_id': sid,
|
|
||||||
# 'target': 'new',
|
|
||||||
'context': ctx,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class MailMailStats(osv.Model):
|
class MailMailStats(osv.Model):
|
||||||
""" MailMailStats models the statistics collected about emails. Those statistics
|
""" MailMailStats models the statistics collected about emails. Those statistics
|
||||||
|
|
|
@ -218,8 +218,8 @@
|
||||||
<label for="contact_list_ids" string="Recipients"/>
|
<label for="contact_list_ids" string="Recipients"/>
|
||||||
<div>
|
<div>
|
||||||
<field name="contact_nbr" class="oe_inline" readonly="True"/>
|
<field name="contact_nbr" class="oe_inline" readonly="True"/>
|
||||||
<field name="mailing_type" class="oe_inline"
|
<field name="mailing_model" class="oe_inline"
|
||||||
on_change='on_change_mailing_type(mailing_type, context)'/>
|
on_change='on_change_mailing_model(mailing_model, context)'/>
|
||||||
<span>selected</span>
|
<span>selected</span>
|
||||||
<group>
|
<group>
|
||||||
<label for="contact_list_ids" string="Selected Lists"/>
|
<label for="contact_list_ids" string="Selected Lists"/>
|
||||||
|
|
Loading…
Reference in New Issue