res_partner.py 1.2 KB

12345678910111213141516171819202122232425262728
  1. # -*- coding:utf-8 -*-
  2. from openerp import fields, models, api
  3. class ResPartner(models.Model):
  4. _inherit="res.partner"
  5. task_ids = fields.One2many('crm.task', 'partner_id','Tareas')
  6. instagram = fields.Char('Instagram', size=64, required=False, readonly=False)
  7. def goto_instagram(self, cr, uid, ids, context=None):
  8. partner_obj = self.pool.get('res.partner')
  9. partner = partner_obj.browse(cr, uid, ids, context=context)[0]
  10. if partner.instagram:
  11. good_starting_urls = ['https://instagram.com/', 'https://www.instagram.com/', \
  12. 'http://instagram.com/', 'http://www.instagram.com/']
  13. non_protocol_starting_urls = ['instagram.com/', 'www.instagram.com/']
  14. if any(map(lambda x: partner.instagram.startswith(x), good_starting_urls)):
  15. url = partner.instagram
  16. elif any(map(lambda x: partner.instagram.startswith(x), non_protocol_starting_urls)):
  17. url = 'https://' + partner.instagram
  18. else:
  19. url = 'https://www.instagram.com/' + partner.instagram
  20. return {'type': 'ir.actions.act_url', 'url': url, 'target': 'new'}