# -*- 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): _name = 'res.partner' _inherit = 'res.partner' _columns = { 'instagram':fields.char('Instagram', size=64), 'linkedin':fields.char('LinkedIn', size=64), } 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 goto_linkedin(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.linkedin: good_starting_urls = ['https://linkedin.com/', 'https://www.linkedin.com/', \ 'http://linkedin.com/', 'http://www.linkedin.com/'] non_protocol_starting_urls = ['linkedin.com/', 'www.linkedin.com/'] if any(map(lambda x: partner.linkedin.startswith(x), good_starting_urls)): url = partner.linkedin elif any(map(lambda x: partner.linkedin.startswith(x), non_protocol_starting_urls)): url = 'https://' + partner.linkedin else: url = 'https://www.linkedin.com/' + partner.linkedin return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}