diff --git a/addons/crm/wizard/email_compose_message.py b/addons/crm/wizard/email_compose_message.py index f2241abfdcc..c7e389e3470 100644 --- a/addons/crm/wizard/email_compose_message.py +++ b/addons/crm/wizard/email_compose_message.py @@ -30,39 +30,79 @@ email_model = [ class email_compose_message(osv.osv_memory): _inherit = 'email.compose.message' + def get_value(self, cr, uid, model, resource_id, context=None): + if context is None: + context = {} + result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context) + if model not in email_model: + return result + model_obj = self.pool.get(model) + data = model_obj.browse(cr, uid , resource_id, context) + result.update({ + 'name' : data.name, + 'email_to' : data.email_from, + 'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False, + 'description' : '\n' + (tools.ustr(data.user_id.signature or '')), + 'email_cc' : tools.ustr(data.email_cc or '') + }) + if hasattr(data, 'section_id'): + result.update({'reply_to' : data.section_id and data.section_id.reply_to or False}) + return result + 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) if context.get('active_id',False) and context.get('email_model',False) and context.get('email_model') in email_model: - model_obj = self.pool.get(context.get('email_model')) - data = model_obj.browse(cr, uid ,context.get('active_id'), context) + vals = self.get_value(cr, uid, context.get('email_model'), context.get('active_id'), context) if 'name' in fields: - result['name'] = data.name + result.update({'name' : vals.get('name','')}) if 'email_to' in fields: - result['email_to'] = data.email_from + result.update({'email_to' : vals.get('email_to','')}) if 'email_from' in fields: - result['email_from'] = data.user_id and data.user_id.address_id and data.user_id.address_id.email or False + result.update({'email_from' : vals.get('email_from','')}) if 'description' in fields: - result['description'] = '\n' + (tools.ustr(data.user_id.signature or '')) + result.update({'description' : vals.get('description','')}) if 'model' in fields: result['model'] = context.get('email_model','') if 'email_cc' in fields: - result['email_cc'] = tools.ustr(data.email_cc or '') + result.update({'email_cc' : vals.get('email_cc','')}) if 'res_id' in fields: result['res_id'] = context.get('active_id',0) - if 'reply_to' in fields and hasattr(data, 'section_id'): - result['reply_to'] = data.section_id and data.section_id.reply_to or False + if 'reply_to' in fields: + result['reply_to'] = vals.get('reply_to','') return result + def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None): + if context is None: + context = {} + if context.get('mail') == 'reply': + return {'value':{}} + result = super(email_compose_message, self).on_change_referred_doc(cr, uid, ids, model, resource_id, context=context) + value = {} + if not result.get('value'): + result.update({'value':{}}) + if resource_id and model in email_model: + vals = self.get_value(cr, uid, model, resource_id, context) + result['value'].update({ + 'email_from': vals.get('email_from',''), + 'email_to': vals.get('email_to',''), + 'name': vals.get('name',''), + 'description': vals.get('description',''), + 'email_cc': vals.get('email_cc',''), + 'email_bcc': vals.get('email_bcc',''), + 'reply_to': vals.get('reply_to',''), + }) + return result + email_compose_message() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/email_template/wizard/email_compose_message.py b/addons/email_template/wizard/email_compose_message.py index 1214595c68e..01f31b0a7fa 100644 --- a/addons/email_template/wizard/email_compose_message.py +++ b/addons/email_template/wizard/email_compose_message.py @@ -95,7 +95,7 @@ class email_compose_message(osv.osv_memory): model = context.get('email_model') if model: record_ids = email_temp_pool.search(cr, uid, [('model','=',model)]) - return email_temp_pool.name_get(cr, uid, record_ids, context) + return email_temp_pool.name_get(cr, uid, record_ids, context) + [(False,'')] return [] _columns = { @@ -110,31 +110,17 @@ class email_compose_message(osv.osv_memory): 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: + 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}) - if template_id and resource_id: context.update({'template_id': template_id}) value = email_temp_previ_pool.on_change_ref(cr, uid, [], resource_id, context) - new_value = value.get('value',{}) - if vals.get('email_from'): - new_value.get('email_from') and new_value.update({'email_from': new_value.get('email_from') + ',' + vals.get('email_from')}) or vals.get('email_from') - - if vals.get('email_to'): - new_value.update({'email_to': new_value.get('email_to') + ',' + vals.get('email_to')}) or vals.get('email_to') - - if vals.get('email_cc'): - new_value.get('email_cc') and new_value.update({'email_cc': new_value.get('email_cc') + ',' + vals.get('email_cc')}) or vals.get('email_cc') - - if vals.get('email_bcc'): - new_value.get('email_bcc') and new_value.update({'email_bcc': new_value.get('email_bcc') + ',' + vals.get('email_bcc')}) or vals.get('email_bcc') - - if vals.get('reply_to'): - new_value.get('reply_to') and new_value.update({'reply_to': new_value.get('reply_to') + ',' + vals.get('reply_to')}) or vals.get('reply_to') - - vals.update(new_value) - vals.update({'name': new_value.get('subject','')}) + 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']}) + else: + vals.update({'attachment_ids' : []}) return {'value': vals} email_compose_message() diff --git a/addons/email_template/wizard/email_template_preview.py b/addons/email_template/wizard/email_template_preview.py index 09abd9fe8ff..175722a2ea2 100644 --- a/addons/email_template/wizard/email_template_preview.py +++ b/addons/email_template/wizard/email_template_preview.py @@ -95,7 +95,11 @@ class email_template_preview(osv.osv_memory): elif template.track_campaign_item: vals['message_id'] = tools.misc.generate_tracking_message_id(res_id) vals['subject'] = self.get_template_value(cr, uid, template.subject, model, res_id, context) - vals['description'] = self.get_template_value(cr, uid, template.description, model, res_id, context) + description = self.get_template_value(cr, uid, template.description, model, res_id, context) or '' + if template.user_signature: + signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature + description += '\n' + signature + vals['description'] = description vals['report_name'] = self.get_template_value(cr, uid, template.report_name, model, res_id, context) return {'value':vals} diff --git a/addons/emails/email_view.xml b/addons/emails/email_view.xml index a88764dd883..09b723d991b 100644 --- a/addons/emails/email_view.xml +++ b/addons/emails/email_view.xml @@ -21,7 +21,7 @@ - + @@ -72,7 +72,7 @@ email.message tree - + @@ -101,6 +101,7 @@ + diff --git a/addons/emails/wizard/email_compose_message.py b/addons/emails/wizard/email_compose_message.py index 059e5f5e9b0..ba8ffea016d 100644 --- a/addons/emails/wizard/email_compose_message.py +++ b/addons/emails/wizard/email_compose_message.py @@ -132,9 +132,18 @@ class email_compose_message(osv.osv_memory): 'res_id':fields.selection(_get_records, 'Referred Document'), } + def get_value(self, cr, uid, model, resource_id, context=None): + return {} + def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None): return {'value':{}} + def on_change_smtp_server(self, cr, uid, ids, smtp_server_id, email_from, context=None): + if not email_from and smtp_server_id: + email_smtp_server_pool = self.pool.get("email.smtp_server") + email_from = email_smtp_server_pool.browse(cr, uid, smtp_server_id, context).email_id or False + return {'value':{'email_from': email_from}} + def save_to_drafts(self, cr, uid, ids, context=None): if context is None: context = {} diff --git a/addons/emails/wizard/email_compose_message_view.xml b/addons/emails/wizard/email_compose_message_view.xml index 9cb9a6d43fc..a4984ff1ad8 100644 --- a/addons/emails/wizard/email_compose_message_view.xml +++ b/addons/emails/wizard/email_compose_message_view.xml @@ -12,7 +12,8 @@ - + diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py index 892313c0102..e69bbdf87a2 100644 --- a/addons/fetchmail/fetchmail.py +++ b/addons/fetchmail/fetchmail.py @@ -116,7 +116,7 @@ class email_server(osv.osv): if context is None: context = {} for server in self.browse(cr, uid, ids, context=context): - logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail start checking for new emails on %s' % (server.name)) + 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}) try: if server.type == 'imap': @@ -167,8 +167,8 @@ class email_server(osv.osv): for server in self.browse(cr, uid, ids, context=context): count = 0 user = server.user_id.id or uid - try: - if server.type == 'imap': + if server.type == 'imap': + try: imap_server = self.button_confirm_login(cr, uid, [server.id], context=context) imap_server.select() result, data = imap_server.search(None, '(UNSEEN)') @@ -180,14 +180,18 @@ class email_server(osv.osv): imap_server.store(num, '+FLAGS', '\\Seen') count += 1 - logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail fetch/process %s email(s) from %s' % (count, server.name)) + logger.notifyChannel(server.type, netsvc.LOG_INFO, 'fetchmail fetch/process %s email(s) from %s' % (count, server.name)) + except Exception, e: + logger.notifyChannel(server.type, netsvc.LOG_WARNING, '%s' % (tools.ustr(e))) + finally: imap_server.close() imap_server.logout() - elif server.type == 'pop': + elif server.type == 'pop': + try: pop_server = self.button_confirm_login(cr, uid, [server.id], context=context) - pop_server.list() (numMsgs, totalSize) = pop_server.stat() + pop_server.list() for num in range(1, numMsgs + 1): (header, msges, octets) = pop_server.retr(num) msg = '\n'.join(msges) @@ -196,14 +200,11 @@ class email_server(osv.osv): action_pool.run(cr, user, [server.action_id.id], {'active_id': res_id, 'active_ids':[res_id]}) pop_server.dele(num) - + logger.notifyChannel(server.type, netsvc.LOG_INFO, 'fetchmail fetch %s email(s) from %s' % (numMsgs, server.name)) + except Exception, e: + logger.notifyChannel(server.type, netsvc.LOG_WARNING, '%s' % (tools.ustr(e))) + finally: pop_server.quit() - - logger.notifyChannel('imap', netsvc.LOG_INFO, 'fetchmail fetch %s email(s) from %s' % (numMsgs, server.name)) - - except Exception, e: - logger.notifyChannel(server.type, netsvc.LOG_WARNING, '%s' % (tools.ustr(e))) - return True email_server() diff --git a/addons/fetchmail/fetchmail_view.xml b/addons/fetchmail/fetchmail_view.xml index f03d8f91a72..fec467083a7 100644 --- a/addons/fetchmail/fetchmail_view.xml +++ b/addons/fetchmail/fetchmail_view.xml @@ -126,10 +126,6 @@ search - - - - diff --git a/addons/hr_evaluation/wizard/email_compose_message.py b/addons/hr_evaluation/wizard/email_compose_message.py index fda67e4131c..7095659f164 100644 --- a/addons/hr_evaluation/wizard/email_compose_message.py +++ b/addons/hr_evaluation/wizard/email_compose_message.py @@ -68,11 +68,16 @@ class email_compose_message(osv.osv_memory): record_data = model_pool.browse(cr, uid, resource_id, context) if record_data.state == "waiting_answer": msg = _("Hello %s, \n\n Kindly post your response for '%s' survey interview. \n\n Thanks,") %(record_data.user_to_review_id.name, record_data.survey_id.title) - result['value'].update({'email_from': tools.config.get('email_from','')}) - result['value'].update({'email_to': record_data.user_to_review_id.work_email or False}) - result['value'].update({'name': _("Reminder to fill up Survey")}) - result['value'].update({'description': msg }) - result['value'].update({'res_id': resource_id}) + result['value'].update({ + 'email_from': tools.config.get('email_from',''), + 'email_to': record_data.user_to_review_id.work_email or False, + 'name': _("Reminder to fill up Survey"), + 'description': msg, + 'res_id': resource_id, + 'email_cc': False, + 'email_bcc': False, + 'reply_to': False, + }) return result email_compose_message() diff --git a/addons/project/wizard/email_compose_message.py b/addons/project/wizard/email_compose_message.py index 042cdd61a30..59b7258eb9d 100644 --- a/addons/project/wizard/email_compose_message.py +++ b/addons/project/wizard/email_compose_message.py @@ -26,56 +26,91 @@ from tools.translate import _ class email_compose_message(osv.osv_memory): _inherit = 'email.compose.message' + def get_value(self, cr, uid, model, resource_id, context=None): + if context is None: + context = {} + result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context) + if model != 'project.task': + return result + task_pool = self.pool.get('project.task') + task_data = task_pool.browse(cr, uid, resource_id, context=context) + partner = task_data.partner_id or task_data.project_id.partner_id + + result.update({'email_from': task_data.user_id and task_data.user_id.user_email or False}) + val = { + 'name': task_data.name, + 'user_id': task_data.user_id.name, + 'task_id': "%d/%d" % (task_data.project_id.id, task_data.id), + 'date_start': task_data.date_start, + 'date': task_data.date_end, + 'state': task_data.state + } + header = (task_data.project_id.warn_header or '') % val + footer = (task_data.project_id.warn_footer or '') % val + description = u'%s\n %s\n %s\n\n \n%s' % (header, task_data.description or '', footer, task_data.user_id and task_data.user_id.signature) + result.update({'description': description or False}) + result.update({'email_to': task_data.project_id.user_id and task_data.project_id.user_id.user_email or False}) + if partner and len(partner.address) and 'email_to' in fields: + result.update({'email_to': result.get('email_to',False) and result.get('email_to') + ',' + partner.address[0].email}) + result.update({'name': _("Task '%s' Closed") % task_data.name}) + + return result + 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) - if context.get('active_id',False) and context.get('active_model',False) and context.get('active_model') == 'project.task': + if context.get('active_id',False) and context.get('email_model',False) and context.get('email_model') == 'project.task': task_pool = self.pool.get('project.task') task_data = task_pool.browse(cr, uid, context.get('active_id'), context=context) - project = task_data.project_id - manager = project.user_id or False partner = task_data.partner_id or task_data.project_id.partner_id - if project.warn_manager and (not manager or manager and not manager.user_email) : + if task_data.project_id.warn_manager and (not task_data.project_id.user_id or task_data.project_id.user_id and not task_data.project_id.user_id.user_email) : raise osv.except_osv(_('Error'), _("Please specify the Project Manager or email address of Project Manager.")) - elif project.warn_customer and (not partner or not len(partner.address) or (partner and len(partner.address) and not partner.address[0].email)): + elif task_data.project_id.warn_customer and (not partner or not len(partner.address) or (partner and len(partner.address) and not partner.address[0].email)): raise osv.except_osv(_('Error'), _("Please specify the Customer or email address of Customer.")) - + vals = self.get_value(cr, uid, context.get('email_model'), context.get('active_id'), context) if 'email_from' in fields: - result.update({'email_from': task_data.user_id and task_data.user_id.user_email or False}) + result.update({'email_from': vals.get('email_from','')}) if 'description' in fields: - val = { - 'name': task_data.name, - 'user_id': task_data.user_id.name, - 'task_id': "%d/%d" % (project.id, task_data.id), - 'date_start': task_data.date_start, - 'date': task_data.date_end, - 'state': task_data.state - } - header = (project.warn_header or '') % val - footer = (project.warn_footer or '') % val - description = u'%s\n %s\n %s\n\n \n%s' % (header, task_data.description or '', footer, task_data.user_id and task_data.user_id.signature) - result.update({'description': description or False}) + result.update({'description': vals.get('description','')}) if 'email_to' in fields: - result.update({'email_to': manager and manager.user_email or False}) - - if partner and len(partner.address) and 'email_to' in fields: - result.update({'email_to': result.get('email_to',False) and result.get('email_to') + ',' + partner.address[0].email}) + result.update({'description': vals.get('description','')}) if 'name' in fields: - result.update({'name': _("Task '%s' Closed") % task_data.name}) + result.update({'description': vals.get('name','')}) if 'model' in fields: - result.update({'model':context.get('active_model')}) + result.update({'model':context.get('email_model')}) if 'res_id' in fields: result.update({'res_id':context.get('active_id')}) return result + def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None): + if context is None: + context = {} + if context.get('mail') == 'reply': + return {'value':{}} + result = super(email_compose_message, self).on_change_referred_doc(cr, uid, ids, model, resource_id, context=context) + if not result.get('value'): + result.update({'value':{}}) + if resource_id and model == 'project.task': + vals = self.get_value(cr, uid, model, resource_id, context) + result.get('value',{}).update({ + 'email_from': vals.get('email_from',''), + 'email_to': vals.get('email_to',''), + 'description': vals.get('description',''), + 'name': vals.get('name',''), + 'email_cc': vals.get('email_cc',''), + 'email_bcc': vals.get('email_bcc',''), + 'reply_to': vals.get('reply_to',''), + }) + return result + email_compose_message() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/project_scrum/wizard/email_compose_message.py b/addons/project_scrum/wizard/email_compose_message.py index fc97709459d..1354196275a 100644 --- a/addons/project_scrum/wizard/email_compose_message.py +++ b/addons/project_scrum/wizard/email_compose_message.py @@ -26,35 +26,49 @@ from tools.translate import _ class email_compose_message(osv.osv_memory): _inherit = 'email.compose.message' + def get_value(self, cr, uid, model, resource_id, context=None): + if context is None: + context = {} + result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context) + if model != 'project.scrum.meeting': + return result + meeting_pool = self.pool.get('project.scrum.meeting') + user_pool = self.pool.get('res.users') + meeting = meeting_pool.browse(cr, uid, resource_id, context=context) + + sprint = meeting.sprint_id + user_data = user_pool.browse(cr, uid, uid, context=context) + result.update({'email_from': user_data.address_id and user_data.address_id.email or False}) + + if sprint.scrum_master_id and sprint.scrum_master_id.user_email: + result.update({'email_to': sprint.scrum_master_id.user_email}) + if sprint.product_owner_id and sprint.product_owner_id.user_email: + result.update({'email_to': result.get('email_to',False) and result.get('email_to') + ',' + sprint.product_owner_id.user_email or sprint.product_owner_id.user_email}) + + subject = _("Scrum Meeting : %s") %(meeting.date) + result.update({'name': subject}) + message = _("Hello , \nI am sending you Scrum Meeting : %s for the Sprint '%s' of Project '%s'") %(meeting.date, sprint.name, sprint.project_id.name) + result.update({'description': message}) + return result + 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) if context.get('active_id',False) and context.get('email_model',False) and context.get('email_model') == 'project.scrum.meeting': - - meeting_pool = self.pool.get('project.scrum.meeting') - user_pool = self.pool.get('res.users') - meeting = meeting_pool.browse(cr, uid, context.get('active_id'), context=context) - sprint = meeting.sprint_id - + vals = self.get_value(cr, uid, context.get('email_model'), context.get('active_id'), context) if 'email_from' in fields: - user_data = user_pool.browse(cr, uid, uid, context=context) - result.update({'email_from': user_data.address_id and user_data.address_id.email or False}) + result.update({'email_from': vals.get('email_from','')}) - if 'email_to' in fields and sprint.scrum_master_id and sprint.scrum_master_id.user_email: - result.update({'email_to': sprint.scrum_master_id.user_email}) - - if sprint.product_owner_id and sprint.product_owner_id.user_email: - result.update({'email_to': result.get('email_to',False) and result.get('email_to') + ',' + sprint.product_owner_id.user_email or sprint.product_owner_id.user_email}) + if 'email_to' in fields: + result.update({'email_to': vals.get('email_to','')}) if 'name' in fields: - subject = _("Scrum Meeting : %s") %(meeting.date) - result.update({'name': subject}) + result.update({'name': vals.get('name','')}) if 'description' in fields: - message = _("Hello , \nI am sending you Scrum Meeting : %s for the Sprint '%s' of Project '%s'") %(meeting.date, sprint.name, sprint.project_id.name) - result.update({'description': message}) + result.update({'description': vals.get('description','')}) if 'model' in fields: result.update({'model':context.get('email_model')}) @@ -64,6 +78,27 @@ class email_compose_message(osv.osv_memory): return result + def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None): + if context is None: + context = {} + if context.get('mail') == 'reply': + return {'value':{}} + result = super(email_compose_message, self).on_change_referred_doc(cr, uid, ids, model, resource_id, context=context) + if not result.get('value'): + result.update({'value':{}}) + if resource_id and model == 'project.scrum.meeting': + vals = self.get_value(cr, uid, model, resource_id, context) + result.get('value',{}).update({ + 'email_from': vals.get('email_from',''), + 'email_to': vals.get('email_to',''), + 'description': vals.get('description',''), + 'name': vals.get('name',''), + 'email_cc': vals.get('email_cc',''), + 'email_bcc': vals.get('email_bcc',''), + 'reply_to': vals.get('reply_to',''), + }) + return result + email_compose_message() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: