# -*- encoding: utf-8 -*- ################################################################################# # # # product_features for OpenERP # # Copyright (C) 2009 NetAndCo (). # # Authors, Mathieu Lemercier, mathieu@netandco.net, # # Franck Bret, franck@netandco.net # # Copyright (C) 2011 Akretion Benoît Guillot # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU Affero General Public License as # # published by the Free Software Foundation, either version 3 of the # # License, or (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU Affero General Public License for more details. # # # # You should have received a copy of the GNU Affero General Public License # # along with this program. If not, see . # # # ################################################################################# from openerp import models, fields, tools class crm_lead(models.Model): _name = 'crm.lead' _inherit = 'crm.lead' #Campos facebook = fields.Char('Facebook', size=64, required=False, readonly=False) twitter = fields.Char('Twitter', size=64, required=False, readonly=False) skype = fields.Char('Skype', size=64, required=False, readonly=False) msn = fields.Char('MSN', size=64, required=False, readonly=False) instagram = fields.Char('Instagram', size=64, required=False, readonly=False) whatsapp = fields.Boolean('Whatsapp',help='Marque está opción si el cliente tiene Whatsapp') primer_contacto = fields.Many2one('res.partner.primer.contacto','Por cual medio se enteró de la empresa?',help='Medio por cual supo acerca de la empresa') def goto_facebook(self, cr, uid, ids, context=None): partner_obj = self.pool.get('res.partner') partner = partner_obj.browse(cr, uid, ids, context=context)[0] if partner.facebook: good_starting_urls = ['https://facebook.com/', 'https://www.facebook.com/', \ 'http://facebook.com/', 'http://www.facebook.com/'] non_protocol_starting_urls = ['facebook.com/', 'www.facebook.com/'] if any(map(lambda x: partner.facebook.startswith(x), good_starting_urls)): url = partner.facebook elif any(map(lambda x: partner.facebook.startswith(x), non_protocol_starting_urls)): url = 'https://' + partner.facebook else: url = 'https://www.facebook.com/' + partner.facebook return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'} def goto_twitter(self, cr, uid, ids, context=None): partner_obj = self.pool.get('res.partner') partner = partner_obj.browse(cr, uid, ids, context=context)[0] if partner.twitter: good_starting_urls = ['https://twitter.com/', 'https://www.twitter.com/', \ 'http://twitter.com/', 'http://www.twitter.com/'] non_protocol_starting_urls = ['twitter.com/', 'www.twitter.com/'] if any(map(lambda x: partner.twitter.startswith(x), good_starting_urls)): url = partner.twitter elif any(map(lambda x: partner.twitter.startswith(x), non_protocol_starting_urls)): url = 'https://' + partner.twitter else: url = 'https://www.twitter.com/' + partner.twitter return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'} def goto_instagram(self, cr, uid, ids, context=None): partner_obj = self.pool.get('res.partner') partner = partner_obj.browse(cr, uid, ids, context=context)[0] if partner.instagram: good_starting_urls = ['https://instagram.com/', 'https://www.instagram.com/', \ 'http://instagram.com/', 'http://www.instagram.com/'] non_protocol_starting_urls = ['instagram.com/', 'www.instagram.com/'] if any(map(lambda x: partner.instagram.startswith(x), good_starting_urls)): url = partner.instagram elif any(map(lambda x: partner.instagram.startswith(x), non_protocol_starting_urls)): url = 'https://' + partner.instagram else: url = 'https://www.instagram.com/' + partner.instagram return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'} 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': tools.email_split(lead.email_from) and tools.email_split(lead.email_from)[0] or False, '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', 'facebook':lead.facebook, 'twitter':lead.twitter, 'instagram':lead.instagram, 'skype':lead.skype, 'msn':lead.msn, 'whatsapp':lead.whatsapp, 'primer_contacto': lead.primer_contacto and lead.primer_contacto.id or False } partner = partner.create(cr, uid, vals, context=context) return partner crm_lead()