From d5494f5ea4a7b50277a040ee22a8bab6741f00af Mon Sep 17 00:00:00 2001 From: "Yogesh (OpenERP)" Date: Mon, 28 Feb 2011 17:09:19 +0530 Subject: [PATCH] [IMP] emails,crm,project,project_scrum :- improve email.compose.wizard and add blank value add in selection box of template_id field in wizard. if template_id blank then default value set based on current record. bzr revid: ysa@tinyerp.com-20110228113919-d7quaz8uqmjnkuzh --- addons/crm/wizard/email_compose_message.py | 58 +++++++++++-- .../wizard/email_compose_message.py | 24 +----- .../wizard/email_template_preview.py | 6 +- addons/emails/wizard/email_compose_message.py | 3 + .../wizard/email_compose_message.py | 15 ++-- .../project/wizard/email_compose_message.py | 85 +++++++++++++------ .../wizard/email_compose_message.py | 69 +++++++++++---- 7 files changed, 183 insertions(+), 77 deletions(-) diff --git a/addons/crm/wizard/email_compose_message.py b/addons/crm/wizard/email_compose_message.py index f2241abfdcc..27163e0931e 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(context.get('email_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..f944c503a17 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,15 @@ 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') + vals.update(value.get('value',{})) + vals.update({'name': value.get('value',{}).get('subject','')}) - 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','')}) 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/wizard/email_compose_message.py b/addons/emails/wizard/email_compose_message.py index 059e5f5e9b0..76eadaade5f 100644 --- a/addons/emails/wizard/email_compose_message.py +++ b/addons/emails/wizard/email_compose_message.py @@ -132,6 +132,9 @@ 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':{}} 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: