From 92864126a905fb401ac33ad07da7ebb57f9e5d7c Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Tue, 1 Mar 2011 15:58:52 +0530 Subject: [PATCH 1/2] [IMP] email_template :- create get_template_data method and remove code in on_change and default_get method. make generic method in email.compose.messageg wizard. bzr revid: ysa@tinyerp.com-20110301102852-c35165ydv2xuufb0 --- .../wizard/email_compose_message.py | 91 +++++++++++-------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/addons/email_template/wizard/email_compose_message.py b/addons/email_template/wizard/email_compose_message.py index a95e0e51f31..37e4c3df9f0 100644 --- a/addons/email_template/wizard/email_compose_message.py +++ b/addons/email_template/wizard/email_compose_message.py @@ -26,55 +26,82 @@ import tools class email_compose_message(osv.osv_memory): _name = 'email.compose.message' _inherit = 'email.compose.message' - def default_get(self, cr, uid, fields, context=None): + + def get_template_data(self, cr, uid, res_id, template_id, context=None): if context is None: context = {} - result = super(email_compose_message, self).default_get(cr, uid, fields, context=context) + result = {} template_pool = self.pool.get('email.template') - model_pool = self.pool.get('ir.model') - template_id = context.get('template_id', False) if template_id: template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context) def _get_template_value(field): if not template: return False - if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets original template values for multiple email change + if len(context.get('src_rec_ids',[])) > 1: # Multiple Mail: Gets original template values for multiple email change return getattr(template, field) else: # Simple Mail: Gets computed template values return template_pool.get_template_value(cr, uid, getattr(template, field), template.model, context.get('email_res_id'), context) + result.update({ + 'template_id' : template.id, + 'smtp_server_id' : template.smtp_server_id.id, + 'description' : _get_template_value('description') or False, + 'name' : _get_template_value('subject') or False, + 'attachment_ids' : template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] or [], + 'res_id' : res_id or False, + 'email_to' : _get_template_value('email_to') or False, + 'email_cc' : _get_template_value('email_cc') or False, + 'email_bcc' : _get_template_value('email_bcc') or False, + 'reply_to' : _get_template_value('reply_to') or False, + 'model' : template.model or False, + }) + return result - if 'template_id' in fields: - result['template_id'] = template.id + def default_get(self, cr, uid, fields, context=None): + if context is None: + context = {} + result = super(email_compose_message, self).default_get(cr, uid, fields, context=context) + template_id = context.get('template_id', False) + vals = {} + if template_id and context.get('email_model') and context.get('email_res_id'): + vals = self.get_template_data(cr, uid, context.get('email_res_id'), template_id, context) + else: + result['model'] = context.get('email_model', False) - if 'smtp_server_id' in fields: - result['smtp_server_id'] = template.smtp_server_id.id + if not vals: + return result - if 'attachment_ids' in fields: - result['attachment_ids'] = template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids'] + if 'template_id' in fields: + result.update({'template_id' : vals.get('template_id', False)}) - if 'model' in fields: - result['model'] = context.get('email_model') + if 'smtp_server_id' in fields: + result.update({'smtp_server_id' : vals.get('smtp_server_id', False)}) - if 'res_id' in fields: - result['res_id'] = context.get('email_res_id') + if 'attachment_ids' in fields: + result.update({'attachment_ids' : vals.get('attachment_ids', False)}) - if 'email_to' in fields: - result['email_to'] = _get_template_value('email_to') + if 'model' in fields: + result.update({'model' : vals.get('model', False)}) - if 'email_cc' in fields: - result['email_cc'] = _get_template_value('email_cc') + if 'res_id' in fields: + result.update({'res_id' : vals.get('res_id', False)}) - if 'email_bcc' in fields: - result['email_bcc'] = _get_template_value('email_bcc') + if 'email_to' in fields: + result.update({'email_to' : vals.get('email_to', False)}) - if 'name' in fields: - result['name'] = _get_template_value('subject') + if 'email_cc' in fields: + result.update({'email_cc' : vals.get('email_cc', False)}) - if 'description' in fields: - result['description'] = _get_template_value('description') + if 'email_bcc' in fields: + result.update({'email_bcc' : vals.get('email_bcc', False)}) - if 'reply_to' in fields: - result['reply_to'] = _get_template_value('reply_to') + if 'name' in fields: + result.update({'name' : vals.get('name', False)}) + + if 'description' in fields: + result.update({'description' : vals.get('description', False)}) + + if 'reply_to' in fields: + result.update({'reply_to' : vals.get('reply_to', False)}) return result @@ -107,18 +134,10 @@ class email_compose_message(osv.osv_memory): context = {} if context.get('mail') == 'reply': return {'value':{}} - email_temp_previ_pool = self.pool.get('email_template.preview') result = self.on_change_referred_doc(cr, uid, [], model, resource_id, context=context) vals = result.get('value',{}) if template_id and resource_id: - email_temp_pool = self.pool.get('email.template') - email_temp_data = email_temp_pool.browse(cr, uid, template_id, context) - vals.update({'smtp_server_id': email_temp_data.smtp_server_id and email_temp_data.smtp_server_id.id or False}) - context.update({'template_id': template_id}) - value = email_temp_previ_pool.on_change_ref(cr, uid, [], resource_id, context) - vals.update(value.get('value',{})) - vals.update({'name': value.get('value',{}).get('subject','')}) - vals.update({'attachment_ids' : email_temp_pool.read(cr, uid, template_id, ['attachment_ids'])['attachment_ids']}) + vals.update(self.get_template_data(cr, uid, resource_id, template_id, context)) else: vals.update({'attachment_ids' : []}) return {'value': vals} From 062c57e4b0f6532ae1e80f2fbf2d0b27e2f020f2 Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Tue, 1 Mar 2011 16:13:05 +0530 Subject: [PATCH 2/2] [REMOVE] fetchmail :- remove server_type in email.message object. bzr revid: ysa@tinyerp.com-20110301104305-qtfqy8fkr8xifime --- addons/fetchmail/fetchmail.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py index e69bbdf87a2..296d592396a 100644 --- a/addons/fetchmail/fetchmail.py +++ b/addons/fetchmail/fetchmail.py @@ -117,7 +117,7 @@ class email_server(osv.osv): context = {} for server in self.browse(cr, uid, ids, context=context): logger.notifyChannel(server.type, netsvc.LOG_INFO, 'fetchmail start checking for new emails on %s' % (server.name)) - context.update({'server_id': server.id, 'server_type': server.type}) + context.update({'server_id': server.id}) try: if server.type == 'imap': imap_server = None @@ -215,22 +215,14 @@ class email_message(osv.osv): _columns = { 'server_id': fields.many2one('email.server', "Mail Server", readonly=True, select=True), - 'server_type':fields.selection([ - ('pop', 'POP Server'), - ('imap', 'IMAP Server'), - ], 'Server Type', select=True, readonly=True), } - _order = 'id desc' def create(self, cr, uid, values, context=None): if context is None: context={} server_id = context.get('server_id',False) - server_type = context.get('server_type',False) if server_id: values['server_id'] = server_id - if server_type: - values['server_type'] = server_type res = super(email_message,self).create(cr, uid, values, context=context) return res @@ -238,11 +230,8 @@ class email_message(osv.osv): if context is None: context={} server_id = context.get('server_id',False) - server_type = context.get('server_type',False) if server_id: values['server_id'] = server_id - if server_type: - values['server_type'] = server_type res = super(email_message,self).write(cr, uid, ids, values, context=context) return res