12345678910111213141516171819202122232425262728 |
- # -*- coding:utf-8 -*-
- from openerp import fields, models, api
- class ResPartner(models.Model):
- _inherit="res.partner"
- task_ids = fields.One2many('crm.task', 'partner_id','Tareas')
- instagram = fields.Char('Instagram', size=64, required=False, readonly=False)
- 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'}
|