def action_forward(self, cr, uid, ids, context=None): """ Forward the lead to a partner """ if context is None: context = {} res = {'type': 'ir.actions.act_window_close'} model = context.get('active_model') if model not in ('crm.lead'): return res this = self.browse(cr, uid, ids[0], context=context) lead = self.pool.get(model) lead_id = context and context.get('active_id', False) or False lead_ids = lead_id and [lead_id] or [] mode = context.get('mail.compose.message.mode') if mode == 'mass_mail': lead_ids = context and context.get('active_ids', []) or [] value = self.default_get(cr, uid, ['body_text', 'email_to', 'email_cc', 'subject', 'history'], context=context) self.write(cr, uid, ids, value, context=context) context['mail.compose.message.mode'] = mode self.send_mail(cr, uid, ids, context=context) for case in lead.browse(cr, uid, lead_ids, context=context): if (this.send_to == 'partner' and this.partner_id): lead.assign_partner(cr, uid, [case.id], this.partner_id.id, context=context) if this.send_to == 'user': lead.allocate_salesman(cr, uid, [case.id], [this.user_id.id], context=context) email_cc = to_email(case.email_cc) email_cc = email_cc and email_cc[0] or '' new_cc = [] if email_cc: new_cc.append(email_cc) for to in this.email_to.split(','): email_to = to_email(to) email_to = email_to and email_to[0] or '' if email_to not in new_cc: new_cc.append(to) update_vals = {'email_cc' : ', '.join(new_cc) } lead.write(cr, uid, case.id, update_vals, context=context) return res
def _lead_create_partner_address(self, cr, uid, lead, partner_id, context=None): context = context or self.pool['res.users'].context_get(cr, uid) address_obj = self.pool['res.partner.address'] address_ids = address_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'default')], context=context) if address_ids: address_id = address_ids[0] else: address_id = address_obj.create( cr, uid, { 'type': 'default', 'partner_id': partner_id, 'name': lead.contact_name, 'phone': lead.phone, 'mobile': lead.mobile, 'email': lead.email_from and to_email(lead.email_from)[0], 'fax': lead.fax, 'title': lead.title and lead.title.id or False, 'function': lead.function_id and lead.function_id.name or False, 'street': lead.street, 'street2': lead.street2, 'zip': lead.zip, 'city': lead.city, 'country_id': lead.country_id and lead.country_id.id or False, 'state_id': lead.state_id and lead.state_id.id or False, }, context) if lead.contact_name: vals = { 'last_name': lead.contact_name[0:lead.contact_name.find(' ')], 'first_name': lead.contact_name[lead.contact_name.find(' '):], 'title': lead.title.id, 'email': lead.email_from, 'website': lead.website, 'address_id': address_id, 'function_id': lead.function_id and lead.function_id.id or False, 'mobile': lead.mobile or lead.phone, } contact_partner_address_obj = self.pool[ 'res.partner.address.contact'] contact_id = contact_partner_address_obj.create( cr, uid, vals, context) lead.write({'contact_id': contact_id}) return address_id
def action_forward(self, cr, uid, ids, context=None): """ Forward the lead to a partner """ if context is None: context = {} res = {'type': 'ir.actions.act_window_close'} model = context.get('active_model') if model not in ('crm.lead'): return res this = self.browse(cr, uid, ids[0], context=context) lead = self.pool.get(model) lead_id = context and context.get('active_id', False) or False lead_ids = lead_id and [lead_id] or [] mode = context.get('mail.compose.message.mode') if mode == 'mass_mail': lead_ids = context and context.get('active_ids', []) or [] value = self.default_get( cr, uid, ['body_text', 'email_to', 'email_cc', 'subject', 'history'], context=context) self.write(cr, uid, ids, value, context=context) context['mail.compose.message.mode'] = mode self.send_mail(cr, uid, ids, context=context) for case in lead.browse(cr, uid, lead_ids, context=context): if (this.send_to == 'partner' and this.partner_id): lead.assign_partner(cr, uid, [case.id], this.partner_id.id, context=context) if this.send_to == 'user': lead.allocate_salesman(cr, uid, [case.id], [this.user_id.id], context=context) email_cc = to_email(case.email_cc) email_cc = email_cc and email_cc[0] or '' new_cc = [] if email_cc: new_cc.append(email_cc) for to in this.email_to.split(','): email_to = to_email(to) email_to = email_to and email_to[0] or '' if email_to not in new_cc: new_cc.append(to) update_vals = {'email_cc': ', '.join(new_cc)} lead.write(cr, uid, case.id, update_vals, context=context) return res
def _lead_create_partner_address(self, cr, uid, lead, partner_id, context=None): address = self.pool.get('res.partner.address') return address.create(cr, uid, { 'partner_id': partner_id, 'name': lead.contact_name, 'phone': lead.phone, 'mobile': lead.mobile, 'email': lead.email_from and to_email(lead.email_from)[0], 'fax': lead.fax, 'title': lead.title and lead.title.id or False, 'function': lead.function, 'street': lead.street, 'street2': lead.street2, 'zip': lead.zip, 'city': lead.city, 'country_id': lead.country_id and lead.country_id.id or False, 'state_id': lead.state_id and lead.state_id.id or False, })
def _lead_create_partner_address(self, cr, uid, lead, partner_id, context=None): address_obj = self.pool['res.partner.address'] address_ids = address_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'default')]) if address_ids: address_id = address_ids[0] else: address_id = address_obj.create(cr, uid, { 'partner_id': partner_id, 'name': lead.contact_name, 'phone': lead.phone, 'mobile': lead.mobile, 'email': lead.email_from and to_email(lead.email_from)[0], 'fax': lead.fax, 'title': lead.title and lead.title.id or False, 'function': lead.function_id and lead.function_id.name or False, 'street': lead.street, 'street2': lead.street2, 'zip': lead.zip, 'city': lead.city, 'country_id': lead.country_id and lead.country_id.id or False, 'state_id': lead.state_id and lead.state_id.id or False, }) if lead.contact_name: vals = { 'last_name': lead.contact_name[0:lead.contact_name.find(' ')], 'first_name': lead.contact_name[lead.contact_name.find(' '):], 'title': lead.title.id, 'email': lead.email_from, 'website': lead.website, 'address_id': address_id, 'function_id': lead.function_id and lead.function_id.id or False, 'mobile': lead.mobile or lead.phone, } contact_partner_address_obj = self.pool['res.partner.address.contact'] contact_partner_address_obj.create(cr, uid, vals, context) return address_id
def _lead_create_contact(self, cr, uid, lead, name, is_company, parent_id=False, context=None): partner = self.pool.get('res.partner') vals = { 'name': name, 'user_id': lead.user_id.id, 'comment': lead.description, 'section_id': lead.section_id.id or False, 'parent_id': parent_id, 'phone': lead.phone, 'mobile': lead.mobile, 'email': lead.email_from and to_email(lead.email_from)[0], 'fax': lead.fax, 'title': lead.title and lead.title.id or False, 'function': lead.function, 'street': lead.street, 'street2': lead.street2, 'zip': lead.zip, 'city': lead.city, 'country_id': lead.country_id and lead.country_id.id or False, 'state_id': lead.state_id and lead.state_id.id or False, 'is_company': is_company, 'type': 'contact' } partner = partner.create(cr, uid,vals, context) return partner
def send_mail(self, cr, uid, ids, context=None): ''' Overloaded Process:Process Wizard contents and proceed with sending the corresponding email(s), rendering any template patterns on the fly if needed. This is to Enforce the Send Mail Process to Give Prority for HTML Body While Sending Mail. It Replce While Old Method for the Wizard. ''' if context is None: context = {} mail_message = self.pool.get('mail.message') for mail in self.browse(cr, uid, ids, context=context): attachment = {} for attach in mail.attachment_ids: attachment[attach.datas_fname] = attach.datas and attach.datas.decode('base64') references = None headers = {} mail_subtype = mail.subtype body = mail.body_html if mail.subtype == 'html' else mail.body_text if mail.force_html and mail.body_html and mail.body_html.strip(): body, mail_subtype = mail.body_html, 'html' else: body, mail_subtype = mail.body_text, 'plain' # Reply Email if context.get('mail.compose.message.mode') == 'reply' and mail.message_id: references = (mail.references or '') + " " + mail.message_id headers['In-Reply-To'] = mail.message_id if context.get('mail.compose.message.mode') == 'mass_mail': # Mass mailing: must render the template patterns if context.get('active_ids') and context.get('active_model'): active_ids = context['active_ids'] active_model = context['active_model'] else: active_model = mail.model active_model_pool = self.pool.get(active_model) active_ids = active_model_pool.search(cr, uid, ast.literal_eval(mail.filter_id.domain), context=ast.literal_eval(mail.filter_id.context)) for active_id in active_ids: render_context = self._prepare_render_template_context(cr, uid, active_model, active_id, context) subject = self.render_template(cr, uid, mail.subject, active_model, active_id, render_context) rendered_body = self.render_template(cr, uid, body, active_model, active_id, render_context) email_from = self.render_template(cr, uid, mail.email_from, active_model, active_id, render_context) email_to = self.render_template(cr, uid, mail.email_to, active_model, active_id, render_context) email_cc = self.render_template(cr, uid, mail.email_cc, active_model, active_id, render_context) email_bcc = self.render_template(cr, uid, mail.email_bcc, active_model, active_id, render_context) reply_to = self.render_template(cr, uid, mail.reply_to, active_model, active_id, render_context) # in mass-mailing mode we only schedule the mail for sending, it will be # processed as soon as the mail scheduler runs. mail_message.schedule_with_attach(cr, uid, email_from, to_email(email_to), subject, rendered_body, model=mail.model, email_cc=to_email(email_cc), email_bcc=to_email(email_bcc), reply_to=reply_to, attachments=attachment, references=references, res_id=active_id, subtype=mail_subtype, headers=headers, context=context) else: # normal mode - no mass-mailing msg_id = mail_message.schedule_with_attach(cr, uid, mail.email_from, to_email(mail.email_to), mail.subject, body, model=mail.model, email_cc=to_email(mail.email_cc), email_bcc=to_email(mail.email_bcc), reply_to=mail.reply_to, attachments=attachment, references=references, res_id=int(mail.res_id), subtype=mail_subtype, headers=headers, context=context) # in normal mode, we send the email immediately, as the user expects us to (delay should be sufficiently small) mail_message.send(cr, uid, [msg_id], context=context) return {'type': 'ir.actions.act_window_close'}