[FIX] email_template: email_template.preview.fields_view_get() is broken
bzr revid: psi@tinyerp.co.in-20101026084722-00oyp8j3d92yxqkh
This commit is contained in:
parent
2cc265aaef
commit
c73e17329c
|
@ -103,7 +103,7 @@ def get_value(cursor, user, recid, message=None, template=None, context=None):
|
||||||
|
|
||||||
class email_template(osv.osv):
|
class email_template(osv.osv):
|
||||||
"Templates for sending Email"
|
"Templates for sending Email"
|
||||||
|
|
||||||
_name = "email.template"
|
_name = "email.template"
|
||||||
_description = 'Email Templates for Models'
|
_description = 'Email Templates for Models'
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ class email_template(osv.osv):
|
||||||
'def_to':fields.char(
|
'def_to':fields.char(
|
||||||
'Recipient (To)',
|
'Recipient (To)',
|
||||||
size=250,
|
size=250,
|
||||||
help="The Recipient of email. "
|
help="The Recipient of email. "
|
||||||
"Placeholders can be used here. "
|
"Placeholders can be used here. "
|
||||||
"e.g. ${object.email_to}"),
|
"e.g. ${object.email_to}"),
|
||||||
'def_cc':fields.char(
|
'def_cc':fields.char(
|
||||||
|
@ -146,20 +146,20 @@ class email_template(osv.osv):
|
||||||
help="Blind Carbon Copy address(es), comma-separated."
|
help="Blind Carbon Copy address(es), comma-separated."
|
||||||
" Placeholders can be used here. "
|
" Placeholders can be used here. "
|
||||||
"e.g. ${object.email_bcc}"),
|
"e.g. ${object.email_bcc}"),
|
||||||
'reply_to':fields.char('Reply-To',
|
'reply_to':fields.char('Reply-To',
|
||||||
size=250,
|
size=250,
|
||||||
help="The address recipients should reply to,"
|
help="The address recipients should reply to,"
|
||||||
" if different from the From address."
|
" if different from the From address."
|
||||||
" Placeholders can be used here. "
|
" Placeholders can be used here. "
|
||||||
"e.g. ${object.email_reply_to}"),
|
"e.g. ${object.email_reply_to}"),
|
||||||
'message_id':fields.char('Message-ID',
|
'message_id':fields.char('Message-ID',
|
||||||
size=250,
|
size=250,
|
||||||
help="Specify the Message-ID SMTP header to use in outgoing emails. Please note that this overrides the Resource tracking option! Placeholders can be used here."),
|
help="Specify the Message-ID SMTP header to use in outgoing emails. Please note that this overrides the Resource tracking option! Placeholders can be used here."),
|
||||||
'track_campaign_item':fields.boolean('Resource Tracking',
|
'track_campaign_item':fields.boolean('Resource Tracking',
|
||||||
help="Enable this is you wish to include a special \
|
help="Enable this is you wish to include a special \
|
||||||
tracking marker in outgoing emails so you can identify replies and link \
|
tracking marker in outgoing emails so you can identify replies and link \
|
||||||
them back to the corresponding resource record. \
|
them back to the corresponding resource record. \
|
||||||
This is useful for CRM leads for example"),
|
This is useful for CRM leads for example"),
|
||||||
'lang':fields.char(
|
'lang':fields.char(
|
||||||
'Language',
|
'Language',
|
||||||
size=250,
|
size=250,
|
||||||
|
@ -182,7 +182,7 @@ This is useful for CRM leads for example"),
|
||||||
translate=True),
|
translate=True),
|
||||||
'use_sign':fields.boolean(
|
'use_sign':fields.boolean(
|
||||||
'Signature',
|
'Signature',
|
||||||
help="the signature from the User details"
|
help="the signature from the User details"
|
||||||
" will be appended to the mail"),
|
" will be appended to the mail"),
|
||||||
'file_name':fields.char(
|
'file_name':fields.char(
|
||||||
'Report Filename',
|
'Report Filename',
|
||||||
|
@ -199,16 +199,16 @@ This is useful for CRM leads for example"),
|
||||||
'attachment_id',
|
'attachment_id',
|
||||||
'Attached Files',
|
'Attached Files',
|
||||||
help="You may attach existing files to this template, "
|
help="You may attach existing files to this template, "
|
||||||
"so they will be added in all emails created from this template"),
|
"so they will be added in all emails created from this template"),
|
||||||
'ref_ir_act_window':fields.many2one(
|
'ref_ir_act_window':fields.many2one(
|
||||||
'ir.actions.act_window',
|
'ir.actions.act_window',
|
||||||
'Window Action',
|
'Window Action',
|
||||||
help="Action that will open this email template on Resource records",
|
help="Action that will open this email template on Resource records",
|
||||||
readonly=True),
|
readonly=True),
|
||||||
'ref_ir_value':fields.many2one(
|
'ref_ir_value':fields.many2one(
|
||||||
'ir.values',
|
'ir.values',
|
||||||
'Wizard Button',
|
'Wizard Button',
|
||||||
help="Button in the side bar of the form view of this Resource that will invoke the Window Action",
|
help="Button in the side bar of the form view of this Resource that will invoke the Window Action",
|
||||||
readonly=True),
|
readonly=True),
|
||||||
'allowed_groups':fields.many2many(
|
'allowed_groups':fields.many2many(
|
||||||
'res.groups',
|
'res.groups',
|
||||||
|
@ -265,7 +265,7 @@ This is useful for CRM leads for example"),
|
||||||
'template_language' : lambda *a:'mako',
|
'template_language' : lambda *a:'mako',
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
('name', 'unique (name)', _('The template name must be unique !'))
|
('name', 'unique (name)', _('The template name must be unique !'))
|
||||||
]
|
]
|
||||||
|
@ -312,11 +312,11 @@ This is useful for CRM leads for example"),
|
||||||
def delete_action(self, cr, uid, ids, context):
|
def delete_action(self, cr, uid, ids, context):
|
||||||
self.unlink_action(cr, uid, ids, context)
|
self.unlink_action(cr, uid, ids, context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def unlink(self, cr, uid, ids, context=None):
|
def unlink(self, cr, uid, ids, context=None):
|
||||||
self.unlink_action(cr, uid, ids, context)
|
self.unlink_action(cr, uid, ids, context)
|
||||||
return super(email_template, self).unlink(cr, uid, ids, context)
|
return super(email_template, self).unlink(cr, uid, ids, context)
|
||||||
|
|
||||||
def copy(self, cr, uid, id, default=None, context=None):
|
def copy(self, cr, uid, id, default=None, context=None):
|
||||||
if default is None:
|
if default is None:
|
||||||
default = {}
|
default = {}
|
||||||
|
@ -328,7 +328,7 @@ This is useful for CRM leads for example"),
|
||||||
new_name = new_name + '_' + random.choice('abcdefghij') + random.choice('lmnopqrs') + random.choice('tuvwzyz')
|
new_name = new_name + '_' + random.choice('abcdefghij') + random.choice('lmnopqrs') + random.choice('tuvwzyz')
|
||||||
default.update({'name':new_name})
|
default.update({'name':new_name})
|
||||||
return super(email_template, self).copy(cr, uid, id, default, context)
|
return super(email_template, self).copy(cr, uid, id, default, context)
|
||||||
|
|
||||||
def build_expression(self, field_name, sub_field_name, null_value, template_language='mako'):
|
def build_expression(self, field_name, sub_field_name, null_value, template_language='mako'):
|
||||||
"""
|
"""
|
||||||
Returns a template expression based on data provided
|
Returns a template expression based on data provided
|
||||||
|
@ -354,10 +354,10 @@ This is useful for CRM leads for example"),
|
||||||
if sub_field_name:
|
if sub_field_name:
|
||||||
expression += "." + sub_field_name
|
expression += "." + sub_field_name
|
||||||
if null_value:
|
if null_value:
|
||||||
expression += "|default: '''%s'''" % null_value
|
expression += "|default: '''%s'''" % null_value
|
||||||
expression += "}}"
|
expression += "}}"
|
||||||
return expression
|
return expression
|
||||||
|
|
||||||
def onchange_model_object_field(self, cr, uid, ids, model_object_field, template_language, context=None):
|
def onchange_model_object_field(self, cr, uid, ids, model_object_field, template_language, context=None):
|
||||||
if not model_object_field:
|
if not model_object_field:
|
||||||
return {}
|
return {}
|
||||||
|
@ -385,7 +385,7 @@ This is useful for CRM leads for example"),
|
||||||
result['sub_model_object_field'] = False
|
result['sub_model_object_field'] = False
|
||||||
result['null_value'] = False
|
result['null_value'] = False
|
||||||
return {'value':result}
|
return {'value':result}
|
||||||
|
|
||||||
def onchange_sub_model_object_field(self, cr, uid, ids, model_object_field, sub_model_object_field, template_language, context=None):
|
def onchange_sub_model_object_field(self, cr, uid, ids, model_object_field, sub_model_object_field, template_language, context=None):
|
||||||
if not model_object_field or not sub_model_object_field:
|
if not model_object_field or not sub_model_object_field:
|
||||||
return {}
|
return {}
|
||||||
|
@ -447,7 +447,7 @@ This is useful for CRM leads for example"),
|
||||||
def _add_attachment(self, cursor, user, mailbox_id, name, data, filename, context=None):
|
def _add_attachment(self, cursor, user, mailbox_id, name, data, filename, context=None):
|
||||||
"""
|
"""
|
||||||
Add an attachment to a given mailbox entry.
|
Add an attachment to a given mailbox entry.
|
||||||
|
|
||||||
:param data: base64 encoded attachment data to store
|
:param data: base64 encoded attachment data to store
|
||||||
"""
|
"""
|
||||||
attachment_obj = self.pool.get('ir.attachment')
|
attachment_obj = self.pool.get('ir.attachment')
|
||||||
|
@ -484,7 +484,7 @@ This is useful for CRM leads for example"),
|
||||||
"""
|
"""
|
||||||
Generate report to be attached and attach it
|
Generate report to be attached and attach it
|
||||||
to the email, and add any directly attached files as well.
|
to the email, and add any directly attached files as well.
|
||||||
|
|
||||||
@param cursor: Database Cursor
|
@param cursor: Database Cursor
|
||||||
@param user: ID of User
|
@param user: ID of User
|
||||||
@param template: Browse record of
|
@param template: Browse record of
|
||||||
|
@ -492,8 +492,8 @@ This is useful for CRM leads for example"),
|
||||||
@param record_id: ID of the target model
|
@param record_id: ID of the target model
|
||||||
for which this mail has
|
for which this mail has
|
||||||
to be generated
|
to be generated
|
||||||
@param mail: Browse record of email object
|
@param mail: Browse record of email object
|
||||||
@return: True
|
@return: True
|
||||||
"""
|
"""
|
||||||
if template.report_template:
|
if template.report_template:
|
||||||
reportname = 'report.' + \
|
reportname = 'report.' + \
|
||||||
|
@ -510,7 +510,7 @@ This is useful for CRM leads for example"),
|
||||||
user,
|
user,
|
||||||
[record_id],
|
[record_id],
|
||||||
data,
|
data,
|
||||||
context)
|
context)
|
||||||
fname = tools.ustr(get_value(cursor, user, record_id,
|
fname = tools.ustr(get_value(cursor, user, record_id,
|
||||||
template.file_name, template, context)
|
template.file_name, template, context)
|
||||||
or 'Report')
|
or 'Report')
|
||||||
|
@ -524,7 +524,7 @@ This is useful for CRM leads for example"),
|
||||||
self._add_attachment(cursor, user, mail.id, attachment.name, attachment.datas, attachment.datas_fname, context)
|
self._add_attachment(cursor, user, mail.id, attachment.name, attachment.datas, attachment.datas_fname, context)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _generate_mailbox_item_from_template(self,
|
def _generate_mailbox_item_from_template(self,
|
||||||
cursor,
|
cursor,
|
||||||
user,
|
user,
|
||||||
|
@ -534,7 +534,7 @@ This is useful for CRM leads for example"),
|
||||||
"""
|
"""
|
||||||
Generates an email from the template for
|
Generates an email from the template for
|
||||||
record record_id of target object
|
record record_id of target object
|
||||||
|
|
||||||
@param cursor: Database Cursor
|
@param cursor: Database Cursor
|
||||||
@param user: ID of User
|
@param user: ID of User
|
||||||
@param template: Browse record of
|
@param template: Browse record of
|
||||||
|
@ -542,7 +542,7 @@ This is useful for CRM leads for example"),
|
||||||
@param record_id: ID of the target model
|
@param record_id: ID of the target model
|
||||||
for which this mail has
|
for which this mail has
|
||||||
to be generated
|
to be generated
|
||||||
@return: ID of created object
|
@return: ID of created object
|
||||||
"""
|
"""
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
|
@ -571,9 +571,9 @@ This is useful for CRM leads for example"),
|
||||||
ctx = context.copy()
|
ctx = context.copy()
|
||||||
ctx.update({'lang':lang})
|
ctx.update({'lang':lang})
|
||||||
template = self.browse(cursor, user, template.id, context=ctx)
|
template = self.browse(cursor, user, template.id, context=ctx)
|
||||||
|
|
||||||
# determine name of sender, either it is specified in email_id or we
|
# determine name of sender, either it is specified in email_id or we
|
||||||
# use the account name
|
# use the account name
|
||||||
email_id = from_account['email_id'].strip()
|
email_id = from_account['email_id'].strip()
|
||||||
email_from = re.findall(r'([^ ,<@]+@[^> ,]+)', email_id)[0]
|
email_from = re.findall(r'([^ ,<@]+@[^> ,]+)', email_id)[0]
|
||||||
if email_from != email_id:
|
if email_from != email_id:
|
||||||
|
@ -663,7 +663,7 @@ This is useful for CRM leads for example"),
|
||||||
context)
|
context)
|
||||||
|
|
||||||
return mailbox_id
|
return mailbox_id
|
||||||
|
|
||||||
|
|
||||||
def generate_mail(self,
|
def generate_mail(self,
|
||||||
cursor,
|
cursor,
|
||||||
|
@ -721,7 +721,7 @@ email_template()
|
||||||
class email_template_preview(osv.osv_memory):
|
class email_template_preview(osv.osv_memory):
|
||||||
_name = "email_template.preview"
|
_name = "email_template.preview"
|
||||||
_description = "Email Template Preview"
|
_description = "Email Template Preview"
|
||||||
|
|
||||||
def _get_model_recs(self, cr, uid, context=None):
|
def _get_model_recs(self, cr, uid, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
|
@ -738,6 +738,7 @@ class email_template_preview(osv.osv_memory):
|
||||||
if default_id and default_id not in ref_obj_ids:
|
if default_id and default_id not in ref_obj_ids:
|
||||||
ref_obj_ids.insert(0, default_id)
|
ref_obj_ids.insert(0, default_id)
|
||||||
return model_obj.name_get(cr, uid, ref_obj_ids, context)
|
return model_obj.name_get(cr, uid, ref_obj_ids, context)
|
||||||
|
return []
|
||||||
|
|
||||||
def default_get(self, cr, uid, fields, context=None):
|
def default_get(self, cr, uid, fields, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
|
@ -762,7 +763,7 @@ class email_template_preview(osv.osv_memory):
|
||||||
context['template_id'],
|
context['template_id'],
|
||||||
['object_name'],
|
['object_name'],
|
||||||
context)['object_name']
|
context)['object_name']
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'ref_template':fields.many2one(
|
'ref_template':fields.many2one(
|
||||||
'email.template',
|
'email.template',
|
||||||
|
@ -772,13 +773,13 @@ class email_template_preview(osv.osv_memory):
|
||||||
'to':fields.char('To', size=250, readonly=True),
|
'to':fields.char('To', size=250, readonly=True),
|
||||||
'cc':fields.char('CC', size=250, readonly=True),
|
'cc':fields.char('CC', size=250, readonly=True),
|
||||||
'bcc':fields.char('BCC', size=250, readonly=True),
|
'bcc':fields.char('BCC', size=250, readonly=True),
|
||||||
'reply_to':fields.char('Reply-To',
|
'reply_to':fields.char('Reply-To',
|
||||||
size=250,
|
size=250,
|
||||||
help="The address recipients should reply to,"
|
help="The address recipients should reply to,"
|
||||||
" if different from the From address."
|
" if different from the From address."
|
||||||
" Placeholders can be used here."),
|
" Placeholders can be used here."),
|
||||||
'message_id':fields.char('Message-ID',
|
'message_id':fields.char('Message-ID',
|
||||||
size=250,
|
size=250,
|
||||||
help="The Message-ID header value, if you need to"
|
help="The Message-ID header value, if you need to"
|
||||||
"specify it, for example to automatically recognize the replies later."
|
"specify it, for example to automatically recognize the replies later."
|
||||||
" Placeholders can be used here."),
|
" Placeholders can be used here."),
|
||||||
|
@ -819,7 +820,7 @@ class email_template_preview(osv.osv_memory):
|
||||||
vals['body_html'] = get_value(cr, uid, rel_model_ref, template.def_body_html, template, context)
|
vals['body_html'] = get_value(cr, uid, rel_model_ref, template.def_body_html, template, context)
|
||||||
vals['report'] = get_value(cr, uid, rel_model_ref, template.file_name, template, context)
|
vals['report'] = get_value(cr, uid, rel_model_ref, template.file_name, template, context)
|
||||||
return {'value':vals}
|
return {'value':vals}
|
||||||
|
|
||||||
email_template_preview()
|
email_template_preview()
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
Loading…
Reference in New Issue