# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # # 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.osv import osv, fields class res_partner(osv.osv): ''' Add social media to res.partner ''' _name = 'res.partner' _inherit = 'res.partner' _description = 'Add social media to Partner' _columns = { '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), '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'} class res_partner_primer_contacto(osv.osv): _name = 'res.partner.primer.contacto' _columns = { 'name':fields.char('Forma de Contacto', size=64, required=False), }