[IMP] mail, email_template: better consistence of mail.compose.message mdoel ans 0 or res_id res_id for attachments on composer; generate_email_for_composer should avoid returning keys for void values.
bzr revid: tde@openerp.com-20130306134612-yazwi6cgwvw8suyw
This commit is contained in:
parent
d794920d43
commit
4665d10f05
|
@ -69,12 +69,11 @@ class mail_compose_message(osv.TransientModel):
|
|||
for wizard in self.browse(cr, uid, ids, context=context):
|
||||
if not wizard.attachment_ids or wizard.composition_mode == 'mass_mail' or not wizard.template_id:
|
||||
continue
|
||||
active_model_pool_name = wizard.model if wizard.model else 'mail.thread'
|
||||
template = self.pool.get('email.template').browse(cr, uid, wizard.template_id, context=context)
|
||||
new_attachment_ids = []
|
||||
for attachment in wizard.attachment_ids:
|
||||
if attachment in template.attachment_ids:
|
||||
new_attachment_ids.append(self.pool.get('ir.attachment').copy(cr, uid, attachment.id, {'res_model': active_model_pool_name, 'res_id': wizard.res_id}, context=context))
|
||||
new_attachment_ids.append(self.pool.get('ir.attachment').copy(cr, uid, attachment.id, {'res_model': 'mail.compose.message', 'res_id': wizard.id}, context=context))
|
||||
else:
|
||||
new_attachment_ids.append(attachment.id)
|
||||
self.write(cr, uid, wizard.id, {'attachment_ids': [(6, 0, new_attachment_ids)]}, context=context)
|
||||
|
@ -87,10 +86,10 @@ class mail_compose_message(osv.TransientModel):
|
|||
values = self.pool.get('email.template').read(cr, uid, template_id, ['subject', 'body_html', 'attachment_ids'], context)
|
||||
values.pop('id')
|
||||
elif template_id:
|
||||
# FIXME odo: change the mail generation to avoid attachment duplication
|
||||
values = self.generate_email_for_composer(cr, uid, template_id, res_id, context=context)
|
||||
# transform attachments into attachment_ids; not attached to the document because this will
|
||||
# be done further in the posting process, allowing to clean database if email not send
|
||||
values['attachment_ids'] = values.pop('attachment_ids', [])
|
||||
ir_attach_obj = self.pool.get('ir.attachment')
|
||||
for attach_fname, attach_datas in values.pop('attachments', []):
|
||||
data_attach = {
|
||||
|
@ -141,15 +140,12 @@ class mail_compose_message(osv.TransientModel):
|
|||
mail.compose.message, transform email_cc and email_to into partner_ids """
|
||||
template_values = self.pool.get('email.template').generate_email(cr, uid, template_id, res_id, context=context)
|
||||
# filter template values
|
||||
values = {
|
||||
'attachment_ids': [],
|
||||
'partner_ids': [],
|
||||
}
|
||||
fields = ['body_html', 'subject', 'email_to', 'email_recipients', 'email_cc', 'attachment_ids', 'attachments']
|
||||
values.update(dict((field, template_values[field]) for field in fields if template_values.get(field)))
|
||||
values = dict((field, template_values[field]) for field in fields if template_values.get(field))
|
||||
values['body'] = values.pop('body_html', '')
|
||||
|
||||
# transform email_to, email_cc into partner_ids
|
||||
values['partner_ids'] = []
|
||||
mails = tools.email_split(values.pop('email_to', '') + ' ' + values.pop('email_cc', ''))
|
||||
for mail in mails:
|
||||
partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context)
|
||||
|
@ -170,6 +166,8 @@ class mail_compose_message(osv.TransientModel):
|
|||
values = self.generate_email_for_composer(cr, uid, wizard.template_id, res_id, context=context)
|
||||
else:
|
||||
values = {}
|
||||
# remove attachments as they should not be rendered
|
||||
values.pop('attachment_ids', None)
|
||||
# get values to return
|
||||
email_dict = super(mail_compose_message, self).render_message(cr, uid, wizard, res_id, context)
|
||||
values.update(email_dict)
|
||||
|
|
|
@ -761,7 +761,7 @@ class mail_message(osv.Model):
|
|||
attachments_to_delete = []
|
||||
for message in self.browse(cr, uid, ids, context=context):
|
||||
for attach in message.attachment_ids:
|
||||
if attach.res_model == self._name and attach.res_id == message.id:
|
||||
if attach.res_model == self._name and (attach.res_id == message.id or attach.res_id == 0):
|
||||
attachments_to_delete.append(attach.id)
|
||||
if attachments_to_delete:
|
||||
self.pool.get('ir.attachment').unlink(cr, uid, attachments_to_delete, context=context)
|
||||
|
|
|
@ -944,7 +944,6 @@ class mail_thread(osv.AbstractModel):
|
|||
if attachment_ids:
|
||||
filtered_attachment_ids = ir_attachment.search(cr, SUPERUSER_ID, [
|
||||
('res_model', '=', 'mail.compose.message'),
|
||||
('res_id', '=', 0),
|
||||
('create_uid', '=', uid),
|
||||
('id', 'in', attachment_ids)], context=context)
|
||||
if filtered_attachment_ids:
|
||||
|
|
Loading…
Reference in New Issue